git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse indented blockquotes (#3769)
commit79cc56726c7e876314c7c21f5bb5f65084e7d8b7 authorAlexander Krotov <ilabdsf@gmail.com> dateWed 28 Jun 2017, 15:32 (9 years ago) parentcd690d0
2 files changed+28−2
src/Text/Pandoc/Readers/Muse.hs+22−1 test/Tests/Readers/Muse.hs+6−1
src/Text/Pandoc/Readers/Muse.hs+22−1
@@ -187,6 +187,7 @@ blockElements = choice [ comment
187187 , orderedList
188188 , table
189189 , commentTag
190+ , indentedBlock
190191 , noteBlock
191192 ]
192193
@@ -209,7 +210,8 @@ separator = try $ do
209210header :: PandocMonad m => MuseParser m (F Blocks)
210211header = try $ do
211212 st <- stateParserContext <$> getState
212− getPosition >>= \pos -> guard (st == NullState && sourceColumn pos == 1)
213+ q <- stateQuoteContext <$> getState
214+ getPosition >>= \pos -> guard (st == NullState && q == NoQuote && sourceColumn pos == 1)
213215 level <- liftM length $ many1 $ char '*'
214216 guard $ level <= 5
215217 skipSpaces
@@ -248,6 +250,25 @@ quoteTag = blockTag B.blockQuote "quote"
248250commentTag :: PandocMonad m => MuseParser m (F Blocks)
249251commentTag = parseHtmlContent "comment" block >> return mempty
250252
253+-- Indented block is either center, right or quote
254+indentedLine :: PandocMonad m => MuseParser m (Int, String)
255+indentedLine = try $ do
256+ indent <- length <$> many1 spaceChar
257+ line <- anyLine
258+ return (indent, line)
259+
260+rawIndentedBlock :: PandocMonad m => MuseParser m (Int, String)
261+rawIndentedBlock = try $ do
262+ lns <- many1 indentedLine
263+ let indent = minimum $ map fst lns
264+ return (indent, unlines $ map snd lns)
265+
266+indentedBlock :: PandocMonad m => MuseParser m (F Blocks)
267+indentedBlock = try $ do
268+ (indent, raw) <- rawIndentedBlock
269+ contents <- withQuoteContext InDoubleQuote $ parseFromString parseBlocks raw
270+ return $ (if indent >= 2 && indent < 6 then B.blockQuote else id) <$> contents
271+
251272para :: PandocMonad m => MuseParser m (F Blocks)
252273para = liftM B.para . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
253274 where
test/Tests/Readers/Muse.hs+6−1
@@ -102,7 +102,12 @@ tests =
102102 , "5 dashes is a horizontal rule" =: "-----" =?> horizontalRule
103103 , "4 dashes with spaces is a horizontal rule" =: "---- " =?> horizontalRule
104104 ]
105− , "Quote" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
105+ , "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
106+ , "Quote" =: " This is a quotation\n" =?> blockQuote (para $ text "This is a quotation")
107+ , "Multiline quote" =: T.unlines [ " This is a quotation"
108+ , " with a continuation"
109+ ]
110+ =?> blockQuote (para $ text "This is a quotation with a continuation")
106111 , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
107112 , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
108113 , testGroup "Comments"