git.iko.soy/typeable/pandoc
on master help sign in
Respect indent when parsing Org bullet lists

Fixes issue with top-level bullet list parsing. Previously we would use `many1 spaceChars` rather than respecting the list's indent level. We also permitted `*` bullets on unindented lists, which should unambiguously parse as `header 1`. Combined, this meant headers at a different indent level were being unwittingly slurped into preceding bullet lists, as per Issue #1650.

commit4f4b0f031d17927b6787c9deee736cf0892cab70 authorTimothy Humphries <tim@utf8.me> dateSun 12 Oct 2014, 03:18 (12 years ago) parent8b60d43
2 files changed+37−2
src/Text/Pandoc/Readers/Org.hs+10−2 tests/Tests/Readers/Org.hs+27
src/Text/Pandoc/Readers/Org.hs+10−2
@@ -832,8 +832,9 @@ definitionList = fmap B.definitionList . fmap compactify'DL . sequence
832832 <$> many1 (definitionListItem bulletListStart)
833833
834834bulletList :: OrgParser (F Blocks)
835−bulletList = fmap B.bulletList . fmap compactify' . sequence
836− <$> many1 (listItem bulletListStart)
835+bulletList = try $ do n <- lookAhead bulletListStart
836+ fmap B.bulletList . fmap compactify' . sequence
837+ <$> many1 (listItem (bulletListCont n))
837838
838839orderedList :: OrgParser (F Blocks)
839840orderedList = fmap B.orderedList . fmap compactify' . sequence
@@ -850,6 +851,13 @@ bulletListStart :: OrgParser Int
850851bulletListStart = genericListStart bulletListMarker
851852 where bulletListMarker = pure <$> oneOf "*-+"
852853
854+-- parses bullet list marker at a known indent level
855+bulletListCont :: Int -> OrgParser Int
856+bulletListCont n
857+ -- Unindented lists are legal, but they can't use '*' bullets
858+ | n <= 1 = oneOf "+-" >> return n
859+ | otherwise = count (n-1) spaceChar >> oneOf "+-*" >> return n
860+
853861orderedListStart :: OrgParser Int
854862orderedListStart = genericListStart orderedListMarker
855863 -- Ordered list markers allowed in org-mode
tests/Tests/Readers/Org.hs+27
@@ -622,6 +622,33 @@ tests =
622622 ]
623623 ]
624624
625+ , "Bullet List with Decreasing Indent" =:
626+ (" - Discovery\n\
627+ \ - Human After All\n") =?>
628+ mconcat [ bulletList [ plain "Discovery" ]
629+ , bulletList [ plain ("Human" <> space <> "After" <> space <> "All")]
630+ ]
631+
632+ , "Header follows Bullet List" =:
633+ (" - Discovery\n\
634+ \ - Human After All\n\
635+ \* Homework") =?>
636+ mconcat [ bulletList [ plain "Discovery"
637+ , plain ("Human" <> space <> "After" <> space <> "All")
638+ ]
639+ , header 1 "Homework"
640+ ]
641+
642+ , "Bullet List Unindented with trailing Header" =:
643+ ("- Discovery\n\
644+ \- Homework\n\
645+ \* NotValidListItem") =?>
646+ mconcat [ bulletList [ plain "Discovery"
647+ , plain "Homework"
648+ ]
649+ , header 1 "NotValidListItem"
650+ ]
651+
625652 , "Simple Ordered List" =:
626653 ("1. Item1\n" ++
627654 "2. Item2\n") =?>