git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse definition list terms without parseFromString
19d2576Alexander Krotov
src/Text/Pandoc/Readers/Muse.hs+13−17
@@ -473,10 +473,7 @@ definitionListItem = try $ do
473 guardDisabled Ext_amuse <|> void spaceChar -- Initial space is required by Amusewiki, but not Emacs Muse
473 guardDisabled Ext_amuse <|> void spaceChar -- Initial space is required by Amusewiki, but not Emacs Muse
474 many spaceChar
474 many spaceChar
475 pos <- getPosition
475 pos <- getPosition
476− rawTerm <- many1Till (noneOf "\n") (lookAhead (void (try (spaceChar >> string "::"))))
477− term <- parseFromString (trimInlinesF . mconcat <$> many inline) rawTerm
476+ term <- trimInlinesF . mconcat <$> manyTill (choice inlineList) (string "::")
478− many1 spaceChar
479− string "::"
480 void spaceChar <|> lookAhead eol
477 void spaceChar <|> lookAhead eol
481 contents <- listItemContents' $ sourceColumn pos
478 contents <- listItemContents' $ sourceColumn pos
482 optionMaybe blankline
479 optionMaybe blankline
@@ -587,7 +584,7 @@ tableParseCaption = try $ do
587--
584--
588
585
589inlineList :: PandocMonad m => [MuseParser m (F Inlines)]
586inlineList :: PandocMonad m => [MuseParser m (F Inlines)]
590−inlineList = [ endline
587+inlineList = [ whitespace
591 , br
588 , br
592 , anchor
589 , anchor
593 , footnote
590 , footnote
@@ -605,13 +602,12 @@ inlineList = [ endline
605 , code
602 , code
606 , codeTag
603 , codeTag
607 , inlineLiteralTag
604 , inlineLiteralTag
608− , whitespace
609 , str
605 , str
610 , symbol
606 , symbol
611 ]
607 ]
612
608
613inline :: PandocMonad m => MuseParser m (F Inlines)
609inline :: PandocMonad m => MuseParser m (F Inlines)
614−inline = choice inlineList <?> "inline"
610+inline = choice [endline, linebreak] <|> choice inlineList <?> "inline"
615
611
616endline :: PandocMonad m => MuseParser m (F Inlines)
612endline :: PandocMonad m => MuseParser m (F Inlines)
617endline = try $ do
613endline = try $ do
@@ -645,23 +641,23 @@ footnote = try $ do
645 let contents' = runF contents st { stateNotes' = M.empty }
641 let contents' = runF contents st { stateNotes' = M.empty }
646 return $ B.note contents'
642 return $ B.note contents'
647
643
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+
648whitespace :: PandocMonad m => MuseParser m (F Inlines)
651whitespace :: PandocMonad m => MuseParser m (F Inlines)
649−whitespace = return <$> (lb <|> regsp)
652+whitespace = try $ do
650− where lb = try $ skipMany spaceChar >> linebreak >> return B.space
651− regsp = try $ skipMany1 spaceChar >> return B.space
653+ skipMany1 spaceChar
654+ return $ return B.space
652
655
653br :: PandocMonad m => MuseParser m (F Inlines)
656br :: PandocMonad m => MuseParser m (F Inlines)
654br = try $ do
657br = try $ do
655 string "<br>"
658 string "<br>"
656 return $ return B.linebreak
659 return $ return B.linebreak
657
660
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−
665emphasisBetween :: (PandocMonad m, Show a) => MuseParser m a -> MuseParser m (F Inlines)
661emphasisBetween :: (PandocMonad m, Show a) => MuseParser m a -> MuseParser m (F Inlines)
666emphasisBetween c = try $ enclosedInlines c c
662emphasisBetween c = try $ enclosedInlines c c
667
663
test/Tests/Readers/Muse.hs+2
@@ -924,6 +924,8 @@ tests =
924 definitionList [ ("foo", [ para "bar" ]) ]
924 definitionList [ ("foo", [ para "bar" ]) ]
925 , "Definition list term with emphasis" =: " *Foo* :: bar\n" =?>
925 , "Definition list term with emphasis" =: " *Foo* :: bar\n" =?>
926 definitionList [ (emph "Foo", [ para "bar" ]) ]
926 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" ]) ]
927 , "Multi-line definition lists" =:
929 , "Multi-line definition lists" =:
928 T.unlines
930 T.unlines
929 [ " First term :: Definition of first term"
931 [ " First term :: Definition of first term"