[<https://domain1.example.com>](https://domain2.example.com)
The above renders to illegal HTML containing nested a elements:
<p><a href="https://domain2.example.com"><a href="https://domain1.example.com">https://domain1.example.com</a></a></p>
As far as I know, this is the only time CommonMark produces illegal HTML without there being raw HTML in the source document.
Autolinks should probably be banned from link text, just like ordinary links are. A preferable interpretation would be this:
<p>[<a href="https://domain1.example.com">https://domain1.example.com</a>](https://domain2.example.com)</p>
The proposed behavior always produces well-formed HTML and makes autolink syntax more consistent relative to other types of links.
1 Like
CommonMark has never been concerned with proper HTML syntax rules, as far as I know. It doesn’t matter if element X is valid inside element Y, or if element X is properly closed. CommonMark’s sole focus is Markdown syntax, and it only serves as a Markdown parser.
Some of the specifications there already make this pretty clear. For example, take a look at the rules for HTML blocks of types 1 and 6.
For further clarification, here are some examples of CommonMark syntax that will result in broken HTML (or at least, not giving the results you expected):
<h1>
asdf asdf asdf asdf
</h1>
asdf asdf asdf asdf
<script <script
asdf asdf asdf asdf
</script>
asdf asdf asdf asdf
asdf asdf asdf <!--
asdf asdf asdf asdf
--> asdf asdf asdf
asdf asdf asdf <span>
</span> asdf asdf asdf
Hello, thanks for your response. First of all, I would like to call attention to something you appear to have missed in my original post:
As far as I know, this is the only time CommonMark produces illegal HTML without there being raw HTML in the source document.
Both HTML blocks and inline HTML constitute “raw HTML” according to the spec, and all of your examples include one or the other.
Raw HTML in CommonMark abides a “garbage in, garbage out” rule. If you type junk HTML, you get junk HTML. (This is subject to the constraints imposed by the context in the Markdown document; e.g. paragraphs are p elements that should not contain block-level elements or imbalanced tags). But no other syntax in CommonMark generates illegal HTML except autolinks in this particular usage, which seems like unintended behavior if only due to its uniqueness.
That’s not the only reason, though. In fact, the spec itself directly contradicts this behavior. The specification goes out of its way to ban nesting of links:
Links may not contain other links, at any level of nesting. If multiple otherwise valid link definitions appear nested inside each other, the inner-most definition is used.
It is also made very clear that autolinks are links:
Autolinks are absolute URIs and email addresses inside < and >. They are parsed as links, with the URL or email address as the link label.
(Emphasis is mine).
The behavior described by the specification clearly differs from the behavior of the reference implementations here. That’s another reason why I don’t think this is intended behavior.
(Edit: small changes for clarity).
1 Like
… without there being raw HTML in the source document
Ah, okay. I think I read your post too quickly. Sorry about that.