Page MenuHomePhabricator

Add a means for mixed languages in wikitext in CodeMirror 6
Open, LowPublic

Description

Background

In CodeMirror 5, if you an extension needs a language other than the default (text/mediawiki) to be highlighted in a tag, you need to register a CodeMirrorPluginModules. For example, MediaWiki-extensions-PhpTags does this with the following:

"CodeMirrorTagModes": {
	"phptag": "text/x-php"
},
"CodeMirrorPluginModules": [
	"ext.CodeMirror.lib.mode.php"
]

Here ext.CodeMirror.lib.mode.php provides the PHP stream parser, which can be side-loaded with the core CodeMirror library, and applied to text within a <phptag>. This works great in CM5, but there is no global scope in CM6, and additionally we have to bundle the ECMAScript modules before handing them over to ResourceLoader. Using the PluginModes system is fine, but it won't by itself give that code the scoping it needs to integrate with CM6.

Fortunately, PhpTags appears to be the only CM integration with mixed-languages within wikitext, and that is not a widely used extension nor deployed on the WMF cluster. We'd still like to support it, but that is secondary. (There's also no CM6 legacy parser for PHP, so this integration may unfortunately have to break anyway.)

This task is to brainstorm ideas on making mixed languages in wikitext possible in CM6. As the lack of this functionality would only effect PhpTags, we're not considering this task a requirement for the CodeMirror 6 upgrade project (T259059).

Potential solutions

  • Use dynamic imports so the necessary modules can be loaded at runtime.
  • Use the mw.hook system to pass the scope such that once the mixed language tag is encountered (i.e. <phptag>), we fire the hook and the handler can supply the stream parser.

Relevant links