diff --git a/src/Converter/CodeConverter.php b/src/Converter/CodeConverter.php index c8ec2c0..e536362 100644 --- a/src/Converter/CodeConverter.php +++ b/src/Converter/CodeConverter.php @@ -43,7 +43,7 @@ public function convert(ElementInterface $element) $lines = preg_split('/\r\n|\r|\n/', $code); if (count($lines) > 1) { // Multiple lines detected, adding three backticks and newlines - $markdown .= '```' . $language . "\n" . $code . "\n" . '```'; + $markdown .= '```' . $language . "\n" . $code . "\n" . '```' . "\n\n"; } else { // One line of code, wrapping it on one backtick. $markdown .= '`' . $language . $code . '`'; diff --git a/tests/HtmlConverterTest.php b/tests/HtmlConverterTest.php index 24a793b..517bb48 100644 --- a/tests/HtmlConverterTest.php +++ b/tests/HtmlConverterTest.php @@ -158,6 +158,7 @@ public function test_code_samples() { $this->html_gives_markdown('<p>Some sample HTML</p>', '`

Some sample HTML

`'); $this->html_gives_markdown("\n<p>Some sample HTML</p>\n<p>And another line</p>\n", "```\n\n

Some sample HTML

\n

And another line

\n\n```"); + $this->html_gives_markdown("\n<p>Some sample HTML</p>\n<p>And another line</p>\n

Paragraph after code.

", "```\n\n

Some sample HTML

\n

And another line

\n\n```\n\nParagraph after code."); $this->html_gives_markdown("

\n#sidebar h1 {\n font-size: 1.5em;\n font-weight: bold;\n}\n

", "```\n\n#sidebar h1 {\n font-size: 1.5em;\n font-weight: bold;\n}\n\n```"); $this->html_gives_markdown("

#sidebar h1 {\n font-size: 1.5em;\n font-weight: bold;\n}\n

", "```\n#sidebar h1 {\n font-size: 1.5em;\n font-weight: bold;\n}\n\n```"); $this->html_gives_markdown('
<p>Some sample HTML</p>
', '`

Some sample HTML

`');