@@ -30,9 +30,6 @@ Conversion of mediawiki text to 'Pandoc' document.
34−_ support list style attributes and start values in ol lists, also
35− value attribute on li
36_ support internal links http://www.mediawiki.org/wiki/Help:Links
33_ support internal links http://www.mediawiki.org/wiki/Help:Links
37_ support external links (partially implemented)
34_ support external links (partially implemented)
38_ support images http://www.mediawiki.org/wiki/Help:Images
35_ support images http://www.mediawiki.org/wiki/Help:Images
@@ -50,7 +47,7 @@ import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag,
50import Text.Pandoc.XML ( fromEntities )
47import Text.Pandoc.XML ( fromEntities )
51import Text.Pandoc.Parsing
48import Text.Pandoc.Parsing
52import Text.Pandoc.Generic ( bottomUp )
49import Text.Pandoc.Generic ( bottomUp )
53−import Text.Pandoc.Shared ( stripTrailingNewlines )
50+import Text.Pandoc.Shared ( stripTrailingNewlines, safeRead )
54import Data.Monoid (mconcat, mempty)
51import Data.Monoid (mconcat, mempty)
55import Control.Applicative ((<$>), (<*), (*>), (<$))
52import Control.Applicative ((<$>), (<*), (*>), (<$))
56import Control.Monad
53import Control.Monad
@@ -121,8 +118,8 @@ block :: MWParser Blocks
121block = mempty <$ skipMany1 blankline
118block = mempty <$ skipMany1 blankline
122 <|> header
119 <|> header
123 <|> hrule
120 <|> hrule
125 <|> orderedList
121 <|> orderedList
126 <|> definitionList
123 <|> definitionList
127 <|> mempty <$ try (spaces *> htmlComment)
124 <|> mempty <$ try (spaces *> htmlComment)
128 <|> preformatted
125 <|> preformatted
@@ -151,7 +148,7 @@ blockTag = do
151 "pre" -> B.codeBlock . trimCode <$> charsInTags "pre"
148 "pre" -> B.codeBlock . trimCode <$> charsInTags "pre"
152 "syntaxhighlight" -> syntaxhighlight attrs
149 "syntaxhighlight" -> syntaxhighlight attrs
153 "haskell" -> B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
150 "haskell" -> B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
154− charsInTags "haskell"
151+ charsInTags "haskell"
155 "p" -> return mempty
152 "p" -> return mempty
156 _ -> return $ B.rawBlock "html" raw
153 _ -> return $ B.rawBlock "html" raw
@@ -207,10 +204,23 @@ header = try $ do
207 return $ B.header lev contents
204 return $ B.header lev contents
209bulletList :: MWParser Blocks
206bulletList :: MWParser Blocks
210−bulletList = B.bulletList <$> many1 (listItem '*')
207+bulletList = B.bulletList <$>
208+ ( many1 (listItem '*')
209+ <|> (htmlTag (~== TagOpen "ul" []) *> spaces *> many (listItem '*' <|> li) <*
210+ optional (htmlTag (~== TagClose "ul"))) )
212orderedList :: MWParser Blocks
212orderedList :: MWParser Blocks
213−orderedList = B.orderedList <$> many1 (listItem '#')
214+ (B.orderedList <$> many1 (listItem '#'))
215+ <|> (B.orderedList <$> (htmlTag (~== TagOpen "ul" []) *> spaces *>
216+ many (listItem '#' <|> li) <*
217+ optional (htmlTag (~== TagClose "ul"))))
218+ <|> do (tag,_) <- htmlTag (~== TagOpen "ol" [])
220+ items <- many (listItem '#' <|> li)
221+ optional (htmlTag (~== TagClose "ol"))
222+ let start = maybe 1 id $ safeRead $ fromAttrib "start" tag
223+ return $ B.orderedListWith (start, DefaultStyle, DefaultDelim) items
215definitionList :: MWParser Blocks
225definitionList :: MWParser Blocks
216definitionList = B.definitionList <$> many1 defListItem
226definitionList = B.definitionList <$> many1 defListItem
@@ -237,6 +247,10 @@ anyListStart = char '*'
237 <|> char ':'
247 <|> char ':'
238 <|> char ';'
248 <|> char ';'
250+li :: MWParser Blocks
251+li = htmlTag (~== TagOpen "li" []) *>
252+ (firstParaToPlain <$> blocksInTags "li") <* spaces
240listItem :: Char -> MWParser Blocks
254listItem :: Char -> MWParser Blocks
241listItem c = try $ do
255listItem c = try $ do
242 extras <- many (try $ char c <* lookAhead listStartChar)
256 extras <- many (try $ char c <* lookAhead listStartChar)
@@ -261,11 +275,14 @@ listItem' c = try $ do
261 first <- manyTill anyChar newline
275 first <- manyTill anyChar newline
262 rest <- many (try $ char c *> lookAhead listStartChar *>
276 rest <- many (try $ char c *> lookAhead listStartChar *>
263 manyTill anyChar newline)
277 manyTill anyChar newline)
264− contents <- parseFromString (mconcat <$> many1 block)
278+ parseFromString (firstParaToPlain . mconcat <$> many1 block)
265− $ unlines $ first : rest
279+ $ unlines $ first : rest
281+firstParaToPlain :: Blocks -> Blocks
282+firstParaToPlain contents =
266 case viewl (B.unMany contents) of
283 case viewl (B.unMany contents) of
267− (Para xs) :< ys -> return $ B.Many $ (Plain xs) <| ys
284+ (Para xs) :< ys -> B.Many $ (Plain xs) <| ys
268− _ -> return contents
285+ _ -> contents
271-- inline parsers
288-- inline parsers