Code block with empty lines within a list item

I would like to add this example to the spec.

.
- Foo

        bar

        baz
.
<ul>
<li><p>Foo</p>

<pre><code>bar

baz
</code></pre></li>
</ul>
.

I.e., this is a list item with a code block containing an empty line. The “bar” and “baz” lines begin with eight space characters.

The reason for this test case is that some Markdown implementations fail this case, and the set of examples in the spec doesn’t cover this case—as far as I know.

Here’s the result of running the example against John Gruber’s implementation.

Example --- (lines ?-?) List items
- Foo

        bar

        baz

--- expected HTML
+++ actual HTML
@@ -3,6 +3,7 @@
 
 <pre><code>bar
 
+
 baz
 </code></pre></li>
 </ul>

Notice the Gruber implementation adds an empty, second line between “bar” and “baz.” This corrupts complex code listings within list items.

That’s a Markdown.pl bug I’d never noticed before.

I’d be open to adding a case like this to the spec. Note, however, that the CommonMark rules would produce a slightly different output than you seem to be expecting, namely:

<ul>
<li>
<p>Foo</p>
<pre><code>  bar

  baz
</code></pre>
</li>
</ul>

Note the spaces at the beginning. That’s because CommonMark will expect indented code to start 4 spaces after the beginning of the content on the first line, which in your case is in column 3.

1 Like

John, thanks for the quick response and correction. My intention is not to have the extra spaces at the beginning of the line, but I’m no CommonMark expert—I found out about this project today after trying to figure out what to do about the Markdown.pl bug.

If I understand you correctly, then the code block in my example should be indented four spaces to the right of the ‘F’ column in “Foo,” like so:

.
- Foo

      bar

      baz
.
<ul>
<li><p>Foo</p>

<pre><code>bar

baz
</code></pre></li>
</ul>
.

Is this right? If so then what’s the next step for getting this example into the CommonMark spec? Should I file an issue on the GitHub page? Submit a merge request?

Sure, a PR would be welcome. You’ll just have to figure out what the best place would be to put this example.