aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-09-22 12:00:55 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-09-22 12:01:45 -0700
commit9abed458792564b610b2e999b01bae04ae0e23e0 (patch)
treec269180ed34cc133857f6110fa6a91d4260a013e /src/Text/Pandoc/Readers
parent9b6ee81c1916bb23d2cb24534adb88d65b4642df (diff)
downloadpandoc-9abed458792564b610b2e999b01bae04ae0e23e0.tar.gz
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.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 8875fdebe..fd20351b4 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -363,16 +363,19 @@ hrule = try $ do
--
-- read a line indented by a given string
-indentedLine :: Monad m => String -> ParserT [Char] st m [Char]
+indentedLine :: (HasReaderOptions st, Monad m)
+ => Int -> ParserT [Char] st m [Char]
indentedLine indents = try $ do
- string indents
+ lookAhead spaceChar
+ gobbleAtMostSpaces indents
anyLine
-- one or more indented lines, possibly separated by blank lines.
-- any amount of indentation will work.
-indentedBlock :: Monad m => ParserT [Char] st m [Char]
+indentedBlock :: (HasReaderOptions st, Monad m)
+ => ParserT [Char] st m [Char]
indentedBlock = try $ do
- indents <- lookAhead $ many1 spaceChar
+ indents <- length <$> lookAhead (many1 spaceChar)
lns <- many1 $ try $ do b <- option "" blanklines
l <- indentedLine indents
return (b ++ l)
@@ -389,10 +392,10 @@ quotedBlock = try $ do
codeBlockStart :: Monad m => ParserT [Char] st m Char
codeBlockStart = string "::" >> blankline >> blankline
-codeBlock :: Monad m => ParserT [Char] st m Blocks
+codeBlock :: (HasReaderOptions st, Monad m) => ParserT [Char] st m Blocks
codeBlock = try $ codeBlockStart >> codeBlockBody
-codeBlockBody :: Monad m => ParserT [Char] st m Blocks
+codeBlockBody :: (HasReaderOptions st, Monad m) => ParserT [Char] st m Blocks
codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$>
(indentedBlock <|> quotedBlock)