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

**URL:** https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406
**Category:** Bug
**Tags:** markdown-it-review
**Created:** [19 Febbraio 2015, 3:46pm UTC](https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406 "2015-02-19T15:46:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Ajedi32](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ajedi32/32/107370_2.png) [@Ajedi32](https://meta.discourse.org/u/Ajedi32)
#### Post date: [19 Febbraio 2015, 3:46pm UTC](https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406/1 "2015-02-19T15:46:13Z")

</div>

The CommonMark spec [states](http://spec.commonmark.org/0.17/#example-257):

> Code spans, HTML tags, and autolinks have the same precedence. Thus, this is code:
> 
> Input:
> 
> ```plaintext
> `<a href="`">`
> 
> ```
> 
> Render:
> 
> ```plaintext
> <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.)

---

<div class="post-metadata">

### Author: ![Ajedi32](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ajedi32/32/107370_2.png) [@Ajedi32](https://meta.discourse.org/u/Ajedi32)
#### Post date: [19 Febbraio 2015, 3:48pm UTC](https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406/2 "2015-02-19T15:48:13Z")

</div>

```plaintext
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.
```

---

<div class="post-metadata">

### Author: ![Ajedi32](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ajedi32/32/107370_2.png) [@Ajedi32](https://meta.discourse.org/u/Ajedi32)
#### Post date: [19 Febbraio 2015, 3:49pm UTC](https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406/3 "2015-02-19T15:49:23Z")

</div>

```
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.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [19 Febbraio 2015, 3:50pm UTC](https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406/4 "2015-02-19T15:50:50Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Ajedi32](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ajedi32/32/107370_2.png) [@Ajedi32](https://meta.discourse.org/u/Ajedi32)
#### Post date: [19 Febbraio 2015, 4:44pm UTC](https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406/5 "2015-02-19T16:44:40Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [26 Giugno 2017, 7:33pm UTC](https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406/6 "2017-06-26T19:33:33Z")

</div>

This is now all fixed see:

> [@CommonMark testing started here!](https://meta.discourse.org/t/commonmark-testing-started-here/65121):
>
> Per our [migration plans](https://meta.discourse.org/t/discourse-commonmark-migration-plans-confetti-ball-balloon), I just enabled [markdown.it](https://github.com/markdown-it/markdown-it) at Meta. It is an excellent [CommonMark](http://commonmark.org/) compliant engine. I expect quite a few edges to be found during this period of testing. Do not open bugs about the new Engine, just reply here. I/we will be updating the top post here with the list of issues and striking out stuff as it is fixed. Current known issues (to be fixed)white_check_mark Onebox vanishes after you start typing and works not-super consistently white_check_mark pending…

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

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [26 Giugno 2017, 7:33pm UTC](https://meta.discourse.org/t/discourse-doesnt-follow-the-commonmark-spec-for-html-pre-tags-inside-code-spans/25406/7 "2017-06-26T19:33:38Z")

</div>


