Commit graph

428 commits

Author SHA1 Message Date
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
bhsd 8a3d203a03 fix attributes of table caption and table cell
Merging `inTableCaptioin` method into `eatTableRow` with an additional parameter so that table caption attributes can be respected. This patch also distinguishes double pipes (`||`) which start a new table cell and single pipe (`|`) which ends the attributes.

Bug: T324374
Change-Id: If2d4600067c587fe0b6a6edb332fd4e55abec607
2024-01-19 10:53:51 +08:00
bhsd 5235dbb322 fix protocol-like words not as URL protocol
A valid URL, whether free or not, requires at least 1 character after the protocol.

Bug: T309880
Change-Id: I972c4f0ea4273a3f50db17376af808770f28df0b
2024-01-19 10:27:55 +08:00
jenkins-bot 84d88b1f4e Merge "improve treatment of lists at start of line" 2024-01-19 00:42:52 +00:00
bhsd b4e762bd99 improve treatment of lists at start of line
In the parser, '*', '#', ';' and ':' can actually become nested lists (<ul>, <ol>, <dt> and <dd>) in any possible combinations. This patch does not yet support the `; dt : dd` syntax.

This patch also fixes the 'Unknown highlighting tag undefined' warning.

Bug: T184272
Bug: T170042
Change-Id: I13cc55fadbc9b03fd7c70eab123f7e378d52898d
2024-01-19 00:36:54 +08:00
bhsd e0af18f99d fix heading style conflict with CM5
CSS classes such as `.cm-mw-section-3` are assigned to the `<pre>` elements in CM5 while to the `<span>` elements in CM6. The heading styles for CM6 should not interfere with CM5, at least for now.

Bug: T355290
Change-Id: I47426a8319e67503014f847fba39891bdf42db5b
2024-01-18 23:53:52 +08: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
James D. Forrester 75127a79e3 .nvmrc: Update now we're using Node 18
This also necessitated switching to a newer version of
babel-loader that is compatible with Node 18's SSL stack.

Change-Id: Ic9b65ced978fd91a3c0e50ab94cd59556c355ba9
2024-01-11 11:05:51 -05:00
bhsd 9826cc906f Line-level styling for section heading
This is merely a CSS hack which seems to work well for me. The only required JS change is to wrap plain text in section heading in a span, the CSS class of which is unused.

Bug: T351686
Change-Id: I17b1f0b7a6fdf9c090309f558349a06ccec4257f
2024-01-09 02:35:51 +00:00
MusikAnimal b70413441e CodeMirrorModeMediaWiki: add highlighting for <nowiki> and <pre>
Since <nowiki> and <pre> ignore wikitext, the CM5 implementation
cleverly leveraged the tagModes system so that only HTML entities are
processed. We're effectively doing the same here, only we don't need to
register them as proper TagModes. A FIXME is left to remove the entries
from extension.json after the CM6 upgrade is complete.

Note that line-level styling is still missing, see T351686#9431669.
As a result, multi-line content in a <nowiki> or <pre> may emit JS
warnings, but this is expected until T351686 is resolved.

Bug: T348684
Change-Id: Ia834c4609faf38af3c8f6b791544a7441b5cfb0a
2024-01-03 21:54:35 -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 c1cd9dabf3 CodeMirrorModeMediaWiki: don't detect additional { as template name
This merely ports over Ica3fb110ce and Id5e50c2baf to the CM6
stream parser. Also port the test that was added in I7907b4743b

Bug: T292967
Bug: T348019
Follow-Up: Ica3fb110cebb5650f66be321b533ed030e2c9698
Change-Id: I54b1624131ea63f403ebc1f6f900556ca868b7f4
2024-01-03 19:14:41 +00: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
jenkins-bot 1b6b86a937 Merge "CodeMirror: add stability flags and document properties" 2024-01-02 22:05:18 +00:00
Ed Sanders d7d6cd9410 Remove useless @copyright tags from VE code headers
Change-Id: I43c38a5f21d14341a54f5d18ea535d1c12a81c09
2023-12-18 17:01:58 +00:00
MusikAnimal c1af5e11e0 CodeMirror: add stability flags and document properties
These methods will be used by other modes and/or extensions,
and as per the frontend stable interface policy, they should
be marked as stable.

Also permit callers to pass in a HTMLTextAreaElement, jQuery
object, or a CSS query string.

Change-Id: Iec57bf8fe4086faf57b3cc10834baaa27af80b85
2023-12-13 01:19:34 -05:00
jenkins-bot ed36d5284f Merge "CodeMirrorWikiEditor: add bracketMatching as default extension" 2023-12-11 11:01:53 +00:00
jenkins-bot 89563724b0 Merge "Bump Node dependencies and fix deprecations and linting failures" 2023-12-08 12:16:45 +00:00
thiemowmde 1e845daedc Expand test case for {{!}} in the table syntax
The test case was super minimal, without any actual table cells.

