Is a new line required before a closing code fence?

Does the following produce <pre><code>a</code></pre> ?

```
a```

If yes, IMHO there should be an explicit example in the fenced code blocks section.

Not according to the dingus, here it results in the following HTML:

<pre><code>a```
</code></pre>

It is closed because the end of the document is reached.

Code fences might confuse people because the spec defines it as a “sequence” of symbols rather than a line of symbols. Should the spec be more implicit here? A good example would be how a horizontal rule is also defined as “a line”:

A line consisting of 0-3 spaces of indentation, followed by a sequence of three or more matching -, _, or * characters, each followed optionally any number of spaces, forms a horizontal rule.

Agreed, it should be more explicit. It seems sort of implied (because open and closing fence “may be indented”, which only makes sense for stuff at the beginning of a line), but it should definitly be clearer.

Do you want to open a pull request?

I would if I could come-up with a good flowing text for this, but I get stuck on the details every time I try to incorporate the “info string” section. Rather leave it up to someone more capable.

Maybe the change can focus only on the closing code fence, since the opening code fence is indeed clarified by the indentation part.

BTW the spec should state the maximum indentation (or that there is no maximum) for the closing fence.

E.g.

The content of the code block consists of all subsequent lines, until a closing code fence of the same type as the code block began with (backticks or tildes), and with at least as many backticks or tildes as the opening code fence, and also not indented more than three spaces.

+ examples of valid and invalid (no new line, too much indentation) closing code fence.

1 Like

One more suggested rephrasing, just to make it explicit that the closing code fence must also be its own line:

The content of the code block consists of all subsequent lines, until a line consisting of a closing code fence of the same type as the code block began with (backticks or tildes), with at least as many backticks or tildes as the opening code fence, and also not indented more than three spaces.

The first sentence of the very next paragraph does mention indentation for closing code fences, though:

The closing code fence may be indented up to three spaces, and may be followed only by spaces, which are ignored.

so maybe it would be ok to leave off “and also not indented more than three spaces” from the earlier paragraph.