mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 03:06:30 +00:00
HTML reader: don't drop the initial newline in a pre element.
Closes #11064.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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!')"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user