Page MenuHomePhabricator

Add different color themes of syntax highlighting
Open, In Progress, MediumPublic

Description

Different page types (for example articles in main namespace and templates, or pages in different content models) have different concentration of different markup elements and it is not trivial task to color all wikitext markup elements since the combination of colors is much less than the combination of wikitext markup elements. Also tastes of editors likely different.

The availability of using different color themes in CodeMirror should help in this case.

Kinds of color themes for wikitext:

  • Light color theme for articles in main namespace (used by default)
  • Theme(s) for people who are color-blind
  • No syntax highlighting at all (T419339)
  • Same vendor themes provided in non-wikitext

Kinds of color themes for codes:

Related Objects

Event Timeline

MusikAnimal raised the priority of this task from Lowest to Medium.Mar 4 2026, 8:39 PM

When this is tackled (after T420429), we should migrate the codemirror-colorblind user option to the new theme CM preference, and slowly over time the codemirror-colorblind rows will be deleted.

MusikAnimal changed the task status from Open to In Progress.Apr 26 2026, 6:43 PM
MusikAnimal claimed this task.

I'm going to add this as part of T420429: Add support for non-boolean CodeMirror preferences.

For the initial implementation, we will have just three themes:

  • Default
  • No highlighting (T419339)
  • Colorblind (for wikitext-only; moves the existing "colorblind-friendly" preference to be a theme)

Under the hood, I'm trying abstract things and make it easy to add new non-boolean preferences. I'll do this with a system called a "form specifier" which is similar to how HTMLForm works in PHP.

Change #1277806 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] [WIP] Add themes to preferences, and support for non-boolean prefs

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

Change #1295787 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] CodeMirrorPreferences: add support for form specifiers

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

Change #1295787 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirrorPreferences: add support for form specifiers

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

Change #1297761 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] [POC] Rework mediawiki tags to be better suited for themes

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

@MusikAnimal Is this task worth User-notice? We can merge your patch after Monday.

I would think so, especially since it involves moving existing functionality (colorblind mode) to a new location. An announcement would help people know what to expect.

Change #1277806 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirrorThemes: add themes to preferences in a new Appearance section

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

A patch that will be deployed next week adds themes to CodeMirror syntax highlighting. The themes can be picked from a dropdown menu in the full CodeMirror preference dialog. For Wikitext, available themes are default, colorblind-friendly (previously the colorblind preference option on Special:Preferences#mw-prefsection-editing) and no-highlight. For code languages (i.e., CSS/JavaScript/JSON/Vue/Lua), there are a few third-party themes available.

@Bhsd entry added, please make any changes if needed on the draft meta page: https://meta.wikimedia.org/wiki/Tech/News/2026/31

@Bhsd entry added, please make any changes if needed on the draft meta page: https://meta.wikimedia.org/wiki/Tech/News/2026/31

@MusikAnimal Could you take a look at the draft?

I made some copy edits. Thanks for getting it in Tech News!

Change #1316992 had a related patch set uploaded (by DLynch; author: DLynch):

[mediawiki/extensions/CodeMirror@master] CodeMirrorThemes: extract mediawiki theme colors to a shared less file

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

Change #1316992 had a related patch set uploaded (by DLynch; author: DLynch):

[mediawiki/extensions/CodeMirror@master] CodeMirrorThemes: extract mediawiki theme colors to a shared less file

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

Change #1316992 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirrorThemes: extract mediawiki theme colors to a shared less file

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

Thank you for adding themes in CodeMirror.

Would it be possible to add pygment syntax highlighting, or is there some technical difficulty with it? That would allow to have the same syntax highlighting when viewing code and when editing it, as pygment is used by Extension:SyntaxHighlight.

Would it be possible to add pygment syntax highlighting, or is there some technical difficulty with it? That would allow to have the same syntax highlighting when viewing code and when editing it, as pygment is used by Extension:SyntaxHighlight.

These are fundamentally different solutions that don't share the same method of interpreting the code, nor the same color schemes. While something can probably be made that 'somewhat looks the same for some languages' they will never be fully the same.

Yeah if anyone wants to take a stab at implementing a Pygments theme, I'll gladly assist. You can use an existing theme (example) as a guide. It's mostly just picking out the right colours. There is also currently a requirement that all themes have both a light and dark mode variant.