git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse <verse> tag (#3872)
commite6f767b581742343bd7319bcc4c3632e18c58a70 authorAlexander <ilabdsf@gmail.com> dateFri 25 Aug 2017, 17:09 (9 years ago) parentef209eb
2 files changed+42−1
src/Text/Pandoc/Readers/Muse.hs+21−1 test/Tests/Readers/Muse.hs+21
src/Text/Pandoc/Readers/Muse.hs+21−1
@@ -32,7 +32,7 @@ TODO:
3232- {{{ }}} syntax for <example>
3333- Page breaks (five "*")
3434- Headings with anchors (make it round trip with Muse writer)
35−- <verse> and ">"
35+- Verse markup (">")
3636- Org tables
3737- table.el tables
3838- Images with attributes (floating and width)
@@ -180,6 +180,7 @@ blockElements = choice [ comment
180180 , centerTag
181181 , rightTag
182182 , quoteTag
183+ , verseTag
183184 , bulletList
184185 , orderedList
185186 , definitionList
@@ -244,6 +245,25 @@ rightTag = blockTag id "right"
244245quoteTag :: PandocMonad m => MuseParser m (F Blocks)
245246quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
246247
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+
247267commentTag :: PandocMonad m => MuseParser m (F Blocks)
248268commentTag = parseHtmlContent "comment" anyChar >> return mempty
249269
test/Tests/Readers/Muse.hs+21
@@ -147,6 +147,27 @@ tests =
147147 blockQuote (para "This is a quotation with a continuation")
148148 ]
149149 , "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" ]
150171 , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
151172 , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
152173 , testGroup "Comments"