From 56685e8735e62af2855ae5703a10829979f32a46 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Fri, 31 Aug 2018 15:57:58 +0300 Subject: Muse reader: parse tag in one pass instead of using parseFromString. This change makes it possible to have verbatim tag inside verse. --- src/Text/Pandoc/Readers/Muse.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 2c21d377e..2b55251e8 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -462,16 +462,19 @@ verseLine = do rest <- manyTill (choice inlineList) newline return $ trimInlinesF $ mconcat (pure indent : rest) -verseLines :: PandocMonad m => MuseParser m (F Blocks) -verseLines = do - lns <- many verseLine - return $ B.lineBlock <$> sequence lns - -- | Parse @\@ tag. verseTag :: PandocMonad m => MuseParser m (F Blocks) -verseTag = do - (_, content) <- htmlBlock "verse" - parseFromString verseLines (intercalate "\n" $ dropSpacePrefix $ splitOn "\n" $ lchop content) +verseTag = try $ do + many spaceChar + pos <- getPosition + (TagOpen _ _, _) <- htmlTag (~== TagOpen "verse" []) + manyTill spaceChar eol + let indent = count (sourceColumn pos - 1) spaceChar + content <- sequence <$> manyTill (indent >> verseLine) (try $ indent >> endtag) + manyTill spaceChar eol + return $ B.lineBlock <$> content + where + endtag = void $ htmlTag (~== TagClose "verse") -- | Parse @\@ tag. commentTag :: PandocMonad m => MuseParser m (F Blocks) -- cgit v1.2.3