git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse verse markup (#3882)
commit14f813c3f294739f3965058e27eb228ab3ed90d5 authorAlexander <ilabdsf@gmail.com> dateTue 29 Aug 2017, 22:40 (9 years ago) parent2d936ff
2 files changed+45−1
src/Text/Pandoc/Readers/Muse.hs+21−1 test/Tests/Readers/Muse.hs+24
src/Text/Pandoc/Readers/Muse.hs+21−1
@@ -32,7 +32,6 @@ TODO:
3232- {{{ }}} syntax for <example>
3333- Page breaks (five "*")
3434- Headings with anchors (make it round trip with Muse writer)
35−- Verse markup (">")
3635- Org tables
3736- table.el tables
3837- Images with attributes (floating and width)
@@ -181,6 +180,7 @@ blockElements = choice [ comment
181180 , rightTag
182181 , quoteTag
183182 , verseTag
183+ , lineBlock
184184 , bulletList
185185 , orderedList
186186 , definitionList
@@ -298,6 +298,26 @@ noteBlock = try $ do
298298 blocksTillNote =
299299 many1Till block (eof <|> () <$ lookAhead noteMarker)
300300
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+
301321--
302322-- lists
303323--
test/Tests/Readers/Muse.hs+24
@@ -145,6 +145,30 @@ tests =
145145 , " with a continuation"
146146 ] =?>
147147 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+ ]
148172 ]
149173 , "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
150174 , "Verse tag" =: