git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Fixed parsing of indented blocks.
9abed45John MacFarlane
src/Text/Pandoc/Readers/RST.hs+9−6
@@ -363,16 +363,19 @@ hrule = try $ do
363--
363--
364
364
365-- read a line indented by a given string
365-- read a line indented by a given string
366+indentedLine :: (HasReaderOptions st, Monad m)
366−indentedLine :: Monad m => String -> ParserT [Char] st m [Char]
367+ => Int -> ParserT [Char] st m [Char]
367indentedLine indents = try $ do
368indentedLine indents = try $ do
368− string indents
369+ lookAhead spaceChar
370+ gobbleAtMostSpaces indents
369 anyLine
371 anyLine
370
372
371-- one or more indented lines, possibly separated by blank lines.
373-- one or more indented lines, possibly separated by blank lines.
372-- any amount of indentation will work.
374-- any amount of indentation will work.
375+indentedBlock :: (HasReaderOptions st, Monad m)
373−indentedBlock :: Monad m => ParserT [Char] st m [Char]
376+ => ParserT [Char] st m [Char]
374indentedBlock = try $ do
377indentedBlock = try $ do
375− indents <- lookAhead $ many1 spaceChar
378+ indents <- length <$> lookAhead (many1 spaceChar)
376 lns <- many1 $ try $ do b <- option "" blanklines
379 lns <- many1 $ try $ do b <- option "" blanklines
377 l <- indentedLine indents
380 l <- indentedLine indents
378 return (b ++ l)
381 return (b ++ l)
@@ -389,10 +392,10 @@ quotedBlock = try $ do
389codeBlockStart :: Monad m => ParserT [Char] st m Char
392codeBlockStart :: Monad m => ParserT [Char] st m Char
390codeBlockStart = string "::" >> blankline >> blankline
393codeBlockStart = string "::" >> blankline >> blankline
391
394
392−codeBlock :: Monad m => ParserT [Char] st m Blocks
395+codeBlock :: (HasReaderOptions st, Monad m) => ParserT [Char] st m Blocks
393codeBlock = try $ codeBlockStart >> codeBlockBody
396codeBlock = try $ codeBlockStart >> codeBlockBody
394
397
395−codeBlockBody :: Monad m => ParserT [Char] st m Blocks
398+codeBlockBody :: (HasReaderOptions st, Monad m) => ParserT [Char] st m Blocks
396codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$>
399codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$>
397 (indentedBlock <|> quotedBlock)
400 (indentedBlock <|> quotedBlock)
398
401
test/command/5753.mdnew file+15
@@ -0,0 +1,15 @@
1+```
2+% pandoc -f rst -t native
3+.. math::
4+
5+ q_3
6+ + 4
7+ - 5
8+
9+ q_5
10+
11+end
12+^D
13+[Para [Math DisplayMath "q_3\n+ 4\n- 5",Math DisplayMath "q_5"]
14+,Para [Str "end"]]
15+```