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.
This commit is contained in:
parent
8b60d430f2
commit
4f4b0f031d
2 changed files with 37 additions and 2 deletions
|
@ -832,8 +832,9 @@ definitionList = fmap B.definitionList . fmap compactify'DL . sequence
|
|||
<$> many1 (definitionListItem bulletListStart)
|
||||
|
||||
bulletList :: OrgParser (F Blocks)
|
||||
bulletList = fmap B.bulletList . fmap compactify' . sequence
|
||||
<$> many1 (listItem bulletListStart)
|
||||
bulletList = try $ do n <- lookAhead bulletListStart
|
||||
fmap B.bulletList . fmap compactify' . sequence
|
||||
<$> many1 (listItem (bulletListCont n))
|
||||
|
||||
orderedList :: OrgParser (F Blocks)
|
||||
orderedList = fmap B.orderedList . fmap compactify' . sequence
|
||||
|
@ -850,6 +851,13 @@ bulletListStart :: OrgParser Int
|
|||
bulletListStart = genericListStart bulletListMarker
|
||||
where bulletListMarker = pure <$> oneOf "*-+"
|
||||
|
||||
-- parses bullet list marker at a known indent level
|
||||
bulletListCont :: Int -> OrgParser Int
|
||||
bulletListCont n
|
||||
-- Unindented lists are legal, but they can't use '*' bullets
|
||||
| n <= 1 = oneOf "+-" >> return n
|
||||
| otherwise = count (n-1) spaceChar >> oneOf "+-*" >> return n
|
||||
|
||||
orderedListStart :: OrgParser Int
|
||||
orderedListStart = genericListStart orderedListMarker
|
||||
-- Ordered list markers allowed in org-mode
|
||||
|
|
|
@ -622,6 +622,33 @@ tests =
|
|||
]
|
||||
]
|
||||
|
||||
, "Bullet List with Decreasing Indent" =:
|
||||
(" - Discovery\n\
|
||||
\ - Human After All\n") =?>
|
||||
mconcat [ bulletList [ plain "Discovery" ]
|
||||
, bulletList [ plain ("Human" <> space <> "After" <> space <> "All")]
|
||||
]
|
||||
|
||||
, "Header follows Bullet List" =:
|
||||
(" - Discovery\n\
|
||||
\ - Human After All\n\
|
||||
\* Homework") =?>
|
||||
mconcat [ bulletList [ plain "Discovery"
|
||||
, plain ("Human" <> space <> "After" <> space <> "All")
|
||||
]
|
||||
, header 1 "Homework"
|
||||
]
|
||||
|
||||
, "Bullet List Unindented with trailing Header" =:
|
||||
("- Discovery\n\
|
||||
\- Homework\n\
|
||||
\* NotValidListItem") =?>
|
||||
mconcat [ bulletList [ plain "Discovery"
|
||||
, plain "Homework"
|
||||
]
|
||||
, header 1 "NotValidListItem"
|
||||
]
|
||||
|
||||
, "Simple Ordered List" =:
|
||||
("1. Item1\n" ++
|
||||
"2. Item2\n") =?>
|
||||
|
|
Loading…
Add table
Reference in a new issue