Bug: T292967
Change-Id: I4d86a369b69d12ed0f4967e0e1edd00f886fcb1e
2023-12-07 11:33:40 +01: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 75fa1ec8c7 Bump Node dependencies and fix deprecations and linting failures
Bumps the following, which will be needed by subsequent patches:

* stylelint-config-wikimedia = 0.16.1
* webpack = 5.89.0
* webpack-cli = 5.1.4
* @babel/preset-env = 7.3.0

Change-Id: Icd44ad126f11365ee1215672cee66868e79c8978
2023-12-06 00:43:15 -05:00
thiemowmde 4c92345e6f Don't detect additional { as part of the template name
It's impossible to have a template that has the character { as part
of the name. The real-world example explained in T292967 is the
sequence {{{!}}. The old code detected this as:
* A template that starts with {{
* The template name is {!
* Template ends with }}

New behavior as proposed in this patch:
* A single { with no special meaning
* The parser function {{!}}

Note this is only a very small improvement, but doesn't fully solve
T292967.

Bug: T292967
Change-Id: Ica3fb110cebb5650f66be321b533ed030e2c9698
2023-11-21 12:47:15 +01:00
thiemowmde aa391c1c77 Much more robust detection of template {{{variables}}}
Variables like {{{foo}}} with 3 brackets typically only appear in
templates. But odd combinations of other features that also start
with 3 brackets are much more common. These should not be detected
as variables.

1. When something starts with 4 or more brackets it's not a variable
but something else. E.g. the start of a template where the template
name is a variable (2 + 3 = 5 brackets).

2. Tables can start with {{{!}}.

Note this doesn't fully solve T292967 but already improves the
situation a lot.

Bug: T108450
Bug: T292967
Change-Id: Id5e50c2bafb35a211d4b63609126c40b32f06a64
2023-11-21 12:30:13 +01:00
thiemowmde 8274034243 Add test cases for certain combinations of wikitext features
Document the status quo. This is relevant for the next two patches.

Change-Id: I7907b4743b4dec60c6523dfcc210d947926161be
2023-11-21 12:27:55 +01:00
Volker E c7662a4e74 docs: Remove reference to WikimediaUI Base
And replace with Codex color label, see
https://doc.wikimedia.org/codex/latest/style-guide/colors.html

Bug: T334934
Change-Id: Ia99eae4e09b2b5e622a9b0d316b03006e0ef94ed
2023-10-25 20:06:42 -07:00
MusikAnimal 314bd6d8c4 CodeMirrorWikiEditor: scroll selection into view on inital load
Without the scrollIntoView option set, CodeMirror will always scroll
to the bottom.

See:
https://codemirror.net/docs/ref/#state.TransactionSpec.scrollIntoView

Bug: T317243
Change-Id: I3174685cd3508abf8074eb47e8f2bf81bd303916
2023-10-20 20:47:13 -04:00
MusikAnimal 361741ec86 CodeMirrorWikiEditor: sync with textarea when using CodeMirror toggle
This was working before somehow… but according to the CodeMirror docs,
it never syncs with the textarea automatically, so regardless this is
a necessary safeguard at least.

Repro steps:
1) Have CodeMirror turned on
2) Open a page for editing
3) Add content
4) Toggle CodeMirror off

With this patch, it should now always be synced.

Also add selenium test to ensure this doesn't break again.

Bug: T317243
Change-Id: Ie44e62fe5838bf32f40c6a3595ec3f541380cfe1
2023-10-21 00:42:22 +00:00
MusikAnimal 65b864588b Enable support for RTL when using CodeMirror 6
Refactor common contentAttributes Facet into a default Extension

Bug: T170001
Change-Id: I648bac617b5939c1fc4e115144e55a5cb77d6d66
2023-10-17 20:33:01 -04:00
MusikAnimal c0b01008a4 Add $wgCodeMirrorConflictingGadgets instead of checking wikEd directly
Since wikEd and DotsSyntaxHighlighter are both popular gadgets in and
outside WMF wikis, they are included in this setting by default.

Change-Id: If6c953858f9cf73024959b5a3b71b33ab7b48b4c
2023-10-11 01:33:35 -04:00
MusikAnimal d1cb5a0d01 CodeMirror: fix scrollToCaretPosition $.textSelection implementation
Add selenium tests for textSelection API.

Bug: T317243
Change-Id: I0904a715698aa235fb0744cbc4ff0f9787387592
2023-10-11 01:25:10 -04:00
MusikAnimal 06829a5a0a CodeMirrorWikiEditor: add missing hook and fix reference to textarea
This fixes integration with some consumers of the
'ext.CodeMirror.switch' hook, such as Extension:Disambiguator.
The jQuery element passed to the hook is around the CodeMirror DOM
element which has the jQuery.textSelection() API registered to it.

