@@ -30,9 +30,6 @@ Conversion of mediawiki text to 'Pandoc' document.
3030-}
3131{-
3232TODO:
33−_ support HTML lists
34−_ support list style attributes and start values in ol lists, also
35− value attribute on li
3633_ support internal links http://www.mediawiki.org/wiki/Help:Links
3734_ support external links (partially implemented)
3835_ support images http://www.mediawiki.org/wiki/Help:Images
@@ -50,7 +47,7 @@ import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag,
5047import Text.Pandoc.XML ( fromEntities )
5148import Text.Pandoc.Parsing
5249import Text.Pandoc.Generic ( bottomUp )
53−import Text.Pandoc.Shared ( stripTrailingNewlines )
50+import Text.Pandoc.Shared ( stripTrailingNewlines, safeRead )
5451import Data.Monoid (mconcat, mempty)
5552import Control.Applicative ((<$>), (<*), (*>), (<$))
5653import Control.Monad
@@ -121,8 +118,8 @@ block :: MWParser Blocks
121118block = mempty <$ skipMany1 blankline
122119 <|> header
123120 <|> hrule
124− <|> bulletList
125121 <|> orderedList
122+ <|> bulletList
126123 <|> definitionList
127124 <|> mempty <$ try (spaces *> htmlComment)
128125 <|> preformatted
@@ -151,7 +148,7 @@ blockTag = do
151148 "pre" -> B.codeBlock . trimCode <$> charsInTags "pre"
152149 "syntaxhighlight" -> syntaxhighlight attrs
153150 "haskell" -> B.codeBlockWith ("",["haskell"],[]) . trimCode <$>
154− charsInTags "haskell"
151+ charsInTags "haskell"
155152 "p" -> return mempty
156153 _ -> return $ B.rawBlock "html" raw
157154
@@ -207,10 +204,23 @@ header = try $ do
207204 return $ B.header lev contents
208205
209206bulletList :: 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"))) )
211211
212212orderedList :: MWParser Blocks
213−orderedList = B.orderedList <$> many1 (listItem '#')
213+orderedList =
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" [])
219+ spaces
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
214224
215225definitionList :: MWParser Blocks
216226definitionList = B.definitionList <$> many1 defListItem
@@ -237,6 +247,10 @@ anyListStart = char '*'
237247 <|> char ':'
238248 <|> char ';'
239249
250+li :: MWParser Blocks
251+li = htmlTag (~== TagOpen "li" []) *>
252+ (firstParaToPlain <$> blocksInTags "li") <* spaces
253+
240254listItem :: Char -> MWParser Blocks
241255listItem c = try $ do
242256 extras <- many (try $ char c <* lookAhead listStartChar)
@@ -261,11 +275,14 @@ listItem' c = try $ do
261275 first <- manyTill anyChar newline
262276 rest <- many (try $ char c *> lookAhead listStartChar *>
263277 manyTill anyChar newline)
264− contents <- parseFromString (mconcat <$> many1 block)
265− $ unlines $ first : rest
278+ parseFromString (firstParaToPlain . mconcat <$> many1 block)
279+ $ unlines $ first : rest
280+
281+firstParaToPlain :: Blocks -> Blocks
282+firstParaToPlain contents =
266283 case viewl (B.unMany contents) of
267− (Para xs) :< ys -> return $ B.Many $ (Plain xs) <| ys
268− _ -> return contents
284+ (Para xs) :< ys -> B.Many $ (Plain xs) <| ys
285+ _ -> contents
269286
270287--
271288-- inline parsers