aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-08-31 15:57:58 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-08-31 16:43:07 +0300
commit56685e8735e62af2855ae5703a10829979f32a46 (patch)
tree1352df00bf5170a3934492443138a2dc0558686a /src/Text/Pandoc
parentd63202c2f40123acf0a8f0242b53eeffd11c51e2 (diff)
downloadpandoc-56685e8735e62af2855ae5703a10829979f32a46.tar.gz
Muse reader: parse <verse> tag in one pass
instead of using parseFromString. This change makes it possible to have verbatim </verse> tag inside verse.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Muse.hs19
1 files changed, 11 insertions, 8 deletions
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 @\<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)