Do these "links" render as expected?


#1

Apologies for not being able to frame this question more specifically. I just came across a post where someone had typed text like the following and was surprised at how it rendered. I tried a few variations, and they all seem strange to me. They render a bit differently here than they do on the dingus as well. Curious if the results in these examples are “expected” or not.

brackets, brackets, parens

[1][foo](https://meta.discourse.org)

[1]foo

brackets, whitespace, brackets, parens

[1]        [foo](https://meta.discourse.org)

1 foo

brackets, colon, brackets, parens

[1]:[foo](https://meta.discourse.org)

^ nothing

brackets, colon, whitespace, brackets, parens

[1]:        [foo](https://meta.discourse.org)

^ nothing


#2

This site doesn’t (yet) use CommonMark. So only what you see on the dingus is relevant. If you find what the dingus produces for these examples surprising, perhaps you could explain why. (And do look at the spec for links.)


#3

OK, I’ve reviewed the spec more closely, along with the dingus results.

The and second examples render as I would expect in CommonMark now, with the [1] treated as normal text and [foo](https://meta.discourse.org) as an inline link.

The last two examples do not show anything in the rendered text. And I can understand why from the spec, but it is not explicitly called out.

There is one example (538) that shows the same behavior:

[foo][bar][baz]

[baz]: /url
<p>[foo]<a href="/url">bar</a></p>

In this example, baz does not is a reference definition that does not match any references in the document.

I don’t see how that should be handled explicitly specified in the spec text, so perhaps that would be good to add?

Something like:

When a link reference definition does not match any link reference, it is still treated as a link reference definition, but because there is no matching link reference, it will not appear in the output.


#4

When a link reference definition does not match any link reference, it is still treated as a link reference definition, but because there is no matching link reference, it will not appear in the output.

I agree that it would be worth being explicit about this in the spec. Could you put up an issue on jgm/CommonMark so I won’t lose track?


Turning empty link definitions into anchors
#5

Sure thing. Issue opened here: