git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: debug indented paragraph support (#3839)
1b5bfceAlexander
src/Text/Pandoc/Readers/Muse.hs+5−21
@@ -186,7 +186,6 @@ blockElements = choice [ comment
186 , orderedList
186 , orderedList
187 , table
187 , table
188 , commentTag
188 , commentTag
189− , indentedBlock
190 , noteBlock
189 , noteBlock
191 ]
190 ]
192
191
@@ -249,27 +248,12 @@ quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
249commentTag :: PandocMonad m => MuseParser m (F Blocks)
248commentTag :: PandocMonad m => MuseParser m (F Blocks)
250commentTag = parseHtmlContent "comment" anyChar >> return mempty
249commentTag = parseHtmlContent "comment" anyChar >> return mempty
251
250
252−-- Indented block is either center, right or quote
251+-- Indented paragraph 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−
271para :: PandocMonad m => MuseParser m (F Blocks)
252para :: PandocMonad m => MuseParser m (F Blocks)
253+para = do
254+ indent <- length <$> many spaceChar
255+ let f = if indent >= 2 && indent < 6 then B.blockQuote else id
272−para = liftM B.para . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
256+ liftM (f . B.para) . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
273 where
257 where
274 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
258 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
275 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
259 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
test/Tests/Readers/Muse.hs+29−6
@@ -32,7 +32,7 @@ tests =
32 [ testGroup "Inlines"
32 [ testGroup "Inlines"
33 [ "Plain String" =:
33 [ "Plain String" =:
34 "Hello, World" =?>
34 "Hello, World" =?>
35− para (spcSep [ "Hello,", "World" ])
35+ para "Hello, World"
36
36
37 , "Emphasis" =: "*Foo bar*" =?> para (emph . spcSep $ ["Foo", "bar"])
37 , "Emphasis" =: "*Foo bar*" =?> para (emph . spcSep $ ["Foo", "bar"])
38
38
@@ -102,12 +102,35 @@ tests =
102 , "5 dashes is a horizontal rule" =: "-----" =?> horizontalRule
102 , "5 dashes is a horizontal rule" =: "-----" =?> horizontalRule
103 , "4 dashes with spaces is a horizontal rule" =: "---- " =?> horizontalRule
103 , "4 dashes with spaces is a horizontal rule" =: "---- " =?> horizontalRule
104 ]
104 ]
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+ ]
105 , "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
133 , "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")
111 , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
134 , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
112 , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
135 , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
113 , testGroup "Comments"
136 , testGroup "Comments"