git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse verse markup (#3882)
14f813cAlexander
src/Text/Pandoc/Readers/Muse.hs+21−1
@@ -32,7 +32,6 @@ TODO:
32- {{{ }}} syntax for <example>
32- {{{ }}} syntax for <example>
33- Page breaks (five "*")
33- Page breaks (five "*")
34- Headings with anchors (make it round trip with Muse writer)
34- Headings with anchors (make it round trip with Muse writer)
35−- Verse markup (">")
36- Org tables
35- Org tables
37- table.el tables
36- table.el tables
38- Images with attributes (floating and width)
37- Images with attributes (floating and width)
@@ -181,6 +180,7 @@ blockElements = choice [ comment
181 , rightTag
180 , rightTag
182 , quoteTag
181 , quoteTag
183 , verseTag
182 , verseTag
183+ , lineBlock
184 , bulletList
184 , bulletList
185 , orderedList
185 , orderedList
186 , definitionList
186 , definitionList
@@ -298,6 +298,26 @@ noteBlock = try $ do
298 blocksTillNote =
298 blocksTillNote =
299 many1Till block (eof <|> () <$ lookAhead noteMarker)
299 many1Till block (eof <|> () <$ lookAhead noteMarker)
300
300
301+--
302+-- Verse markup
303+--
304+
305+lineVerseLine :: PandocMonad m => MuseParser m String
306+lineVerseLine = try $ do
307+ char '>'
308+ white <- many1 (char ' ' >> pure '\160')
309+ rest <- anyLine
310+ return $ tail white ++ rest
311+
312+blanklineVerseLine :: PandocMonad m => MuseParser m Char
313+blanklineVerseLine = try $ char '>' >> blankline
314+
315+lineBlock :: PandocMonad m => MuseParser m (F Blocks)
316+lineBlock = try $ do
317+ lns <- many1 (pure <$> blanklineVerseLine <|> lineVerseLine)
318+ lns' <- mapM (parseFromString' (trimInlinesF . mconcat <$> many inline)) lns
319+ return $ B.lineBlock <$> sequence lns'
320+
301--
321--
302-- lists
322-- lists
303--
323--
test/Tests/Readers/Muse.hs+24
@@ -145,6 +145,30 @@ tests =
145 , " with a continuation"
145 , " with a continuation"
146 ] =?>
146 ] =?>
147 blockQuote (para "This is a quotation with a continuation")
147 blockQuote (para "This is a quotation with a continuation")
148+ , "Verse" =:
149+ T.unlines [ "> This is"
150+ , "> First stanza"
151+ , ">" -- Emacs produces verbatim ">" here, we follow Amusewiki
152+ , "> And this is"
153+ , "> Second stanza"
154+ , ">"
155+ , ""
156+ , ">"
157+ , ""
158+ , "> Another verse"
159+ , "> is here"
160+ ] =?>
161+ lineBlock [ "This is"
162+ , "First stanza"
163+ , ""
164+ , "And this is"
165+ , "\160\160Second stanza"
166+ , ""
167+ ] <>
168+ lineBlock [ "" ] <>
169+ lineBlock [ "Another verse"
170+ , "\160\160\160is here"
171+ ]
148 ]
172 ]
149 , "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
173 , "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
150 , "Verse tag" =:
174 , "Verse tag" =: