Skip to content

Commit f1f56e8

Browse files
committed
Fix indent issue for definition lists
Tidy up fix for #1650, #1698 as per comments in #1680. Fix same issue for definition lists with the same method.
1 parent 4f4b0f0 commit f1f56e8

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

src/Text/Pandoc/Readers/Org.hs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -828,13 +828,14 @@ list :: OrgParser (F Blocks)
828828
list = choice [ definitionList, bulletList, orderedList ] <?> "list"
829829

830830
definitionList :: OrgParser (F Blocks)
831-
definitionList = fmap B.definitionList . fmap compactify'DL . sequence
832-
<$> many1 (definitionListItem bulletListStart)
831+
definitionList = try $ do n <- lookAhead (bulletListStart' Nothing)
832+
fmap B.definitionList . fmap compactify'DL . sequence
833+
<$> many1 (definitionListItem $ bulletListStart' (Just n))
833834

834835
bulletList :: OrgParser (F Blocks)
835-
bulletList = try $ do n <- lookAhead bulletListStart
836+
bulletList = try $ do n <- lookAhead (bulletListStart' Nothing)
836837
fmap B.bulletList . fmap compactify' . sequence
837-
<$> many1 (listItem (bulletListCont n))
838+
<$> many1 (listItem (bulletListStart' $ Just n))
838839

839840
orderedList :: OrgParser (F Blocks)
840841
orderedList = fmap B.orderedList . fmap compactify' . sequence
@@ -846,17 +847,27 @@ genericListStart listMarker = try $
846847
(+) <$> (length <$> many spaceChar)
847848
<*> (length <$> listMarker <* many1 spaceChar)
848849

849-
-- parses bullet list start and returns its length (excl. following whitespace)
850+
-- parses bullet list marker. maybe we know the indent level
850851
bulletListStart :: OrgParser Int
851-
bulletListStart = genericListStart bulletListMarker
852-
where bulletListMarker = pure <$> oneOf "*-+"
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
852+
bulletListStart = bulletListStart' Nothing
853+
854+
bulletListStart' :: Maybe Int -> OrgParser Int
855+
-- returns length of bulletList prefix, inclusive of marker
856+
bulletListStart' Nothing = do ind <- many spaceChar
857+
oneOf bullets
858+
many1 spaceChar
859+
return $ length ind + 1
860+
-- Unindented lists are legal, but they can't use '*' bullets
861+
-- We return n to maintain compatibility with the generic listItem
862+
bulletListStart' (Just n) = do count (n-1) spaceChar
863+
oneOf validBullets
864+
many1 spaceChar
865+
return n
866+
where validBullets = if n == 1 then noAsterisks else bullets
867+
noAsterisks = filter (/= '*') bullets
868+
869+
bullets :: String
870+
bullets = "*+-"
860871

861872
orderedListStart :: OrgParser Int
862873
orderedListStart = genericListStart orderedListMarker

tests/Tests/Readers/Org.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,16 @@ tests =
744744
, ("PCR", [ plain $ spcSep [ "polymerase", "chain", "reaction" ] ])
745745
]
746746

747+
, "Definition List With Trailing Header" =:
748+
"- definition :: list\n\
749+
\- cool :: defs\n\
750+
\* header" =?>
751+
mconcat [ definitionList [ ("definition", [plain "list"])
752+
, ("cool", [plain "defs"])
753+
]
754+
, header 1 "header"
755+
]
756+
747757
, "Loose bullet list" =:
748758
unlines [ "- apple"
749759
, ""

0 commit comments

Comments
 (0)