Page MenuHomePhabricator

Auto-linking in CSS/JavaScript comments
Open, In Progress, Needs TriagePublicFeature

Assigned To
Authored By
Bhsd
Dec 24 2025, 7:20 AM
Referenced Files
F71556694: image.png
Jan 17 2026, 6:30 PM
F71556683: image.png
Jan 17 2026, 6:30 PM
F71282151: image.png
Dec 26 2025, 6:29 PM
F71282140: Screenshot (18).png
Dec 26 2025, 6:29 PM

Description

Original request:

CodeMirror should turn links in CSS/JavaScript comments (e.g. /* [[link]] */) into clickable links like it does for such links in wikitext, and like already happens when viewing the page, not editing it (i.e. viewing the page directly, showing preview, or viewing an old revision).

Note that this feature is not available in CodeEditor, and the implementation in SyntaxHighlight is inconsistent with an editor environment. We may consider something similar to the modifier click for the MediaWiki mode instead, perhaps using a nested language.

Event Timeline

Hi, I’d like to work on this task if it’s still available.
I plan to explore how CodeMirror handles comment tokens and see if i can detect links inside CSS/JS comments and render them as clickable, similar to wikitext auto-linking. I’ll share a proposal once I understand the code path better. Please let me know if this approach sounds good.

Hi, I’d like to work on this task if it’s still available.
I plan to explore how CodeMirror handles comment tokens and see if i can detect links inside CSS/JS comments and render them as clickable, similar to wikitext auto-linking. I’ll share a proposal once I understand the code path better. Please let me know if this approach sounds good.

Sure! Please feel free to claim this task, and I am happy to discuss it with you when your proposal is ready.

Hi! I’ve built a working prototype in the CM6 demo that detects [[...]] patterns inside JavaScript comments using a ViewPlugin, highlights them as links, and makes the full range clickable. Next I plan to refine comment detection, add CSS support, store link targets in attributes, and extract it into a reusable extension. I’d appreciate any feedback on this approach. Thanks!

Screenshot (18).png (1×1 px, 48 KB)

image.png (1×1 px, 83 KB)

Looks cool as a prototype! However, I do not think it should be a real link inside the editor. Otherwise, it will make editing complicated.

Agreed the approach and the screenshots look great! Also agreed that they shouldn't be links without some user interaction to trigger them to become links. The way we do this for opening links in wikitext is to require the user to hold the Ctrl key. I think it'd be ideal to do the same here. The extension you create could similarly be registered with CodeMirrorPreferences like:

cm.preferences.registerExtension( 'openLinks', openLinksExtension, cm.view );

This will make it use the same preference (openLinks) as the MediaWiki extension, keeping the storage footprint of the user option blob at a minimum, and it's reasonable to assume if a user does or doesn't want "open links" functionality in wikitext, they probably want the same behaviour in non-wikitext.

Hopefully that makes sense.

MusikAnimal changed the task status from Open to In Progress.Dec 27 2025, 6:48 AM

hi sir,

i made the changes what you have told in comment

Summary
Adds support for detecting [[wiki-style links]] inside comments and makes them Ctrl/Cmd-clickable, matching existing editor behavior.

Details

  • Links inside comments are visually highlighted
  • Activation requires Ctrl (Windows/Linux) or Cmd (macOS) click to avoid interfering with editing
  • Default CodeMirror multi-cursor behavior is suppressed for these interactions
  • Navigation is currently stubbed with a placeholder action

Notes

  • This change is limited to comments and does not affect normal cursor or selection behavior

Thanks for working on this! No "sirs" here. :) Are the code changes already available somewhere, like as a patch in Gerrit?

It just occurred to me that we could do the same thing for links in comments on normal wikitext pages, too (e.g. <!-- [[Link]] -->). Should we start a separate ticket for that?

Thanks! The changes aren’t in Gerrit yet—I’m preparing the patch now and
will upload it there shortly. I wanted to confirm the approach first before
submitting for review.

For links inside comments on normal wikitext pages (like <!-- [[Link]]

-->), that feels like a related but separate case. I agree it would be
better to handle it in a different task.

I’ve pushed a working implementation of MediaWiki-style wikilinks ([[Page]]) in edit mode.
Links are highlighted and Ctrl/Cmd-clickable.
This keeps the scope minimal and matches MediaWiki behavior;

image.png (504×1 px, 11 KB)

image.png (980×1 px, 462 KB)

Sorry, what do you mean by "pushed"? I cannot see any related patches on Gerrit.

Sorry for the confusion. By “pushed” I meant that I have a working implementation locally/on my branch, but I haven’t uploaded it to Gerrit yet.
I’ll prepare and upload the patch to Gerrit shortly and share the link here.

I’ll prepare and upload the patch to Gerrit shortly and share the link here.

If you put Bug: T413457 on a new line in your commit message when submitting to Gerrit, the bot will automatically link it to this task.

Thanks for the note! I’ll include
Bug: T413457
on a new line in the commit message when submitting the patch to Gerrit.

kindly can you provide gerrit repo link