Some wikis do overwrite certain Cite messages in a way that HTML tags get rearranged, and additional ones added. This confuses the jQuery selectors we currently use in the JavaScript code.
Expected:
<sup>[[#$1|$2]]</sup>
Currently on https://en.wikipedia.org/w/index.php?title=MediaWiki:Cite_references_link_many_format&action=edit:
[[#$1|<sup>'''''$3'''''</sup>]]
The selector .mw-cite-backlink * a[href="#…"] assumes the <sup> comes before the <a>. This is critical, because the selector would otherwise include the <a …>↑</a>, and we don't want this to happen. It seems we need an other way to differentiate between the <sup><a …>… and (unexpected) <a …><sup>… we want, and the <a …>↑</a> we don't want.
- One idea we had was to somehow count the number of <a>, and bail out if there is only one. But counting is hard if the <span class="mw-cite-backlink"> got removed.
- Another idea is to check if there are at least two links, and check if the href of the second link ends with -1. This is not the case with the standard <a …>↑</a>, which always ends with -0.