Discourse doesn't follow the CommonMark spec for HTML <pre> tags inside code spans

AI-generated summary

Ajedi32 reports a bug where Discourse fails to correctly render HTML <pre> tags inside code spans when followed by preformatted text, contrary to the CommonMark spec example 257. Examples show that code spans containing <pre> break rendering if subsequent content includes <pre> blocks Ajedi32, though the issue doesn’t occur if preformatted text appears before the code span or is absent entirely Ajedi32. eviltrout notes Discourse isn’t yet fully CommonMark-compliant but acknowledges it may still be a non-CM-specific bug. Ajedi32 clarifies that even without CommonMark, the behavior is suboptimal. sam confirms the issue is now resolved as part of ongoing CommonMark testing and notes that code block hoisting has been disabled, preventing this behavior entirely. See CommonMark Testing Started Here for details.

The CommonMark spec states:

Code spans, HTML tags, and autolinks have the same precedence. Thus, this is code:

Input:

`<a href="`">`

Render:

<p><code>&lt;a href=&quot;</code>&quot;&gt;`</p>

The problem is that this doesn’t work for <pre> tags when any part of the input markdown following the code span contains preformatted text. (Example shown in my reply to this post.)

1 « J'aime »
This is the `<pre>` tag.

Results in:

This is the <pre> tag.

When any following part of the document contains preformatted text:

This is   pre-formatted text.
This is     pre-formatted text.

This issue does not occur when the document contains pre-formatted text before the code span containing <pre>, or when the document does not contain pre-formatted text at all.

Discourse isn’t on CommonMark yet. It does pass MDTest 1.2 though.

edit: This might still be a bug though that isn’t CM specific, will look into it!

Right. The only reason I mentioned CommonMark is that it’s the only standard I can point to which explains the correct behavior.

Really though the current behavior of Discourse in this area is less than optimal regardless of whether you’re following CommonMark.

This is now all fixed see:

Can not repro any of the issues, also we stopped hoisting code blocks so this can not happen anymore.

4 « J'aime »