Page MenuHomePhabricator

CodeMirror handling of comments within links
Closed, ResolvedPublicBUG REPORT

Description

If you have a comment within a link, e.g. [[Foo <!-- bar -->]], CodeMirror incorrectly highlights the comment as part of the link, and clicking + modifier key on the link doesn't work to open the page "Foo". It's even worse if you put link syntax in the comment, e.g. [[Foo <!-- [[bar]] -->]], where it thinks the closing brackets within the comment mark the end of the link.

Example (go to line 65).

Same goes for external link syntax (e.g. single bracket). And similarly, if you include a bare URL without any brackets but include a comment within it, the comment is highlighted correctly, but the rest of the link after the comment isn't highlighted or included in the link target when you click + modifier key.

When you try the same thing with templates, e.g. {{Foo <!-- {{bar}} --> foo }}, the syntax highlighting works fine, but each bit links as if it is its own template, i.e. in the example I gave each "Foo" links to "Template:Foo" instead of them both linking to "Template:Foo foo".

See also T419335: Add CodeMirror auto-linking where missing, specifically the entries about auto-linking within comments, which touches on this same topic.

Event Timeline

First of all, what is the use case for inserting comments between two parts of a page name/ external URL?

Highlighting of comments inside links is a bug that we should work on first. Will see if we can support openLinks with comments later.
External links (i.e., URLs) containing comments will likely be a "won't fix", which does not make any sense to me.

Change #1275202 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] CodeMirrorMediaWiki: comment in internal/external links

https://gerrit.wikimedia.org/r/1275202

Change #1275202 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirrorMediaWiki: comment in internal/external links

https://gerrit.wikimedia.org/r/1275202

Change #1277223 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] openLinks: handle comments in page names

https://gerrit.wikimedia.org/r/1277223

Bhsd changed the task status from Open to In Progress.Apr 25 2026, 2:31 AM
Bhsd claimed this task.

Change #1277223 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] openLinks: handle comments in page names

https://gerrit.wikimedia.org/r/1277223

Bhsd moved this task from Bugs to Done on the MediaWiki-extensions-CodeMirror board.