Commit graph

11 commits

Author SHA1 Message Date
MusikAnimal 7d3482f89e Isolate build step to CM6 library and restructure files to work with RL
CodeMirror 6 requires the use of NPM, but we can still bundle all CM
packages into one file, and then everything else (i.e. our code) is
managed by ResourceLoader as per usual. This makes contribution
considerably easier as we no longer need a build step for each change.

CM5 files are now under resources/legacy, and the CM6 files are moved to
the root of the resources/ directory. Only one file,
codemirror.bundle.js, is managed by Rollup, while everything else is RL.
The Rollup output for now is put under resources/lib/ alongside the CM5
upstream files.

This patch is *mostly* renames of files, along with changing ECMAScript
Module (ESM) syntax into the CommonJS style that ResourceLoader prefers.
We also remove more modern JS syntax (i.e. private class methods) that
we were able to use before because we had a build step with Babel.

This patch should effectively make no user-facing changes, or to the
ResourceLoader modules we offer in Extension:CodeMirror.

Finally, bump version in extension.json to 6, to match the upstream lib,
and add Bhsd as an author :-)

Bug: T368053
Change-Id: Ie258e49f5df8db23a7344ac3c4c9300aaa991042
2024-07-31 22:45:48 -04:00
MusikAnimal d652f3d2a2 CM6: Add jsdoc build step, fix JSDoc annotations, and add @stable tags
There is a known bug with JSDoc and using `export default`. These must
be separate statements for JSDoc to parse properly.
See https://github.com/jsdoc/jsdoc/issues/1132

Update README; change log now lives on the wiki.

Bug: T359986
Depends-On: I58a0766e35eddaf7bebe2c080757bb09963d8555
Change-Id: Ibc2212ef9eab512511b13a99ecc2ccbda8c52ece
2024-03-26 13:35:47 -04:00
MusikAnimal ca02360228 CM6: Switch to using Rollup instead of Webpack; make RL-compatible
See https://w.wiki/9Twh for example usage with ResourceLoader.

Webpack is retired in favor of Rollup, which allows us to convert the
ECMAScript Modules into CommonJS modules for use by ResourceLoader.
We now have a file in dist/ for each RL module that we want to offer,
including the 'lib' module which includes the CM library itself.

Because Rollup has no knowledge of the ResourceLoader module registry,
the generated output requires other modules via relative path, when it
needs to be the RL module name. To get around this, we do a crude
find/replace after the files are generated. Hacky, but necessary to make
CodeMirror usable by gadgets and scripts that don't also want
WikiEditor.

Add new RL modules 'ext.CodeMirror.v6.lib' (vendor code) and
'ext.CodeMirror.v6' (the main CodeMirror class, sans WikiEditor).

Clean up extension.json, listing the v6 modules beneath the old ones.

Bug: T214989
Change-Id: Ide716247e545cf2bdd977bea645729564ebbe6e2
2024-03-19 22:48:52 -04:00
MusikAnimal 63cd3e4ff8 CodeMirror 6: show wikitext highlighting on protected pages
It is necessary to have a way to toggle CodeMirror on and off, so we use
WikiEditor and hide all other buttons. This is more costly than loading
just vanilla CodeMirror, but it ensures a consistent experience with
pages that are editable, with the toggle button in the familiar place.
At a later time, WikiEditor may be updated to better support read only
pages in a lightweight fashion (T188817).

Bug: T301615
Change-Id: I8ea7597d07ff60a3f58ba306d2d6d12d3ec08b16
2024-03-11 17:35:20 -04:00
MusikAnimal 5a07eb35db CodeMirror 6: localize search dialog
As of this patch, these should be the only messages used by us that live
in the CodeMirror library. More may be added later as new features
are added. We load all translations as a default CodeMirror extension
given the small cost and importance of localization.

German translations from the CodeMirror docs:
https://codemirror.net/examples/translate/

Also add a note in the README about the search dialog.

Bug: T317243
Change-Id: Iba40bcaf197ed48166ce4cdcc4f48177fc8d07f3
2024-02-13 14:56:23 -05:00
MusikAnimal 380ec9d1ce CodeMirrorModeMediaWiki: add support for mediawiki TagModes
This is essentially the CM6-style variant of the same code used for
TagModes in CM5. The big difference is in CM6, every tag must be
registered in order to be used. We do this dynamically when
CodeMirrorModeMediaWiki is intantiated. As of this patch only tags
that contain mediawiki (formerly 'text/mediawiki') are supported,
such as <ref>.

The CM6 tag registration surfaced an old bug, now fixed: when using
different capitalization on extension-supplied tags, the CSS class name
used to match that. I.e. <REF> would produce .cm-mw-ext-REF, when it
should be .cm-mw-ext-ref

