git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse definition lists with multiple descriptions
commit42e39fbd2678fb8480b6253232ffe0258d2bae00 authorAlexander Krotov <ilabdsf@gmail.com> dateTue 13 Feb 2018, 08:55 (9 years ago) parent5a30436
2 files changed+45−21
src/Text/Pandoc/Readers/Muse.hs+25−14 test/Tests/Readers/Muse.hs+20−7
src/Text/Pandoc/Readers/Muse.hs+25−14
@@ -631,26 +631,37 @@ orderedListUntil end = try $ do
631631 (items, e) <- orderedListItemsUntil indent style end
632632 return $ (B.orderedListWith p <$> sequence items, e)
633633
634+descriptionsUntil :: PandocMonad m
635+ => Int
636+ -> MuseParser m a
637+ -> MuseParser m ([F Blocks], a)
638+descriptionsUntil indent end = do
639+ void spaceChar <|> lookAhead eol
640+ st <- getState
641+ setState $ st{ museInPara = False }
642+ (x, e) <- listItemContentsUntil indent (Right <$> try (optional blankline >> indentWith indent >> manyTill spaceChar (string "::") >> descriptionsUntil indent end)) (Left <$> end)
643+ case e of
644+ Right (xs, ee) -> return (x:xs, ee)
645+ Left ee -> return ([x], ee)
646+
634647definitionListItemsUntil :: PandocMonad m
635648 => Int
636649 -> MuseParser m a
637650 -> MuseParser m ([F (Inlines, [Blocks])], a)
638651definitionListItemsUntil indent end =
639652 continuation
640− where continuation = try $ do
641− pos <- getPosition
642− term <- trimInlinesF . mconcat <$> manyTill (choice inlineList) (string "::")
643− void spaceChar <|> lookAhead eol
644− st <- getState
645− setState $ st{ museInPara = False }
646− (x, e) <- listItemContentsUntil (sourceColumn pos) ((Right <$> try (optional blankline >> count indent spaceChar >> continuation)) <|> (Left <$> end))
647− let xx = do
648− term' <- term
649− x' <- x
650− (return (term', [x']))::(F (Inlines, [Blocks]))
651− case e of
652− Left ee -> return $ ([xx], ee)
653− Right (xs, ee) -> return $ (xx : xs, ee)
653+ where
654+ continuation = try $ do
655+ pos <- getPosition
656+ term <- trimInlinesF . mconcat <$> manyTill (choice inlineList) (string "::")
657+ (x, e) <- descriptionsUntil (sourceColumn pos) ((Right <$> try (optional blankline >> indentWith indent >> continuation)) <|> (Left <$> end))
658+ let xx = do
659+ term' <- term
660+ x' <- sequence x
661+ return (term', x')
662+ case e of
663+ Left ee -> return ([xx], ee)
664+ Right (xs, ee) -> return (xx:xs, ee)
654665
655666definitionListUntil :: PandocMonad m
656667 => MuseParser m a
test/Tests/Readers/Muse.hs+20−7
@@ -28,15 +28,9 @@ spcSep :: [Inlines] -> Inlines
2828spcSep = mconcat . intersperse space
2929
3030-- Tables don't round-trip yet
31−-- Definition lists with multiple descriptions are supported by writer, but not reader yet
32−
33−singleDescription :: ([Inline], [[Block]]) -> ([Inline], [[Block]])
34−singleDescription (a, x:_) = (a, [x])
35−singleDescription x = x
36−
31+--
3732makeRoundTrip :: Block -> Block
3833makeRoundTrip Table{} = Para [Str "table was here"]
39−makeRoundTrip (DefinitionList items) = DefinitionList $ map singleDescription items
4034makeRoundTrip x = x
4135
4236-- Demand that any AST produced by Muse reader and written by Muse writer can be read back exactly the same way.
@@ -1092,6 +1086,25 @@ tests =
10921086 ("Fourth", [ definitionList [ ("Fifth", [ para "Sixth"] ) ] ] ) ] ] )
10931087 , ("Seventh", [ para "Eighth" ])
10941088 ]
1089+ , testGroup "Definition lists with multiple descriptions"
1090+ [ "Correctly indented second description" =:
1091+ T.unlines
1092+ [ " First term :: first description"
1093+ , " :: second description"
1094+ ] =?>
1095+ definitionList [ ("First term", [ para "first description"
1096+ , para "second description"
1097+ ])
1098+ ]
1099+ , "Incorrectly indented second description" =:
1100+ T.unlines
1101+ [ " First term :: first description"
1102+ , " :: second description"
1103+ ] =?>
1104+ definitionList [ ("First term", [ para "first description" ])
1105+ , ("", [ para "second description" ])
1106+ ]
1107+ ]
10951108 , "Two blank lines separate definition lists" =:
10961109 T.unlines
10971110 [ " First :: list"