Muse reader: parse <verse> tag in one pass

instead of using parseFromString.

This change makes it possible to have verbatim </verse> tag
inside verse.
This commit is contained in:
Alexander Krotov 2018-08-31 15:57:58 +03:00
parent d63202c2f4
commit 56685e8735
2 changed files with 17 additions and 8 deletions

View file

@ -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 @\<verse>@ 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 @\<comment>@ tag.
commentTag :: PandocMonad m => MuseParser m (F Blocks)

View file

@ -407,6 +407,12 @@ tests =
, "</verse>"
] =?>
lineBlock [ "" ]
, "Verse tag with verbatim close tag inside" =:
T.unlines [ "<verse>"
, "<verbatim></verse></verbatim>"
, "</verse>"
] =?>
lineBlock [ "</verse>" ]
, testGroup "Example"
[ "Braces on separate lines" =:
T.unlines [ "{{{"