diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 9f63a1947..c09c110aa 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1094,18 +1094,20 @@ rawHtmlBlocks = do
-- inline will not be parsed as inline tags
oldInHtmlBlock <- stateInHtmlBlock <$> getState
updateState $ \st -> st{ stateInHtmlBlock = Just tagtype }
- let closer = htmlTag (\x -> x ~== TagClose tagtype)
- let block' = try $
- do notFollowedBy' closer
- gobbleAtMostSpaces indentlevel
- block
+ let closer = htmlTag (~== TagClose tagtype)
+ let block' = try $ do
+ gobbleAtMostSpaces indentlevel
+ notFollowedBy' closer
+ block
contents <- mconcat <$> many block'
result <-
- (closer >>= \(_, rawcloser) -> return (
- return (B.rawBlock "html" $ stripMarkdownAttribute raw) <>
+ try
+ (do gobbleAtMostSpaces indentlevel
+ (_, rawcloser) <- closer
+ return (return (B.rawBlock "html" $ stripMarkdownAttribute raw) <>
contents <>
return (B.rawBlock "html" rawcloser)))
- <|> return (return (B.rawBlock "html" raw) <> contents)
+ <|> (return (return (B.rawBlock "html" raw) <> contents))
updateState $ \st -> st{ stateInHtmlBlock = oldInHtmlBlock }
return result
diff --git a/test/command/5360.md b/test/command/5360.md
new file mode 100644
index 000000000..924c1ea28
--- /dev/null
+++ b/test/command/5360.md
@@ -0,0 +1,19 @@
+```
+% pandoc -t native
+::: {.foo}
+
+:::
+^D
+[Div ("",["foo"],[])
+ [RawBlock (Format "html") ""
+ ,RawBlock (Format "html") ""
+ ,RawBlock (Format "html") ""
+ ,Plain [Str "hi"]
+ ,RawBlock (Format "html") " | "
+ ,RawBlock (Format "html") "
"
+ ,RawBlock (Format "html") "
"]]
+```
diff --git a/test/command/6009.md b/test/command/6009.md
new file mode 100644
index 000000000..ed6b46cbb
--- /dev/null
+++ b/test/command/6009.md
@@ -0,0 +1,18 @@
+```
+% pandoc -t native
+
+
+ |
+
+
+x
+
+ y
+^D
+[RawBlock (Format "html") ""
+,RawBlock (Format "html") ""
+,RawBlock (Format "html") " | "
+,RawBlock (Format "html") "
"
+,Para [Str "x"]
+,CodeBlock ("",[],[]) "y"]
+```