git.iko.soy/typeable/pandoc
on master help sign in
Respect indent when parsing Org bullet lists
4f4b0f0Timothy Humphries
src/Text/Pandoc/Readers/Org.hs+10−2
@@ -832,8 +832,9 @@ definitionList = fmap B.definitionList . fmap compactify'DL . sequence
832 <$> many1 (definitionListItem bulletListStart)
832 <$> many1 (definitionListItem bulletListStart)
833
833
834bulletList :: OrgParser (F Blocks)
834bulletList :: OrgParser (F Blocks)
835+bulletList = try $ do n <- lookAhead bulletListStart
835−bulletList = fmap B.bulletList . fmap compactify' . sequence
836+ fmap B.bulletList . fmap compactify' . sequence
836− <$> many1 (listItem bulletListStart)
837+ <$> many1 (listItem (bulletListCont n))
837
838
838orderedList :: OrgParser (F Blocks)
839orderedList :: OrgParser (F Blocks)
839orderedList = fmap B.orderedList . fmap compactify' . sequence
840orderedList = fmap B.orderedList . fmap compactify' . sequence
@@ -850,6 +851,13 @@ bulletListStart :: OrgParser Int
850bulletListStart = genericListStart bulletListMarker
851bulletListStart = genericListStart bulletListMarker
851 where bulletListMarker = pure <$> oneOf "*-+"
852 where bulletListMarker = pure <$> oneOf "*-+"
852
853
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+
853orderedListStart :: OrgParser Int
861orderedListStart :: OrgParser Int
854orderedListStart = genericListStart orderedListMarker
862orderedListStart = genericListStart orderedListMarker
855 -- Ordered list markers allowed in org-mode
863 -- Ordered list markers allowed in org-mode
tests/Tests/Readers/Org.hs+27
@@ -622,6 +622,33 @@ tests =
622 ]
622 ]
623 ]
623 ]
624
624
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+
625 , "Simple Ordered List" =:
652 , "Simple Ordered List" =:
626 ("1. Item1\n" ++
653 ("1. Item1\n" ++
627 "2. Item2\n") =?>
654 "2. Item2\n") =?>