Both indented and fenced code blocks generate a trailing newline. If that’s what’s desired, it should be easy to produce one. But it should also be easy to produce a code block without a trailing newline.
Thus:
This is a code block
should produce
<pre><code>This is a code block</code></pre>
If you want a trailing newline, insert one:
This is a code block with a trailing newline
to obtain
<pre><code>This is a code block
</code></pre>
jgm
March 3, 2015, 4:42am
2
Does it actually make a difference to HTML output whether there is a newline at the end of the code?
Of course it does. <pre> is whitespace (including linebreak) preserving. In any browsers,
<pre><code>This is a code block
</code></pre>
has more trailing whitespace at the bottom (the equivalent of an extra blank line) than
<pre><code>This is a code block</code></pre>
Try it yourself and see.
vitaly
March 3, 2015, 5:34am
4
I don’t see additional empty line (Firefox, Chromium).
<style>
pre { border: 1px solid; }
</style>
<pre><code>This is a code block
</code></pre>
123
<pre><code>This is a code block</code></pre>
Hmmm. Fascinating. A leading newline is preserved, but a trailing newline is stripped:
<style>
pre { border: 1px solid; }
</style>
<pre><code>
This is a code block
</code></pre>
(at least in the browsers I’ve tested). I guess I withdraw the comment, then …
vitaly
March 3, 2015, 7:40am
6
Yes, leading and tailing line breaks are completely different things.
Code blocks are ok IMHO.