git.iko.soy/typeable/pandoc
on master help sign in
Org reader: Fix parsing of loose lists

Loose lists (i.e. lists with blankline separated items), were parsed as multiple lists, each containing a single item. This patch fixes this issue.

commitf19d7233d8d3e47912b760fc62a253e5baf8275a authorAlbert Krewinkel <tarleb@moltkeplatz.de> dateFri 18 Apr 2014, 08:33 (13 years ago) parent6d6724c
2 files changed+23−9
src/Text/Pandoc/Readers/Org.hs+7−4 tests/Tests/Readers/Org.hs+16−5
src/Text/Pandoc/Readers/Org.hs+7−4
@@ -605,9 +605,10 @@ definitionListItem parseMarkerGetLength = try $ do
605605 markerLength <- parseMarkerGetLength
606606 term <- manyTill (noneOf "\n\r") (try $ string "::")
607607 first <- anyLineNewline
608+ blank <- option "" ("\n" <$ blankline)
608609 cont <- concat <$> many (listContinuation markerLength)
609610 term' <- parseFromString inline term
610− contents' <- parseFromString parseBlocks $ first ++ cont
611+ contents' <- parseFromString parseBlocks $ first ++ blank ++ cont
611612 return $ (,) <$> term' <*> fmap (:[]) contents'
612613
613614
@@ -617,16 +618,18 @@ listItem :: OrgParser Int
617618listItem start = try $ do
618619 markerLength <- try start
619620 firstLine <- anyLineNewline
621+ blank <- option "" ("\n" <$ blankline)
620622 rest <- concat <$> many (listContinuation markerLength)
621− parseFromString parseBlocks $ firstLine ++ rest
623+ parseFromString parseBlocks $ firstLine ++ blank ++ rest
622624
623625-- continuation of a list item - indented and separated by blankline or endline.
624626-- Note: nested lists are parsed as continuations.
625627listContinuation :: Int
626628 -> OrgParser String
627629listContinuation markerLength = try $
628− mappend <$> many blankline
629− <*> (concat <$> many1 listLine)
630+ notFollowedBy' blankline
631+ *> (mappend <$> (concat <$> many1 listLine)
632+ <*> many blankline)
630633 where listLine = try $ indentWith markerLength *> anyLineNewline
631634
632635anyLineNewline :: OrgParser String
tests/Tests/Readers/Org.hs+16−5
@@ -518,13 +518,24 @@ tests =
518518 , ("TTL", [ plain $ "transistor-transistor" <> space <>
519519 "logic" ])
520520 , ("PSK", [ mconcat
521− [ para $ "phase-shift" <> space <> "keying"
522− , plain $ spcSep [ "a", "digital"
523− , "modulation", "scheme" ]
521+ [ para $ "phase-shift" <> space <> "keying"
522+ , para $ spcSep [ "a", "digital"
523+ , "modulation", "scheme" ]
524524 ]
525− ]
526− )
525+ ])
527526 ]
527+
528+ , "Loose bullet list" =:
529+ unlines [ "- apple"
530+ , ""
531+ , "- orange"
532+ , ""
533+ , "- peach"
534+ ] =?>
535+ bulletList [ para "apple"
536+ , para "orange"
537+ , para "peach"
538+ ]
528539 ]
529540
530541 , testGroup "Tables"