git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Fixed parsing of indented blocks.

We were requiring consistent indentation, but this isn't required by RST, as long as each nonblank line of the block has *some* indentation. Closes #5753.

commit9abed458792564b610b2e999b01bae04ae0e23e0 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 22 Sep 2019, 12:00 (7 years ago) parent9b6ee81
2 files changed+24−6
src/Text/Pandoc/Readers/RST.hs+9−6 test/command/5753.md+15
src/Text/Pandoc/Readers/RST.hs+9−6
@@ -363,16 +363,19 @@ hrule = try $ do
363363--
364364
365365-- read a line indented by a given string
366−indentedLine :: Monad m => String -> ParserT [Char] st m [Char]
366+indentedLine :: (HasReaderOptions st, Monad m)
367+ => Int -> ParserT [Char] st m [Char]
367368indentedLine indents = try $ do
368− string indents
369+ lookAhead spaceChar
370+ gobbleAtMostSpaces indents
369371 anyLine
370372
371373-- one or more indented lines, possibly separated by blank lines.
372374-- any amount of indentation will work.
373−indentedBlock :: Monad m => ParserT [Char] st m [Char]
375+indentedBlock :: (HasReaderOptions st, Monad m)
376+ => ParserT [Char] st m [Char]
374377indentedBlock = try $ do
375− indents <- lookAhead $ many1 spaceChar
378+ indents <- length <$> lookAhead (many1 spaceChar)
376379 lns <- many1 $ try $ do b <- option "" blanklines
377380 l <- indentedLine indents
378381 return (b ++ l)
@@ -389,10 +392,10 @@ quotedBlock = try $ do
389392codeBlockStart :: Monad m => ParserT [Char] st m Char
390393codeBlockStart = string "::" >> blankline >> blankline
391394
392−codeBlock :: Monad m => ParserT [Char] st m Blocks
395+codeBlock :: (HasReaderOptions st, Monad m) => ParserT [Char] st m Blocks
393396codeBlock = try $ codeBlockStart >> codeBlockBody
394397
395−codeBlockBody :: Monad m => ParserT [Char] st m Blocks
398+codeBlockBody :: (HasReaderOptions st, Monad m) => ParserT [Char] st m Blocks
396399codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$>
397400 (indentedBlock <|> quotedBlock)
398401
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+```