Muse reader: parse <verse> tag (#3872)

This commit is contained in:
Alexander 2017-08-25 17:09:28 +03:00 committed by John MacFarlane
parent ef209ebad2
commit e6f767b581
2 changed files with 42 additions and 1 deletions

View file

@ -32,7 +32,7 @@ TODO:
- {{{ }}} syntax for <example> - {{{ }}} syntax for <example>
- Page breaks (five "*") - Page breaks (five "*")
- Headings with anchors (make it round trip with Muse writer) - Headings with anchors (make it round trip with Muse writer)
- <verse> and ">" - Verse markup (">")
- Org tables - Org tables
- table.el tables - table.el tables
- Images with attributes (floating and width) - Images with attributes (floating and width)
@ -180,6 +180,7 @@ blockElements = choice [ comment
, centerTag , centerTag
, rightTag , rightTag
, quoteTag , quoteTag
, verseTag
, bulletList , bulletList
, orderedList , orderedList
, definitionList , definitionList
@ -244,6 +245,25 @@ rightTag = blockTag id "right"
quoteTag :: PandocMonad m => MuseParser m (F Blocks) quoteTag :: PandocMonad m => MuseParser m (F Blocks)
quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote" quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
verseLine :: PandocMonad m => MuseParser m String
verseLine = do
line <- anyLine <|> many1Till anyChar eof
let (white, rest) = span (== ' ') line
return $ replicate (length white) '\160' ++ rest
verseLines :: PandocMonad m => MuseParser m (F Blocks)
verseLines = do
optionMaybe blankline -- Skip blankline after opening tag on separate line
lns <- many verseLine
lns' <- mapM (parseFromString' (trimInlinesF . mconcat <$> many inline)) lns
return $ B.lineBlock <$> sequence lns'
verseTag :: PandocMonad m => MuseParser m (F Blocks)
verseTag = do
(_, content) <- htmlElement "verse"
parsedContent <- parseFromString verseLines content
return parsedContent
commentTag :: PandocMonad m => MuseParser m (F Blocks) commentTag :: PandocMonad m => MuseParser m (F Blocks)
commentTag = parseHtmlContent "comment" anyChar >> return mempty commentTag = parseHtmlContent "comment" anyChar >> return mempty

View file

@ -147,6 +147,27 @@ tests =
blockQuote (para "This is a quotation with a continuation") blockQuote (para "This is a quotation with a continuation")
] ]
, "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world") , "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
, "Verse tag" =:
T.unlines [ "<verse>"
, ""
, "Foo bar baz"
, " One two three"
, ""
, "</verse>"
, "<verse>Foo bar</verse>"
, "<verse>"
, "Foo bar</verse>"
, "<verse>"
, " Foo</verse>"
] =?>
lineBlock [ ""
, text "Foo bar baz"
, text "\160\160One two three"
, ""
] <>
lineBlock [ "Foo bar" ] <>
lineBlock [ "Foo bar" ] <>
lineBlock [ "\160\160\160Foo" ]
, "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world") , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
, "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world") , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
, testGroup "Comments" , testGroup "Comments"