git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: debug indented paragraph support (#3839)

Take only first line indentation into account and do not start new paragraph on indentation change.

commit1b5bfced558d28d45caadc6171f9e7448f3deae1 authorAlexander <ilabdsf@gmail.com> dateMon 7 Aug 2017, 07:43 (9 years ago) parenta67a96b
2 files changed+34−27
src/Text/Pandoc/Readers/Muse.hs+5−21 test/Tests/Readers/Muse.hs+29−6
src/Text/Pandoc/Readers/Muse.hs+5−21
@@ -186,7 +186,6 @@ blockElements = choice [ comment
186186 , orderedList
187187 , table
188188 , commentTag
189− , indentedBlock
190189 , noteBlock
191190 ]
192191
@@ -249,27 +248,12 @@ quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
249248commentTag :: PandocMonad m => MuseParser m (F Blocks)
250249commentTag = parseHtmlContent "comment" anyChar >> return mempty
251250
252−-- Indented block is either center, right or quote
253−indentedLine :: PandocMonad m => MuseParser m (Int, String)
254−indentedLine = try $ do
255− indent <- length <$> many1 spaceChar
256− line <- anyLine
257− return (indent, line)
258−
259−rawIndentedBlock :: PandocMonad m => MuseParser m (Int, String)
260−rawIndentedBlock = try $ do
261− lns <- many1 indentedLine
262− let indent = minimum $ map fst lns
263− return (indent, unlines $ map snd lns)
264−
265−indentedBlock :: PandocMonad m => MuseParser m (F Blocks)
266−indentedBlock = try $ do
267− (indent, raw) <- rawIndentedBlock
268− contents <- withQuoteContext InDoubleQuote $ parseFromString parseBlocks raw
269− return $ (if indent >= 2 && indent < 6 then B.blockQuote else id) <$> contents
270−
251+-- Indented paragraph is either center, right or quote
271252para :: PandocMonad m => MuseParser m (F Blocks)
272−para = liftM B.para . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
253+para = do
254+ indent <- length <$> many spaceChar
255+ let f = if indent >= 2 && indent < 6 then B.blockQuote else id
256+ liftM (f . B.para) . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
273257 where
274258 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
275259 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
test/Tests/Readers/Muse.hs+29−6
@@ -32,7 +32,7 @@ tests =
3232 [ testGroup "Inlines"
3333 [ "Plain String" =:
3434 "Hello, World" =?>
35− para (spcSep [ "Hello,", "World" ])
35+ para "Hello, World"
3636
3737 , "Emphasis" =: "*Foo bar*" =?> para (emph . spcSep $ ["Foo", "bar"])
3838
@@ -102,12 +102,35 @@ tests =
102102 , "5 dashes is a horizontal rule" =: "-----" =?> horizontalRule
103103 , "4 dashes with spaces is a horizontal rule" =: "---- " =?> horizontalRule
104104 ]
105+ , testGroup "Paragraphs"
106+ [ "Simple paragraph" =:
107+ T.unlines [ "First line"
108+ , "second line."
109+ ] =?>
110+ para "First line second line."
111+ , "Indented paragraph" =:
112+ T.unlines [ " First line"
113+ , "second line."
114+ ] =?>
115+ para "First line second line."
116+ -- Emacs Muse starts a blockquote on the second line.
117+ -- We copy Amusewiki behavior and require a blank line to start a blockquote.
118+ , "Indentation in the middle of paragraph" =:
119+ T.unlines [ "First line"
120+ , " second line"
121+ , "third line"
122+ ] =?>
123+ para "First line second line third line"
124+ , "Quote" =:
125+ " This is a quotation\n" =?>
126+ blockQuote (para "This is a quotation")
127+ , "Multiline quote" =:
128+ T.unlines [ " This is a quotation"
129+ , " with a continuation"
130+ ] =?>
131+ blockQuote (para "This is a quotation with a continuation")
132+ ]
105133 , "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")
111134 , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
112135 , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
113136 , testGroup "Comments"