git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Properly handle templates in list items.
c9faa27John MacFarlane
src/Text/Pandoc/Readers/MediaWiki.hs+15−4
@@ -397,8 +397,9 @@ listItem c = try $ do
397 then listItem' c
397 then listItem' c
398 else do
398 else do
399 skipMany spaceChar
399 skipMany spaceChar
400− first <- manyTill anyChar newline
400+ first <- concat <$> manyTill listChunk newline
401+ rest <- many
401− rest <- many (try $ string extras *> manyTill anyChar newline)
402+ (try $ string extras *> (concat <$> manyTill listChunk newline))
402 contents <- parseFromString (many1 $ listItem' c)
403 contents <- parseFromString (many1 $ listItem' c)
403 (unlines (first : rest))
404 (unlines (first : rest))
404 case c of
405 case c of
@@ -407,13 +408,23 @@ listItem c = try $ do
407 ':' -> return $ B.definitionList [(mempty, contents)]
408 ':' -> return $ B.definitionList [(mempty, contents)]
408 _ -> mzero
409 _ -> mzero
409
410
411+-- The point of this is to handle stuff like
412+-- * {{cite book
413+-- | blah
414+-- | blah
415+-- }}
416+-- * next list item
417+-- which seems to be valid mediawiki.
418+listChunk :: MWParser String
419+listChunk = template <|> count 1 anyChar
420+
410listItem' :: Char -> MWParser Blocks
421listItem' :: Char -> MWParser Blocks
411listItem' c = try $ do
422listItem' c = try $ do
412 listStart c
423 listStart c
413 skipMany spaceChar
424 skipMany spaceChar
414− first <- manyTill anyChar newline
425+ first <- concat <$> manyTill listChunk newline
415 rest <- many (try $ char c *> lookAhead listStartChar *>
426 rest <- many (try $ char c *> lookAhead listStartChar *>
416− manyTill anyChar newline)
427+ (concat <$> manyTill listChunk newline))
417 parseFromString (firstParaToPlain . mconcat <$> many1 block)
428 parseFromString (firstParaToPlain . mconcat <$> many1 block)
418 $ unlines $ first : rest
429 $ unlines $ first : rest
419
430