HTML reader: don't drop the initial newline in a pre element.

Closes #11064.
This commit is contained in:
John MacFarlane
2025-08-26 18:57:14 +02:00
parent 01f97ed55d
commit 6cff8dfc8a
2 changed files with 4 additions and 8 deletions
+2 -6
View File
@@ -659,14 +659,10 @@ pCodeBlock = try $ do
else v ]
contents <- manyTill pAny (pCloses "pre" <|> eof)
let rawText = T.concat $ map tagToText contents
-- drop leading newline if any
let result' = case T.uncons rawText of
Just ('\n', xs) -> xs
_ -> rawText
-- drop trailing newline if any
let result = case T.unsnoc result' of
let result = case T.unsnoc rawText of
Just (result'', '\n') -> result''
_ -> result'
_ -> rawText
return $ B.codeBlockWith attr result
tagToText :: Tag Text -> Text
+2 -2
View File
@@ -130,10 +130,10 @@ tests = [ testGroup "base tag"
[ test html "attributes in pre > code element" $
"<pre><code id=\"a\" class=\"python\">\nprint('hi')\n</code></pre>"
=?>
codeBlockWith ("a", ["python"], []) "print('hi')"
codeBlockWith ("a", ["python"], []) "\nprint('hi')"
, test html "attributes in pre take precedence" $
"<pre id=\"c\"><code id=\"d\">\nprint('hi mom!')\n</code></pre>"
"<pre id=\"c\"><code id=\"d\">print('hi mom!')\n</code></pre>"
=?>
codeBlockWith ("c", [], []) "print('hi mom!')"
]