we count the number of opening and closing parentheses in the link
if we have more closing parentheses than opening parentheses
AND if there are closing parentheses at the end of the link, we assume they should originally have been outside of the link and be part of the regular text
This seems to work well in practice: Almost all links with parentheses have them balanced (e.g. wikipedia links), and links surrounded by () now work correctly as well
Summary:
This seems to work well in practice: Almost all links with parentheses have them balanced (e.g. wikipedia links), and links surrounded by () now work correctly as well