git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: fix parsing of nested definition lists
22b69b5Alexander Krotov
src/Text/Pandoc/Readers/Muse.hs+10−11
@@ -467,26 +467,25 @@ orderedList = try $ do
467 rest <- many $ listItem (col - 1) (void (orderedListMarker style delim))
467 rest <- many $ listItem (col - 1) (void (orderedListMarker style delim))
468 return $ B.orderedListWith p <$> sequence (first : rest)
468 return $ B.orderedListWith p <$> sequence (first : rest)
469
469
470−definitionListItem :: PandocMonad m => MuseParser m (F (Inlines, [Blocks]))
470+definitionListItem :: PandocMonad m => Int -> MuseParser m (F (Inlines, [Blocks]))
471−definitionListItem = try $ do
471+definitionListItem n = try $ do
472− many spaceChar
472+ count n spaceChar
473 pos <- getPosition
473 pos <- getPosition
474− (guardDisabled Ext_amuse) <|> (guard (sourceColumn pos /= 1)) -- Initial space is required by Amusewiki, but not Emacs Muse
475 term <- trimInlinesF . mconcat <$> manyTill (choice inlineList) (string "::")
474 term <- trimInlinesF . mconcat <$> manyTill (choice inlineList) (string "::")
476 void spaceChar <|> lookAhead eol
475 void spaceChar <|> lookAhead eol
477 contents <- listItemContents' $ sourceColumn pos
476 contents <- listItemContents' $ sourceColumn pos
478− optionMaybe blankline
479 pure $ do lineContent' <- contents
477 pure $ do lineContent' <- contents
480 term' <- term
478 term' <- term
481 pure (term', [lineContent'])
479 pure (term', [lineContent'])
482
480
483−definitionListItems :: PandocMonad m => MuseParser m (F [(Inlines, [Blocks])])
484−definitionListItems = sequence <$> many1 definitionListItem
485−
486definitionList :: PandocMonad m => MuseParser m (F Blocks)
481definitionList :: PandocMonad m => MuseParser m (F Blocks)
487−definitionList = do
482+definitionList = try $ do
488− items <- definitionListItems
483+ many spaceChar
484+ pos <- getPosition
485+ (guardDisabled Ext_amuse) <|> (guard (sourceColumn pos /= 1)) -- Initial space is required by Amusewiki, but not Emacs Muse
486+ first <- definitionListItem 0
487+ rest <- many $ try (optionMaybe blankline >> definitionListItem (sourceColumn pos - 1))
489− return $ B.definitionList <$> items
488+ return $ B.definitionList <$> sequence (first : rest)
490
489
491--
490--
492-- tables
491-- tables
test/Tests/Readers/Muse.hs+11−1
@@ -960,9 +960,19 @@ tests =
960 definitionList [ ("Term1", [ para "This is a first definition\nAnd it has two lines;\nno, make that three."])
960 definitionList [ ("Term1", [ para "This is a first definition\nAnd it has two lines;\nno, make that three."])
961 , ("Term2", [ para "This is a second definition"])
961 , ("Term2", [ para "This is a second definition"])
962 ])
962 ])
963− , "Nested definition list" =:
963+ , "One-line nested definition list" =:
964 " Foo :: bar :: baz" =?>
964 " Foo :: bar :: baz" =?>
965 definitionList [ ("Foo", [ definitionList [ ("bar", [ para "baz" ])]])]
965 definitionList [ ("Foo", [ definitionList [ ("bar", [ para "baz" ])]])]
966+ , "Nested definition list" =:
967+ T.unlines
968+ [ " First :: Second :: Third"
969+ , " Fourth :: Fifth :: Sixth"
970+ , " Seventh :: Eighth"
971+ ] =?>
972+ definitionList [ ("First", [ definitionList [ ("Second", [ para "Third" ]),
973+ ("Fourth", [ definitionList [ ("Fifth", [ para "Sixth"] ) ] ] ) ] ] )
974+ , ("Seventh", [ para "Eighth" ])
975+ ]
966 , "Two blank lines separate definition lists" =:
976 , "Two blank lines separate definition lists" =:
967 T.unlines
977 T.unlines
968 [ " First :: list"
978 [ " First :: list"