MediaWiki reader: Properly handle templates in list items.

This commit is contained in:
John MacFarlane 2012-09-15 16:17:52 -04:00
parent 887fc14f3d
commit c9faa2740b

View file

@ -397,8 +397,9 @@ listItem c = try $ do
then listItem' c then listItem' c
else do else do
skipMany spaceChar skipMany spaceChar
first <- manyTill anyChar newline first <- concat <$> manyTill listChunk newline
rest <- many (try $ string extras *> manyTill anyChar newline) rest <- many
(try $ string extras *> (concat <$> manyTill listChunk newline))
contents <- parseFromString (many1 $ listItem' c) contents <- parseFromString (many1 $ listItem' c)
(unlines (first : rest)) (unlines (first : rest))
case c of case c of
@ -407,13 +408,23 @@ listItem c = try $ do
':' -> return $ B.definitionList [(mempty, contents)] ':' -> return $ B.definitionList [(mempty, contents)]
_ -> mzero _ -> mzero
-- The point of this is to handle stuff like
-- * {{cite book
-- | blah
-- | blah
-- }}
-- * next list item
-- which seems to be valid mediawiki.
listChunk :: MWParser String
listChunk = template <|> count 1 anyChar
listItem' :: Char -> MWParser Blocks listItem' :: Char -> MWParser Blocks
listItem' c = try $ do listItem' c = try $ do
listStart c listStart c
skipMany spaceChar skipMany spaceChar
first <- manyTill anyChar newline first <- concat <$> manyTill listChunk newline
rest <- many (try $ char c *> lookAhead listStartChar *> rest <- many (try $ char c *> lookAhead listStartChar *>
manyTill anyChar newline) (concat <$> manyTill listChunk newline))
parseFromString (firstParaToPlain . mconcat <$> many1 block) parseFromString (firstParaToPlain . mconcat <$> many1 block)
$ unlines $ first : rest $ unlines $ first : rest