git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse definition list terms without parseFromString
commit19d257622356e603d56f3d4350b586420ed63dcb authorAlexander Krotov <ilabdsf@gmail.com> dateFri 19 Jan 2018, 01:41 (9 years ago) parent7e2c75c
2 files changed+15−17
src/Text/Pandoc/Readers/Muse.hs+13−17 test/Tests/Readers/Muse.hs+2
src/Text/Pandoc/Readers/Muse.hs+13−17
@@ -473,10 +473,7 @@ definitionListItem = try $ do
473473 guardDisabled Ext_amuse <|> void spaceChar -- Initial space is required by Amusewiki, but not Emacs Muse
474474 many spaceChar
475475 pos <- getPosition
476− rawTerm <- many1Till (noneOf "\n") (lookAhead (void (try (spaceChar >> string "::"))))
477− term <- parseFromString (trimInlinesF . mconcat <$> many inline) rawTerm
478− many1 spaceChar
479− string "::"
476+ term <- trimInlinesF . mconcat <$> manyTill (choice inlineList) (string "::")
480477 void spaceChar <|> lookAhead eol
481478 contents <- listItemContents' $ sourceColumn pos
482479 optionMaybe blankline
@@ -587,7 +584,7 @@ tableParseCaption = try $ do
587584--
588585
589586inlineList :: PandocMonad m => [MuseParser m (F Inlines)]
590−inlineList = [ endline
587+inlineList = [ whitespace
591588 , br
592589 , anchor
593590 , footnote
@@ -605,13 +602,12 @@ inlineList = [ endline
605602 , code
606603 , codeTag
607604 , inlineLiteralTag
608− , whitespace
609605 , str
610606 , symbol
611607 ]
612608
613609inline :: PandocMonad m => MuseParser m (F Inlines)
614−inline = choice inlineList <?> "inline"
610+inline = choice [endline, linebreak] <|> choice inlineList <?> "inline"
615611
616612endline :: PandocMonad m => MuseParser m (F Inlines)
617613endline = try $ do
@@ -645,23 +641,23 @@ footnote = try $ do
645641 let contents' = runF contents st { stateNotes' = M.empty }
646642 return $ B.note contents'
647643
644+linebreak :: PandocMonad m => MuseParser m (F Inlines)
645+linebreak = try $ do
646+ skipMany spaceChar
647+ newline
648+ notFollowedBy newline
649+ return $ return B.space
650+
648651whitespace :: PandocMonad m => MuseParser m (F Inlines)
649−whitespace = return <$> (lb <|> regsp)
650− where lb = try $ skipMany spaceChar >> linebreak >> return B.space
651− regsp = try $ skipMany1 spaceChar >> return B.space
652+whitespace = try $ do
653+ skipMany1 spaceChar
654+ return $ return B.space
652655
653656br :: PandocMonad m => MuseParser m (F Inlines)
654657br = try $ do
655658 string "<br>"
656659 return $ return B.linebreak
657660
658−linebreak :: PandocMonad m => MuseParser m (F Inlines)
659−linebreak = newline >> notFollowedBy newline >> (lastNewline <|> innerNewline)
660− where lastNewline = do
661− eof
662− return $ return mempty
663− innerNewline = return $ return B.space
664−
665661emphasisBetween :: (PandocMonad m, Show a) => MuseParser m a -> MuseParser m (F Inlines)
666662emphasisBetween c = try $ enclosedInlines c c
667663
test/Tests/Readers/Muse.hs+2
@@ -924,6 +924,8 @@ tests =
924924 definitionList [ ("foo", [ para "bar" ]) ]
925925 , "Definition list term with emphasis" =: " *Foo* :: bar\n" =?>
926926 definitionList [ (emph "Foo", [ para "bar" ]) ]
927+ , "Definition list term with :: inside code" =: " foo <code> :: </code> :: bar <code> :: </code> baz\n" =?>
928+ definitionList [ ("foo " <> code " :: ", [ para $ "bar " <> code " :: " <> " baz" ]) ]
927929 , "Multi-line definition lists" =:
928930 T.unlines
929931 [ " First term :: Definition of first term"