Bug: T317243
Follow-Up: I2239d2449b2db3b638551f847eb4eff1aafa6276
Change-Id: Iec368613da3c69df52ce5e7ca441c31172cdc5de
2023-10-10 16:11:18 -04:00
jenkins-bot 39ed5a05fc Merge "CodeMirror6: add new modules, feature flag, and URL query parameter" 2023-10-10 08:49:11 +00: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
Ed Sanders 1c853da980 Use white-space: break-spaces
Bug: T347902
Bug: T348006
Change-Id: I62cb4c4f55a9ed80c043c4a1c27dd276559b1cba
2023-10-05 14:30:54 +00:00
James D. Forrester 764ff6478d resources: Manage upstream CodeMirror using ManageForeignResources
Depends-On: Ica6a80d6eb127cc10a00d3d6d0890ad724762ff2
Change-Id: I15721ef93c270a5a2f9194d678cd6876e14c7ea6
2023-09-21 12:40:53 +01:00
David Lynch e9e6361610 Update embedded CodeMirror library to 5.65.15
Was at 5.58.3

Bug: T334994
Change-Id: I74e792a5952973240a111180dde9f5097b48c278
2023-09-20 09:17:03 -05:00
Ed Sanders 21c121b898 build: Update linters
Change-Id: I49eb2de402a8c89065968cf927a2ca6a361ca684
2023-09-13 14:02:43 +01:00
MusikAnimal 46b7208d13 Convert applicable ResourceLoader modules to use packageFiles
Move WikiEditor-specific code to ext.CodeMirror.WikiEditor, leaivng only
CodeMirror-specific things in ext.CodeMirror, including the logUsage
method which was duplicated in the VE plugin and now refactored.

Add .env to .gitignore so that selenium tests can be ran more easily

This patch leaves the other non-mediawiki modes still using the
'scripts' system instead of 'packageFiles'. These are not used in
MediaWiki directly but by some extensions (i.e. PhpTags) and using
packageFiles will break that integration.

Bug: T272035
Change-Id: I3bafef196c1f713443d7b8e9cb7dc2891b379f5d
2023-08-24 11:55:13 -04:00
Sam Wilson 7d48f2d8bb Use editRecovery.loadEnd JS hook to add change handler
Add core's change handler for CodeMirror changes as well, to
save in-progress edit data.

Depends-On: I32c13c1eeec55dc442b0a00ede9cb74422b0307e
Bug: T342882
Change-Id: I352470752130c7b9b2dfc55a066cecf785d40067
2023-07-31 10:44:08 +08:00
Func a19cd9b94a ve.ui: Set the CM wrapper to the appropriate language
Bug: T341342
Change-Id: Ibdac3d360527429e396b0c124b57d1531b959a76
2023-07-07 20:54:00 +08:00
Ed Sanders 9520546e09 Add tool to VE toolbar automatically using 'utility' group
This removes the need for the init module.

Bug: T340751
Depends-On: Ibcc81c90bc9ba6c5fd012c512daf861973b03b2e
Change-Id: Iec3a4c6b00288aee376af47e778c4aa67a98d29b
2023-06-29 14:40:43 +00:00
WMDE-Fisch 6744545c61 Skip user setting for unnamed users
Bug: T329771
Change-Id: I0066c2411bf12fedb1e29cde8306b107c3ab95ba
2023-05-20 15:36:29 +03:00
Volker E ba64a52368 styles: Replace mentioning of WikimediaUI Base and add skin variables
It makes no difference to directly assign Codex Design System for
Wikimedia colors as values instead of re-assigning the outdated
`@wmui-color-*` variables.

Bump to required MediaWiki core version >= v1.41.0.

Also put stylelint-disable before the block it's actually needed.

Bug: T334934
Change-Id: I5696f160d39ef4edec7a1b966fe7e73608c86bdc
2023-05-16 17:58:24 +02:00
jenkins-bot 775de7751a Merge "Search for toolbar place in toolbarConfig as well as actionConfig" 2023-02-16 00:00:25 +00:00
Ed Sanders 47e42bc61b Search for toolbar place in toolbarConfig as well as actionConfig
The actionToolbar is deprecated and will be going away soon.

Change-Id: I475e987959a037eaa536986cba063ab3ccc0083e
2023-02-14 17:30:33 -08:00
Ed Sanders 2f5366dab9 CSS: Remove unused browser prefixes
Change-Id: I91dcffc7a05e6a12dd0ae006bd4195d5c5751704
2023-02-14 17:23:32 -08:00
Umherirrender d4924ebc48 build: Disable rule unit-disallowed-list inline
Bug: T279431
Change-Id: I75698f990c168fa6c9958cdcf9b6e1fe4a0113c9
2022-10-27 00:37:31 +02:00
jenkins-bot cbec99c8c4 Merge "Add tags from CodeMirrorPluginModules to extension tags list" 2022-10-05 14:27:22 +00:00
samtar 5061cc1228
ext.CodeMirror.js: Keep at 100% parent width
Force the CodeMirror area to stay at 100% parent width during a
resize event.

Bug: T305939
Change-Id: I99f5d0b0955521f522a549b2cf1f2205cb0e48c0
2022-08-04 12:54:40 +01:00