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.
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:
@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:

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:

This seems to be the regex used in pygments, maybe it helps:
https://bitbucket.org/birkenfeld/pygments-main/src/7941677dc77d4f2bf0bbd6140ade85a9454b8b80/pygments/lexers/markup.py?at=default&fileviewer=file-view-default#markup.py-585
@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.
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.