Also remove the old line-level styles. With I17b1f0b7a6, line-level
styling was added for section headings. Doing the same for tags like
<nowiki> and <pre> isn't as important, and can be addressed later or
not at all.

Add test case for extension tag with no supplied TagMode

Other minor cleanup, including removing old commented out code

Bug: T348684
Change-Id: Ibfff1fc6eacc42b95f557abb40774a65c46ba373
2024-01-16 15:30:22 -05:00
MusikAnimal bbd142c118 mode.mediawiki: rename mnemonic to html-entity and deprecate variants
This removes treating an HTML entity in a template name as a separate
token, and thus deprecates the .cm-mw-template-name-mnemonic CSS class.

In CM6 we have to register tokens for them to show, and this one seems
of little use to begin with. HTML entities should always be styled as a
such, especially in page titles where they are treated post-processing.
i.e. [[&#47;dev/null]] links to [[/dev/null]].

The rename to .cm-html-entity and associated code is to better reflect
what it is. $rarr; is a mnemonic form while &#x2f; is not, but both are
entities.  Deprecations are noted in the README, with the old classes
to be removed later after on-wiki usage has been updated.

Bug: T348019
Change-Id: I1184fb5d7d37084c80af1abd5f3cb5f2091b085c
2024-01-03 21:48:34 -05:00
MusikAnimal 65f9c986f2 mediawiki.less: don't remove font-weight from .cm-mw-strong tokens
Presumably it was always the intention that tokens with the styles
.cm-mw-page-name AND .cm-mw-em should be both bold and italic in links,
without having the CSS rules override each other. As an example:

  '''''[[Bold and italic title]]'''''

Added a note in the README that this will be a new user-facing feature

Change-Id: Iac41e31b7a9cf8683cd5c982c496ff83a092acfb
2024-01-03 16:08:01 -05:00
MusikAnimal c670344851 Implement core MediaWiki stream parser for CodeMirror 6
This is more or less a exact port of the old stream parser, with the big
notable change being that all configuration-related code lives in a
separate class, CodeMirrorModeMediaWikiConfig. A smaller change is that
closing HTML tags that are marked as errors now have the ending '>'
character highlighted red, when it didn't before.

Integration with other extensions and modes is saved for a future patch
(T348684). This means <nowiki>, <ref> and other extension-supplied
markup is not yet highlighted.

The entry point for WikiEditor integration is now at
ext.CodeMirror.v6.WikiEditor.init.js, which needs to first require the
virtual file set via the DataScript (PHP) class. This can't be
integrated into the CM6 code because it needs to be precompiled before
ResourceLoader can use it (T281781).

Known issues, to be addressed separately:

* No support for TagModes / PluginModes (T348684)
* Identical adjacent tokens produce excess markup (T352917)
* Section headings do not have line-level styling (T351686)

Bug: T348019
Change-Id: I8f8a81f362bed60dea14ecde9487a2b0c89225e8
2024-01-02 23:18:32 -05:00
MusikAnimal 62485151c2 CodeMirrorWikiEditor: add bracketMatching as default extension
By default, this feature highlights unmatched brackets when the cursor
is placed over it. This can be disabled, but seems useful so we'll add
it as one of the new features in README and see how users react.

Bug: T348019
Change-Id: Ie6af715e40aeb8217a7c4dfe0c6e6a3dcfa725d5
2023-12-06 01:46:58 -05:00
MusikAnimal 880c690a10 CodeMirror6: add new modules, feature flag, and URL query parameter
Add a new $wgCodeMirrorV6 temporary feature flag that when enabled,
will load the 'ext.CodeMirror.v6.WikiEditor' module that is built
against CodeMirror 6. You can also pass in the ?cm6enable=1 query
parameter to force use of CodeMirror 6. This is currently only
implemented for the 2010 editor.

Due to packaging constraints with CodeMirror 6, we now use Webpack to
bundle the files, which are then used by ResourceLoader. This is similar
to what is done for Extension:Popups, MobileFrontend, among other
extensions.

A new generic class CodeMirror can be used on other areas where syntax
highlighting is desirable, but not necessarily for editing (i.e. without
WikiEditor).

This commit merely lays the foundation for CodeMirror 6 and updates
WikiEditor to use it. The actual MediaWiki syntax highlighting will come
with a future commit.

With the new Webpack build, the Gruntfile was removed and the tasks
moved to npm commands.

Bug: T317243
Change-Id: I2239d2449b2db3b638551f847eb4eff1aafa6276
2023-10-09 19:51:24 -04:00