git.iko.soy/typeable/pandoc
on master help sign in
Org reader: Fix parsing of loose lists
f19d723Albert Krewinkel
src/Text/Pandoc/Readers/Org.hs+7−4
@@ -605,9 +605,10 @@ definitionListItem parseMarkerGetLength = try $ do
605 markerLength <- parseMarkerGetLength
605 markerLength <- parseMarkerGetLength
606 term <- manyTill (noneOf "\n\r") (try $ string "::")
606 term <- manyTill (noneOf "\n\r") (try $ string "::")
607 first <- anyLineNewline
607 first <- anyLineNewline
608+ blank <- option "" ("\n" <$ blankline)
608 cont <- concat <$> many (listContinuation markerLength)
609 cont <- concat <$> many (listContinuation markerLength)
609 term' <- parseFromString inline term
610 term' <- parseFromString inline term
610− contents' <- parseFromString parseBlocks $ first ++ cont
611+ contents' <- parseFromString parseBlocks $ first ++ blank ++ cont
611 return $ (,) <$> term' <*> fmap (:[]) contents'
612 return $ (,) <$> term' <*> fmap (:[]) contents'
612
613
613
614
@@ -617,16 +618,18 @@ listItem :: OrgParser Int
617listItem start = try $ do
618listItem start = try $ do
618 markerLength <- try start
619 markerLength <- try start
619 firstLine <- anyLineNewline
620 firstLine <- anyLineNewline
621+ blank <- option "" ("\n" <$ blankline)
620 rest <- concat <$> many (listContinuation markerLength)
622 rest <- concat <$> many (listContinuation markerLength)
621− parseFromString parseBlocks $ firstLine ++ rest
623+ parseFromString parseBlocks $ firstLine ++ blank ++ rest
622
624
623-- continuation of a list item - indented and separated by blankline or endline.
625-- continuation of a list item - indented and separated by blankline or endline.
624-- Note: nested lists are parsed as continuations.
626-- Note: nested lists are parsed as continuations.
625listContinuation :: Int
627listContinuation :: Int
626 -> OrgParser String
628 -> OrgParser String
627listContinuation markerLength = try $
629listContinuation markerLength = try $
628− mappend <$> many blankline
630+ notFollowedBy' blankline
629− <*> (concat <$> many1 listLine)
631+ *> (mappend <$> (concat <$> many1 listLine)
632+ <*> many blankline)
630 where listLine = try $ indentWith markerLength *> anyLineNewline
633 where listLine = try $ indentWith markerLength *> anyLineNewline
631
634
632anyLineNewline :: OrgParser String
635anyLineNewline :: OrgParser String
tests/Tests/Readers/Org.hs+16−5
@@ -518,13 +518,24 @@ tests =
518 , ("TTL", [ plain $ "transistor-transistor" <> space <>
518 , ("TTL", [ plain $ "transistor-transistor" <> space <>
519 "logic" ])
519 "logic" ])
520 , ("PSK", [ mconcat
520 , ("PSK", [ mconcat
521− [ para $ "phase-shift" <> space <> "keying"
521+ [ para $ "phase-shift" <> space <> "keying"
522− , plain $ spcSep [ "a", "digital"
522+ , para $ spcSep [ "a", "digital"
523− , "modulation", "scheme" ]
523+ , "modulation", "scheme" ]
524 ]
524 ]
525− ]
525+ ])
526− )
527 ]
526 ]
527+
528+ , "Loose bullet list" =:
529+ unlines [ "- apple"
530+ , ""
531+ , "- orange"
532+ , ""
533+ , "- peach"
534+ ] =?>
535+ bulletList [ para "apple"
536+ , para "orange"
537+ , para "peach"
538+ ]
528 ]
539 ]
529
540
530 , testGroup "Tables"
541 , testGroup "Tables"