I re-read the spec about links and code spans, and I think it is unclear about a precedence, and it does not include code samples on this topic.
It explains that code spans have higher priority than links.
However, as I can see in commonmark.js dingus, it is true only for link text.
For inline links, link target and link title have higher priority than code spans:
[link](`fo)o`
In this example, this is a link + “o`” text, not code span. This is not mentioned in the spec (if I am wrong, please correct me).
And for reference link, intersection with code spans is not processed correctly, as it is shown in my previous message.
No, I don’t think it’s a bug. Have a look at the definition of “link label”:
A link label begins with a left bracket ([) and ends with the first right bracket (]) that is not backslash-escaped. Between these brackets there must be at least one non-whitespace character. Unescaped square bracket characters are not allowed inside the opening and closing square brackets of link labels. A link label can have at most 999 characters inside the square brackets.
Here we have bracketed ref followed by a link label [sometext `code].
Since that label does not have a definition, this is not a link.
You might think, shouldn’t it be a shortcut reference link to ddd followed by plain text [sometext and then code code]? This is ruled out by the spec:
I think this is the reason why the parser does it in this way.
However, I believe that this behavior is inconsistent, because unresolved labels are never treated as labels.
You said originally that you thought it was a bug. Since this behavior is required by the spec, it is not a bug. Instead, you just don’t like this aspect of the spec.
Initially, I did not say that it is a bug, I asked “may it be a bug?” )
I think the both ways are ok.
I just wish the specification to be more clear on this topic, explicitly saying that a shortcut link is not created when a list text is followed by an unresolved link label. I think it is not obvious.
I just wish the specification to be more clear on this topic, explicitly saying that a shortcut link is not created when a list text is followed by an unresolved link label. I think it is not obvious.
Agreed, this would be a good candidate for an addition clarifying example. Could you put up on issue on the GitHub tracker so we don’t forget? (commonmark/commonmark-spec).
( foo is not a link here because bar is not defined)
So no additional examples are needed, sorry.
But probably, examples that show preferences of link destination, link title, and link label (in full reference links) over code spans, autolinks and html tags would be useful…