Skip to content

Commit

Permalink
Add newlines after code block
Browse files Browse the repository at this point in the history
  • Loading branch information
nlisgo committed Jan 23, 2018
1 parent 3af14d8 commit 512d821
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Converter/CodeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '`';
Expand Down
1 change: 1 addition & 0 deletions tests/HtmlConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function test_code_samples()
{
$this->html_gives_markdown('<code>&lt;p&gt;Some sample HTML&lt;/p&gt;</code>', '`<p>Some sample HTML</p>`');
$this->html_gives_markdown("<code>\n&lt;p&gt;Some sample HTML&lt;/p&gt;\n&lt;p&gt;And another line&lt;/p&gt;\n</code>", "```\n\n<p>Some sample HTML</p>\n<p>And another line</p>\n\n```");
$this->html_gives_markdown("<code>\n&lt;p&gt;Some sample HTML&lt;/p&gt;\n&lt;p&gt;And another line&lt;/p&gt;\n</code><p>Paragraph after code.</p>", "```\n\n<p>Some sample HTML</p>\n<p>And another line</p>\n\n```\n\nParagraph after code.");
$this->html_gives_markdown("<p><code>\n#sidebar h1 {\n font-size: 1.5em;\n font-weight: bold;\n}\n</code></p>", "```\n\n#sidebar h1 {\n font-size: 1.5em;\n font-weight: bold;\n}\n\n```");
$this->html_gives_markdown("<p><code>#sidebar h1 {\n font-size: 1.5em;\n font-weight: bold;\n}\n</code></p>", "```\n#sidebar h1 {\n font-size: 1.5em;\n font-weight: bold;\n}\n\n```");
$this->html_gives_markdown('<pre><code>&lt;p&gt;Some sample HTML&lt;/p&gt;</code></pre>', '`<p>Some sample HTML</p>`');
Expand Down

0 comments on commit 512d821

Please sign in to comment.