diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index fcc1147ca..3c8c9d50b 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -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 diff --git a/test/Tests/Readers/HTML.hs b/test/Tests/Readers/HTML.hs index 5b7ab12fd..7c075de0b 100644 --- a/test/Tests/Readers/HTML.hs +++ b/test/Tests/Readers/HTML.hs @@ -130,10 +130,10 @@ tests = [ testGroup "base tag" [ test html "attributes in pre > code element" $ "
\nprint('hi')\n
" =?> - codeBlockWith ("a", ["python"], []) "print('hi')" + codeBlockWith ("a", ["python"], []) "\nprint('hi')" , test html "attributes in pre take precedence" $ - "
\nprint('hi mom!')\n
" + "
print('hi mom!')\n
" =?> codeBlockWith ("c", [], []) "print('hi mom!')" ]