git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse <verse> tag (#3872)
e6f767bAlexander
src/Text/Pandoc/Readers/Muse.hs+21−1
@@ -32,7 +32,7 @@ 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> and ">"
35+- Verse markup (">")
36- Org tables
36- Org tables
37- table.el tables
37- table.el tables
38- Images with attributes (floating and width)
38- Images with attributes (floating and width)
@@ -180,6 +180,7 @@ blockElements = choice [ comment
180 , centerTag
180 , centerTag
181 , rightTag
181 , rightTag
182 , quoteTag
182 , quoteTag
183+ , verseTag
183 , bulletList
184 , bulletList
184 , orderedList
185 , orderedList
185 , definitionList
186 , definitionList
@@ -244,6 +245,25 @@ rightTag = blockTag id "right"
244quoteTag :: PandocMonad m => MuseParser m (F Blocks)
245quoteTag :: PandocMonad m => MuseParser m (F Blocks)
245quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
246quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
246
247
248+verseLine :: PandocMonad m => MuseParser m String
249+verseLine = do
250+ line <- anyLine <|> many1Till anyChar eof
251+ let (white, rest) = span (== ' ') line
252+ return $ replicate (length white) '\160' ++ rest
253+
254+verseLines :: PandocMonad m => MuseParser m (F Blocks)
255+verseLines = do
256+ optionMaybe blankline -- Skip blankline after opening tag on separate line
257+ lns <- many verseLine
258+ lns' <- mapM (parseFromString' (trimInlinesF . mconcat <$> many inline)) lns
259+ return $ B.lineBlock <$> sequence lns'
260+
261+verseTag :: PandocMonad m => MuseParser m (F Blocks)
262+verseTag = do
263+ (_, content) <- htmlElement "verse"
264+ parsedContent <- parseFromString verseLines content
265+ return parsedContent
266+
247commentTag :: PandocMonad m => MuseParser m (F Blocks)
267commentTag :: PandocMonad m => MuseParser m (F Blocks)
248commentTag = parseHtmlContent "comment" anyChar >> return mempty
268commentTag = parseHtmlContent "comment" anyChar >> return mempty
249
269
test/Tests/Readers/Muse.hs+21
@@ -147,6 +147,27 @@ tests =
147 blockQuote (para "This is a quotation with a continuation")
147 blockQuote (para "This is a quotation with a continuation")
148 ]
148 ]
149 , "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
149 , "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
150+ , "Verse tag" =:
151+ T.unlines [ "<verse>"
152+ , ""
153+ , "Foo bar baz"
154+ , " One two three"
155+ , ""
156+ , "</verse>"
157+ , "<verse>Foo bar</verse>"
158+ , "<verse>"
159+ , "Foo bar</verse>"
160+ , "<verse>"
161+ , " Foo</verse>"
162+ ] =?>
163+ lineBlock [ ""
164+ , text "Foo bar baz"
165+ , text "\160\160One two three"
166+ , ""
167+ ] <>
168+ lineBlock [ "Foo bar" ] <>
169+ lineBlock [ "Foo bar" ] <>
170+ lineBlock [ "\160\160\160Foo" ]
150 , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
171 , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
151 , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
172 , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
152 , testGroup "Comments"
173 , testGroup "Comments"