Muse reader: parse indented blockquotes (#3769)
This commit is contained in:
parent
cd690d0401
commit
79cc56726c
2 changed files with 28 additions and 2 deletions
|
@ -187,6 +187,7 @@ blockElements = choice [ comment
|
|||
, orderedList
|
||||
, table
|
||||
, commentTag
|
||||
, indentedBlock
|
||||
, noteBlock
|
||||
]
|
||||
|
||||
|
@ -209,7 +210,8 @@ separator = try $ do
|
|||
header :: PandocMonad m => MuseParser m (F Blocks)
|
||||
header = try $ do
|
||||
st <- stateParserContext <$> getState
|
||||
getPosition >>= \pos -> guard (st == NullState && sourceColumn pos == 1)
|
||||
q <- stateQuoteContext <$> getState
|
||||
getPosition >>= \pos -> guard (st == NullState && q == NoQuote && sourceColumn pos == 1)
|
||||
level <- liftM length $ many1 $ char '*'
|
||||
guard $ level <= 5
|
||||
skipSpaces
|
||||
|
@ -248,6 +250,25 @@ quoteTag = blockTag B.blockQuote "quote"
|
|||
commentTag :: PandocMonad m => MuseParser m (F Blocks)
|
||||
commentTag = parseHtmlContent "comment" block >> return mempty
|
||||
|
||||
-- Indented block is either center, right or quote
|
||||
indentedLine :: PandocMonad m => MuseParser m (Int, String)
|
||||
indentedLine = try $ do
|
||||
indent <- length <$> many1 spaceChar
|
||||
line <- anyLine
|
||||
return (indent, line)
|
||||
|
||||
rawIndentedBlock :: PandocMonad m => MuseParser m (Int, String)
|
||||
rawIndentedBlock = try $ do
|
||||
lns <- many1 indentedLine
|
||||
let indent = minimum $ map fst lns
|
||||
return (indent, unlines $ map snd lns)
|
||||
|
||||
indentedBlock :: PandocMonad m => MuseParser m (F Blocks)
|
||||
indentedBlock = try $ do
|
||||
(indent, raw) <- rawIndentedBlock
|
||||
contents <- withQuoteContext InDoubleQuote $ parseFromString parseBlocks raw
|
||||
return $ (if indent >= 2 && indent < 6 then B.blockQuote else id) <$> contents
|
||||
|
||||
para :: PandocMonad m => MuseParser m (F Blocks)
|
||||
para = liftM B.para . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
|
||||
where
|
||||
|
|
|
@ -102,7 +102,12 @@ tests =
|
|||
, "5 dashes is a horizontal rule" =: "-----" =?> horizontalRule
|
||||
, "4 dashes with spaces is a horizontal rule" =: "---- " =?> horizontalRule
|
||||
]
|
||||
, "Quote" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
|
||||
, "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
|
||||
, "Quote" =: " This is a quotation\n" =?> blockQuote (para $ text "This is a quotation")
|
||||
, "Multiline quote" =: T.unlines [ " This is a quotation"
|
||||
, " with a continuation"
|
||||
]
|
||||
=?> blockQuote (para $ text "This is a quotation with a continuation")
|
||||
, "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
|
||||
, "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
|
||||
, testGroup "Comments"
|
||||
|
|
Loading…
Add table
Reference in a new issue