aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs8
-rw-r--r--test/command/indented-fences.md20
2 files changed, 26 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 8fc92f7e8..8977517c1 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -623,8 +623,9 @@ indentedLine = indentSpaces >> anyLineNewline
blockDelimiter :: PandocMonad m
=> (Char -> Bool)
-> Maybe Int
- -> ParserT [Char] st m Int
+ -> ParserT [Char] ParserState m Int
blockDelimiter f len = try $ do
+ skipNonindentSpaces
c <- lookAhead (satisfy f)
case len of
Just l -> count l (char c) >> many (char c) >> return l
@@ -689,6 +690,8 @@ rawAttribute = do
codeBlockFenced :: PandocMonad m => MarkdownParser m (F Blocks)
codeBlockFenced = try $ do
+ indentchars <- nonindentSpaces
+ let indentLevel = length indentchars
c <- try (guardEnabled Ext_fenced_code_blocks >> lookAhead (char '~'))
<|> (guardEnabled Ext_backtick_code_blocks >> lookAhead (char '`'))
size <- blockDelimiter (== c) Nothing
@@ -701,7 +704,8 @@ codeBlockFenced = try $ do
<|> ((\x -> ("",[toLanguageId x],[])) <$> many1 nonspaceChar)))
blankline
contents <- intercalate "\n" <$>
- manyTill anyLine (blockDelimiter (== c) (Just size))
+ manyTill (gobbleAtMostSpaces indentLevel >> anyLine)
+ (blockDelimiter (== c) (Just size))
blanklines
return $ return $
case rawattr of
diff --git a/test/command/indented-fences.md b/test/command/indented-fences.md
new file mode 100644
index 000000000..eb3b78212
--- /dev/null
+++ b/test/command/indented-fences.md
@@ -0,0 +1,20 @@
+`````
+% pandoc -t native
+ ```haskell
+ let x = y
+in y
+ ```
+^D
+[CodeBlock ("",["haskell"],[]) "let x = y\nin y"]
+`````
+`````
+% pandoc -t native
+ ~~~ {.haskell}
+ let x = y
+ in y +
+y +
+ y
+~~~
+^D
+[CodeBlock ("",["haskell"],[]) " let x = y\nin y +\ny +\ny"]
+`````