aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <ilabdsf@gmail.com>2017-08-29 22:40:34 +0300
committerJohn MacFarlane <jgm@berkeley.edu>2017-08-29 12:40:34 -0700
commit14f813c3f294739f3965058e27eb228ab3ed90d5 (patch)
tree5aa7fadc875f136e947b0fab0ef001f57035607f
parent2d936ff4e08c8b77f2dac0b278b85bb7f66658af (diff)
downloadpandoc-14f813c3f294739f3965058e27eb228ab3ed90d5.tar.gz
Muse reader: parse verse markup (#3882)
-rw-r--r--src/Text/Pandoc/Readers/Muse.hs22
-rw-r--r--test/Tests/Readers/Muse.hs24
2 files changed, 45 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index 2947c50d6..a4512cdd7 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -32,7 +32,6 @@ TODO:
- {{{ }}} syntax for <example>
- Page breaks (five "*")
- Headings with anchors (make it round trip with Muse writer)
-- Verse markup (">")
- Org tables
- table.el tables
- Images with attributes (floating and width)
@@ -181,6 +180,7 @@ blockElements = choice [ comment
, rightTag
, quoteTag
, verseTag
+ , lineBlock
, bulletList
, orderedList
, definitionList
@@ -299,6 +299,26 @@ noteBlock = try $ do
many1Till block (eof <|> () <$ lookAhead noteMarker)
--
+-- Verse markup
+--
+
+lineVerseLine :: PandocMonad m => MuseParser m String
+lineVerseLine = try $ do
+ char '>'
+ white <- many1 (char ' ' >> pure '\160')
+ rest <- anyLine
+ return $ tail white ++ rest
+
+blanklineVerseLine :: PandocMonad m => MuseParser m Char
+blanklineVerseLine = try $ char '>' >> blankline
+
+lineBlock :: PandocMonad m => MuseParser m (F Blocks)
+lineBlock = try $ do
+ lns <- many1 (pure <$> blanklineVerseLine <|> lineVerseLine)
+ lns' <- mapM (parseFromString' (trimInlinesF . mconcat <$> many inline)) lns
+ return $ B.lineBlock <$> sequence lns'
+
+--
-- lists
--
diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs
index 1f3218daf..4e5e5b606 100644
--- a/test/Tests/Readers/Muse.hs
+++ b/test/Tests/Readers/Muse.hs
@@ -145,6 +145,30 @@ tests =
, " with a continuation"
] =?>
blockQuote (para "This is a quotation with a continuation")
+ , "Verse" =:
+ T.unlines [ "> This is"
+ , "> First stanza"
+ , ">" -- Emacs produces verbatim ">" here, we follow Amusewiki
+ , "> And this is"
+ , "> Second stanza"
+ , ">"
+ , ""
+ , ">"
+ , ""
+ , "> Another verse"
+ , "> is here"
+ ] =?>
+ lineBlock [ "This is"
+ , "First stanza"
+ , ""
+ , "And this is"
+ , "\160\160Second stanza"
+ , ""
+ ] <>
+ lineBlock [ "" ] <>
+ lineBlock [ "Another verse"
+ , "\160\160\160is here"
+ ]
]
, "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
, "Verse tag" =: