diff --git a/src/Converter/PreformattedConverter.php b/src/Converter/PreformattedConverter.php index af6dd10..e067439 100644 --- a/src/Converter/PreformattedConverter.php +++ b/src/Converter/PreformattedConverter.php @@ -15,6 +15,10 @@ class PreformattedConverter implements ConverterInterface \assert($preContent !== null); $preContent = \str_replace('', '', $preContent); + // A newline right after the
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,
diff --git a/tests/HtmlConverterTest.php b/tests/HtmlConverterTest.php
index e62247e..673bff1 100644
--- a/tests/HtmlConverterTest.php
+++ b/tests/HtmlConverterTest.php
@@ -293,13 +293,15 @@ EOT;
$this->assertHtmlGivesMarkdown(' one line with spaces
', "```\n one line with spaces \n```");
$this->assertHtmlGivesMarkdown('', "```\n```");
$this->assertHtmlGivesMarkdown('', "```\n```\n\n```\n```");
- $this->assertHtmlGivesMarkdown("\n
", "```\n\n```");
+ $this->assertHtmlGivesMarkdown("\n
", "```\n```");
$this->assertHtmlGivesMarkdown("foo\n
", "```\nfoo\n```");
- $this->assertHtmlGivesMarkdown("\nfoo
", "```\n\nfoo\n```");
- $this->assertHtmlGivesMarkdown("\nfoo\n
", "```\n\nfoo\n```");
- $this->assertHtmlGivesMarkdown("\n\n
", "```\n\n\n```");
- $this->assertHtmlGivesMarkdown("\n\n\n
", "```\n\n\n\n```");
- $this->assertHtmlGivesMarkdown("\n
\n
", "```\n\n```\n\n```\n\n```");
+ $this->assertHtmlGivesMarkdown("\nfoo
", "```\nfoo\n```");
+ $this->assertHtmlGivesMarkdown("\nfoo\n
", "```\nfoo\n```");
+ $this->assertHtmlGivesMarkdown("\r\nfoo
", "```\nfoo\n```");
+ $this->assertHtmlGivesMarkdown("\n\nfoo
", "```\n\nfoo\n```");
+ $this->assertHtmlGivesMarkdown("\n\n
", "```\n\n```");
+ $this->assertHtmlGivesMarkdown("\n\n\n
", "```\n\n\n```");
+ $this->assertHtmlGivesMarkdown("\n
\n
", "```\n```\n\n```\n```");
$this->assertHtmlGivesMarkdown("one\ntwo\r\nthree
\nline
", "```\none\ntwo\nthree\n```\n\nline");
$this->assertHtmlGivesMarkdown("test with attributes
", "```\ntest with attributes\n```");
}