Marked: Marked does not handle links with parentheses

Created on 23 Nov 2015  路  14Comments  路  Source: markedjs/marked

This is a carbon copy of this bug for _VSCode_.

Here is an example where the preview engine in VSCode mis-renders links with parentheses:
image3

Looks like a Marked issue - any way to fix it?

L1 - broken links

Most helpful comment

For reference, the CommonMark spec says that one level of balanced parentheses are allowed in link URLs without being escaped. If there are nested parentheses, or if they're unbalanced, they need to be escaped.

I think this is doable with a regex, but I wouldn't want to be the one writing such a regex.

All 14 comments

There's no way to get around this issue. Just replace closing parentheses with '%29'

Why not? Out of curiosity, the StackOverflow inline editor, for example, fully supports this scenario.

Because that would require regexes that count matching opening and closing brackets. And even that is not correct, because URLs are not guaranteed to have balanced brackets in the first place.

Surely the balanced parentheses case is more common and would cover 99% of the cases here?

Please consider that this behaviour would also break every existing link with escaped closing parens (and unescaped opening ones).
IMO the best solution is to use references like suggested in the linked issue.

@dend I got the same problem

An option that accepts balanced parentheses matching would be nice.
I don't care if it's off/false by default.

For reference, the CommonMark spec says that one level of balanced parentheses are allowed in link URLs without being escaped. If there are nested parentheses, or if they're unbalanced, they need to be escaped.

I think this is doable with a regex, but I wouldn't want to be the one writing such a regex.

984

Downstream, Jupyter notebooks and Jupyter lab are facing the same issue, e.g. with links to weird DOIs such as DOI:10.1016/S0010-4655(00)00228-9 :

[Esirkepov](https://dx.doi.org/10.1016/S0010-4655(00)00228-9)

GitHub renders it correctly:

Esirkepov

@ax3l: I鈥檓 not sure the example of GitHub doing it properly is actually doing so, I can see the number from the URL after the link text.

Having said that, if it were rendering it probably, I would be curious to know if it鈥檚 the GitHub markdown processor doing it, or a post-process of some kind.

We see the issue with Wikipedia URLs as well. Alternatively, one could also hardcode the HTML link, if the output destination is known.

I鈥檓 not sure the example of GitHub doing it properly is actually doing so, I can see the number from the URL after the link text.

@joshbruce The GitHub you see is rendered improperly? This is what I see:

github_md

I guess it's a tricky regex that balances the brackets.


Interestingly, the downstream Jupyter .md syntax highlighting get's it right (see red parts on the left), only the preview (right, markedjs) has the glitch:

lab_md

@ax3l: It's what I see now, but wasn't what I was seeing. First time I saw:

Esirkepov00228-9)

So, we'll see what we can do. We're focusing on hitting the CommonMark and GFM specs right now; so, not sure when this will become a priority, if it does. Just to keep you aware of where we are.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

toc
zoe-cjf picture zoe-cjf  路  3Comments

elennaro picture elennaro  路  4Comments

thyxsl picture thyxsl  路  4Comments

mjbvz picture mjbvz  路  4Comments

chunhei2008 picture chunhei2008  路  3Comments