fix: strip the newline right after the <pre> start tag

Fixes #244
This commit is contained in:
dualfroz committed 2026-10-02 16:19:40 +02:00
1 parent 710bc5b8ca
commit 806387f3f6
2 files changed
+12 -6

No files matched your search

+4
View File
@@ -15,6 +15,10 @@ class PreformattedConverter implements ConverterInterface
\assert($preContent !== null);
$preContent = \str_replace('</pre>', '', $preContent);
// A newline right after the <pre> start tag is not part of the content (HTML spec), but the parser keeps it
$preContent = \preg_replace('/^(?:\r\n|\r|\n)/', '', $preContent);
\assert($preContent !== null);
/*
* Checking for the code tag.
* Usually pre tags are used along with code tags. This conditional will check for already converted code tags,
+8 -6
View File
@@ -293,13 +293,15 @@ EOT;
$this->assertHtmlGivesMarkdown('<pre> one line with spaces </pre>', "```\n one line with spaces \n```");
$this->assertHtmlGivesMarkdown('<pre></pre>', "```\n```");
$this->assertHtmlGivesMarkdown('<pre></pre><pre></pre>', "```\n```\n\n```\n```");
$this->assertHtmlGivesMarkdown("<pre>\n</pre>", "```\n\n```");
$this->assertHtmlGivesMarkdown("<pre>\n</pre>", "```\n```");
$this->assertHtmlGivesMarkdown("<pre>foo\n</pre>", "```\nfoo\n```");
$this->assertHtmlGivesMarkdown("<pre>\nfoo</pre>", "```\n\nfoo\n```");
$this->assertHtmlGivesMarkdown("<pre>\nfoo\n</pre>", "```\n\nfoo\n```");
$this->assertHtmlGivesMarkdown("<pre>\n\n</pre>", "```\n\n\n```");
$this->assertHtmlGivesMarkdown("<pre>\n\n\n</pre>", "```\n\n\n\n```");
$this->assertHtmlGivesMarkdown("<pre>\n</pre><pre>\n</pre>", "```\n\n```\n\n```\n\n```");
$this->assertHtmlGivesMarkdown("<pre>\nfoo</pre>", "```\nfoo\n```");
$this->assertHtmlGivesMarkdown("<pre>\nfoo\n</pre>", "```\nfoo\n```");
$this->assertHtmlGivesMarkdown("<pre>\r\nfoo</pre>", "```\nfoo\n```");
$this->assertHtmlGivesMarkdown("<pre>\n\nfoo</pre>", "```\n\nfoo\n```");
$this->assertHtmlGivesMarkdown("<pre>\n\n</pre>", "```\n\n```");
$this->assertHtmlGivesMarkdown("<pre>\n\n\n</pre>", "```\n\n\n```");
$this->assertHtmlGivesMarkdown("<pre>\n</pre><pre>\n</pre>", "```\n```\n\n```\n```");
$this->assertHtmlGivesMarkdown("<pre>one\ntwo\r\nthree</pre>\n<p>line</p>", "```\none\ntwo\nthree\n```\n\nline");
$this->assertHtmlGivesMarkdown("<pre class='some-class'>test with attributes</pre>", "```\ntest with attributes\n```");
}