aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Humphries <tim@utf8.me>2014-10-17 20:06:25 -0400
committerTimothy Humphries <tim@utf8.me>2014-10-17 20:06:25 -0400
commitf1f56e85334fd29b4ed670d0b280e85f68e21bf2 (patch)
treef07f8b4f200331afdca883b00b2995336dabbd64
parent4f4b0f031d17927b6787c9deee736cf0892cab70 (diff)
downloadpandoc-f1f56e85334fd29b4ed670d0b280e85f68e21bf2.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Readers/Org.hs39
-rw-r--r--tests/Tests/Readers/Org.hs10
2 files changed, 35 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs
index 199c9f2de..a75e3cec8 100644
--- a/src/Text/Pandoc/Readers/Org.hs
+++ b/src/Text/Pandoc/Readers/Org.hs
@@ -828,13 +828,14 @@ list :: OrgParser (F Blocks)
list = choice [ definitionList, bulletList, orderedList ] <?> "list"
definitionList :: OrgParser (F Blocks)
-definitionList = fmap B.definitionList . fmap compactify'DL . sequence
- <$> many1 (definitionListItem bulletListStart)
+definitionList = try $ do n <- lookAhead (bulletListStart' Nothing)
+ fmap B.definitionList . fmap compactify'DL . sequence
+ <$> many1 (definitionListItem $ bulletListStart' (Just n))
bulletList :: OrgParser (F Blocks)
-bulletList = try $ do n <- lookAhead bulletListStart
+bulletList = try $ do n <- lookAhead (bulletListStart' Nothing)
fmap B.bulletList . fmap compactify' . sequence
- <$> many1 (listItem (bulletListCont n))
+ <$> many1 (listItem (bulletListStart' $ Just n))
orderedList :: OrgParser (F Blocks)
orderedList = fmap B.orderedList . fmap compactify' . sequence
@@ -846,17 +847,27 @@ genericListStart listMarker = try $
(+) <$> (length <$> many spaceChar)
<*> (length <$> listMarker <* many1 spaceChar)
--- parses bullet list start and returns its length (excl. following whitespace)
+-- parses bullet list marker. maybe we know the indent level
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
+bulletListStart = bulletListStart' Nothing
+
+bulletListStart' :: Maybe Int -> OrgParser Int
+-- returns length of bulletList prefix, inclusive of marker
+bulletListStart' Nothing = do ind <- many spaceChar
+ oneOf bullets
+ many1 spaceChar
+ return $ length ind + 1
+ -- Unindented lists are legal, but they can't use '*' bullets
+ -- We return n to maintain compatibility with the generic listItem
+bulletListStart' (Just n) = do count (n-1) spaceChar
+ oneOf validBullets
+ many1 spaceChar
+ return n
+ where validBullets = if n == 1 then noAsterisks else bullets
+ noAsterisks = filter (/= '*') bullets
+
+bullets :: String
+bullets = "*+-"
orderedListStart :: OrgParser Int
orderedListStart = genericListStart orderedListMarker
diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs
index f27388e46..978bf87b4 100644
--- a/tests/Tests/Readers/Org.hs
+++ b/tests/Tests/Readers/Org.hs
@@ -744,6 +744,16 @@ tests =
, ("PCR", [ plain $ spcSep [ "polymerase", "chain", "reaction" ] ])
]
+ , "Definition List With Trailing Header" =:
+ "- definition :: list\n\
+ \- cool :: defs\n\
+ \* header" =?>
+ mconcat [ definitionList [ ("definition", [plain "list"])
+ , ("cool", [plain "defs"])
+ ]
+ , header 1 "header"
+ ]
+
, "Loose bullet list" =:
unlines [ "- apple"
, ""