git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: refactor definition list parsing

Test with wrong indentation is removed, because now it is parsed as nested lists. Emacs Muse and Text::Amuse don't have the same behavior anyway.

commit5f57094a47c18d1849f7cd5e9306bf05d6187881 authorAlexander Krotov <ilabdsf@gmail.com> dateThu 18 Jan 2018, 14:50 (9 years ago) parent9986ccb
2 files changed+15−28
src/Text/Pandoc/Readers/Muse.hs+15−17 test/Tests/Readers/Muse.hs−11
src/Text/Pandoc/Readers/Muse.hs+15−17
@@ -422,13 +422,17 @@ withListContext p = do
422422 updateState (\st -> st {stateParserContext = oldContext})
423423 return parsed
424424
425+listItemContents' :: PandocMonad m => Int -> MuseParser m (F Blocks)
426+listItemContents' col = do
427+ first <- try $ withListContext parseBlock
428+ rest <- many $ try (skipMany blankline >> indentWith col >> withListContext parseBlock)
429+ return $ mconcat (first : rest)
430+
425431listItemContents :: PandocMonad m => MuseParser m (F Blocks)
426432listItemContents = do
427433 pos <- getPosition
428434 let col = sourceColumn pos - 1
429− first <- try $ withListContext parseBlock
430− rest <- many $ try (skipMany blankline >> indentWith col >> withListContext parseBlock)
431− return $ mconcat (first : rest)
435+ listItemContents' col
432436
433437listItem :: PandocMonad m => Int -> MuseParser m () -> MuseParser m (F Blocks)
434438listItem n p = try $ do
@@ -466,25 +470,19 @@ orderedList = try $ do
466470
467471definitionListItem :: PandocMonad m => MuseParser m (F (Inlines, [Blocks]))
468472definitionListItem = try $ do
469− rawTerm <- termParser
473+ guardDisabled Ext_amuse <|> void spaceChar -- Initial space is required by Amusewiki, but not Emacs Muse
474+ many spaceChar
475+ pos <- getPosition
476+ rawTerm <- many1Till (noneOf "\n") (lookAhead (void (try (spaceChar >> string "::"))))
470477 term <- parseFromString (trimInlinesF . mconcat <$> many inline) rawTerm
471478 many1 spaceChar
472479 string "::"
473− firstLine <- manyTill anyChar eol
474− restLines <- manyTill anyLine endOfListItemElement
475− let lns = dropWhile (== ' ') firstLine : restLines
476− lineContent <- parseFromString (withListContext parseBlocks) $ unlines lns
477− pure $ do lineContent' <- lineContent
480+ void spaceChar <|> lookAhead eol
481+ contents <- listItemContents' $ sourceColumn pos
482+ optionMaybe blankline
483+ pure $ do lineContent' <- contents
478484 term' <- term
479485 pure (term', [lineContent'])
480− where
481− termParser = (guardDisabled Ext_amuse <|> void spaceChar) >> -- Initial space is required by Amusewiki, but not Emacs Muse
482− many spaceChar >>
483− many1Till (noneOf "\n") (lookAhead (void (try (spaceChar >> string "::"))))
484− endOfInput = lookAhead $ try $ skipMany blankline >> skipSpaces >> eof
485− twoBlankLines = try $ blankline >> skipMany1 blankline
486− newDefinitionListItem = try $ void termParser
487− endOfListItemElement = lookAhead $ endOfInput <|> newDefinitionListItem <|> twoBlankLines
488486
489487definitionListItems :: PandocMonad m => MuseParser m (F [(Inlines, [Blocks])])
490488definitionListItems = sequence <$> many1 definitionListItem
test/Tests/Readers/Muse.hs−11
@@ -955,17 +955,6 @@ tests =
955955 definitionList [ ("Term1", [ para "This is a first definition\nAnd it has two lines;\nno, make that three."])
956956 , ("Term2", [ para "This is a second definition"])
957957 ])
958− -- Emacs Muse creates two separate lists when indentation of items is different.
959− -- We follow Amusewiki and allow different indentation within one list.
960− , "Changing indentation" =:
961− T.unlines
962− [ " First term :: Definition of first term"
963− , "and its continuation."
964− , " Second term :: Definition of second term."
965− ] =?>
966− definitionList [ ("First term", [ para "Definition of first term\nand its continuation." ])
967− , ("Second term", [ para "Definition of second term." ])
968− ]
969958 , "Two blank lines separate definition lists" =:
970959 T.unlines
971960 [ " First :: list"