Muse reader: parse verse markup (#3882)

This commit is contained in:
Alexander 2017-08-29 22:40:34 +03:00 committed by John MacFarlane
parent 2d936ff4e0
commit 14f813c3f2
2 changed files with 45 additions and 1 deletions

View file

@ -32,7 +32,6 @@ TODO:
- {{{ }}} syntax for <example>
- Page breaks (five "*")
- Headings with anchors (make it round trip with Muse writer)
- Verse markup (">")
- Org tables
- table.el tables
- Images with attributes (floating and width)
@ -181,6 +180,7 @@ blockElements = choice [ comment
, rightTag
, quoteTag
, verseTag
, lineBlock
, bulletList
, orderedList
, definitionList
@ -298,6 +298,26 @@ noteBlock = try $ do
blocksTillNote =
many1Till block (eof <|> () <$ lookAhead noteMarker)
--
-- Verse markup
--
lineVerseLine :: PandocMonad m => MuseParser m String
lineVerseLine = try $ do
char '>'
white <- many1 (char ' ' >> pure '\160')
rest <- anyLine
return $ tail white ++ rest
blanklineVerseLine :: PandocMonad m => MuseParser m Char
blanklineVerseLine = try $ char '>' >> blankline
lineBlock :: PandocMonad m => MuseParser m (F Blocks)
lineBlock = try $ do
lns <- many1 (pure <$> blanklineVerseLine <|> lineVerseLine)
lns' <- mapM (parseFromString' (trimInlinesF . mconcat <$> many inline)) lns
return $ B.lineBlock <$> sequence lns'
--
-- lists
--

View file

@ -145,6 +145,30 @@ tests =
, " with a continuation"
] =?>
blockQuote (para "This is a quotation with a continuation")
, "Verse" =:
T.unlines [ "> This is"
, "> First stanza"
, ">" -- Emacs produces verbatim ">" here, we follow Amusewiki
, "> And this is"
, "> Second stanza"
, ">"
, ""
, ">"
, ""
, "> Another verse"
, "> is here"
] =?>
lineBlock [ "This is"
, "First stanza"
, ""
, "And this is"
, "\160\160Second stanza"
, ""
] <>
lineBlock [ "" ] <>
lineBlock [ "Another verse"
, "\160\160\160is here"
]
]
, "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
, "Verse tag" =: