summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <tarleb@moltkeplatz.de>2014-04-18 08:33:25 +0200
committerAlbert Krewinkel <tarleb@moltkeplatz.de>2014-04-18 08:34:06 +0200
commitf19d7233d8d3e47912b760fc62a253e5baf8275a (patch)
treedc7e1e95d41a77adf22bbbbae791ec2273f83afc
parent6d6724cf2c6ae6bcc0df312c476e45644c972a85 (diff)
Org reader: Fix parsing of loose lists
Loose lists (i.e. lists with blankline separated items), were parsed as multiple lists, each containing a single item. This patch fixes this issue.
-rw-r--r--src/Text/Pandoc/Readers/Org.hs11
-rw-r--r--tests/Tests/Readers/Org.hs21
2 files changed, 23 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs
index 88e81f5fc..1fa8d4d5e 100644
--- a/src/Text/Pandoc/Readers/Org.hs
+++ b/src/Text/Pandoc/Readers/Org.hs
@@ -605,9 +605,10 @@ definitionListItem parseMarkerGetLength = try $ do
markerLength <- parseMarkerGetLength
term <- manyTill (noneOf "\n\r") (try $ string "::")
first <- anyLineNewline
+ blank <- option "" ("\n" <$ blankline)
cont <- concat <$> many (listContinuation markerLength)
term' <- parseFromString inline term
- contents' <- parseFromString parseBlocks $ first ++ cont
+ contents' <- parseFromString parseBlocks $ first ++ blank ++ cont
return $ (,) <$> term' <*> fmap (:[]) contents'
@@ -617,16 +618,18 @@ listItem :: OrgParser Int
listItem start = try $ do
markerLength <- try start
firstLine <- anyLineNewline
+ blank <- option "" ("\n" <$ blankline)
rest <- concat <$> many (listContinuation markerLength)
- parseFromString parseBlocks $ firstLine ++ rest
+ parseFromString parseBlocks $ firstLine ++ blank ++ rest
-- continuation of a list item - indented and separated by blankline or endline.
-- Note: nested lists are parsed as continuations.
listContinuation :: Int
-> OrgParser String
listContinuation markerLength = try $
- mappend <$> many blankline
- <*> (concat <$> many1 listLine)
+ notFollowedBy' blankline
+ *> (mappend <$> (concat <$> many1 listLine)
+ <*> many blankline)
where listLine = try $ indentWith markerLength *> anyLineNewline
anyLineNewline :: OrgParser String
diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs
index 7d5bfe650..572fc501f 100644
--- a/tests/Tests/Readers/Org.hs
+++ b/tests/Tests/Readers/Org.hs
@@ -518,13 +518,24 @@ tests =
, ("TTL", [ plain $ "transistor-transistor" <> space <>
"logic" ])
, ("PSK", [ mconcat
- [ para $ "phase-shift" <> space <> "keying"
- , plain $ spcSep [ "a", "digital"
- , "modulation", "scheme" ]
+ [ para $ "phase-shift" <> space <> "keying"
+ , para $ spcSep [ "a", "digital"
+ , "modulation", "scheme" ]
]
- ]
- )
+ ])
]
+
+ , "Loose bullet list" =:
+ unlines [ "- apple"
+ , ""
+ , "- orange"
+ , ""
+ , "- peach"
+ ] =?>
+ bulletList [ para "apple"
+ , para "orange"
+ , para "peach"
+ ]
]
, testGroup "Tables"