Shall CommonMark inline inside HTML5 render as CommonMark? If not, why not?

At github.com/MALSync/MALSync/issues/2092:

…via the available “GitHub-Flavoured Markdown” markup syntax, I am able to utilise CommonMark inside a <code> tag, directly inline:

1.	<code>[por](https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1=pt)[-](https://stackoverflow.com/questions/13630355/culture-name-using-underscore-instead-of-dash#comment18695296_13630355)[BRA](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#:~:text=Plurinational%20State%20of%29-,bra,-Brazil)</code>;

	<!-- 
	
	[^1]: [`stackoverflow.com/revisions/40076454/2`][1]

	[1]: https://stackoverflow.com/revisions/40076454/2#:~:text=Sometimes%20you%20need%20to%20encode,%5BSyntax%5D(http://en.wikipedia.org/wiki/Syntax_(programming_languages%2529)

	 -->

1.	<code>[por](https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?code_ID=363)[-](https://stackoverflow.com/questions/13630355/culture-name-using-underscore-instead-of-dash#comment18695296_13630355)[EEE](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#:~:text=ABB%20Asia-,eee,-Europe)</code>;

1.	[`ro`](https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1=ro);

1.	[`sv`](https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1=sv);

1.	<code>[zho](https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?code_ID=)[-](https://stackoverflow.com/questions/13630355/culture-name-using-underscore-instead-of-dash#comment18695296_13630355)[HANS](https://stackoverflow.com/a/4894634/9731176)</code>; and

1.	<code>[zho](https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?code_ID=)[-](https://stackoverflow.com/questions/13630355/culture-name-using-underscore-instead-of-dash#comment18695296_13630355)[HANT](https://stackoverflow.com/a/4894634/9731176)</code>.

I was under the impression that CommonMark requires a newline between the start and end tags of any HTML5 for the CommonMark within to render, which I still believe to be correct. Please correct me if I’m not. However, with that premise, if this is technically feasible, why is it disallowed by the standard?

This is an exceptionally late reply from me, but I happened to see this while reading another post and it’s a question that comes up a lot.

The short answer is, it depends: see § 6.6 Raw HTML for how raw HTML is interpreted inline; note especially the definition of an HTML tag:

An HTML tag consists of an open tag, a closing tag, an HTML comment, a processing instruction, a declaration, or a CDATA section.

In other words, when it comes to inline HTML, there’s no such thing as “inside” a <code> tag: the <code> is itself considered an HTML tag, then there’s some Markdown which is parsed as usual, and then </code> is also considered one. So in this sense, Markdown “within” what we read as a <code></code> pair is totally fine, because parsers just treat each in isolation as inline HTML.

You can see this in action by looking at the AST for e.g. the following input:

1. <code>Hello</code> world.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document xmlns="http://commonmark.org/xml/1.0">
  <list type="ordered" start="1" tight="true" delimiter="period">
    <item>
      <paragraph>
        <html_inline>&lt;code&gt;</html_inline>
        <text>Hello</text>
        <html_inline>&lt;/code&gt;</html_inline>
        <text> world.</text>
      </paragraph>
    </item>
  </list>
</document>

Note each tag is simply html_inline.

Things get more complicated when we consider block HTML, per § 4.6 HTML blocks. The 7 start conditions outline in which cases a compliant parser will suspend treating input as Markdown, and when they’ll resume.

Of particular relevance is start condition 6, as it outlines the majority of tags considered to be “block”: a line that starts with e.g. <table> will suspend parsing until it reaches a blank line. Thus:

<table>
<tr><td>**This won't be emphasised.**</td></tr>
</table>

**This will**

<table><tr><td>

**This will be in a table, *and* will be emphasised.**

</td></tr></table>

Note that <code> is not part of any start condition, so it is interpreted per inline rules even if it happens to come at the start of a line.

1 Like