@bhsd/codemirror-mediawiki 3.1.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,10 +2,17 @@
2
2
  [![jsDelivr hits (npm scoped)](https://img.shields.io/jsdelivr/npm/hm/%40bhsd/codemirror-mediawiki)](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki)
3
3
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/972fd5f6684c4fd8ac2f26e01d349948)](https://app.codacy.com/gh/bhsd-harry/codemirror-mediawiki/dashboard)
4
4
 
5
+ # @bhsd/codemirror-mediawiki
6
+
7
+ This repository contains a modified version of the frontend scripts and styles from [MediaWiki extension CodeMirror](https://www.mediawiki.org/wiki/Extension:CodeMirror). The goal is to support a standalone integration between [CodeMirror](https://codemimrror.net) and [Wikitext](https://www.mediawiki.org/wiki/Wikitext), without the need for a [MediaWiki environment](https://doc.wikimedia.org/mediawiki-core/master/js/).
8
+
9
+ Here is a [demo](https://bhsd-harry.github.io/codemirror-mediawiki). To experiment with the RTL (right-to-left) support, you can append `?rtl=1` to the URL.
10
+
11
+ Nonetheless, this repository also provides a customized version with additional functionality for use on a MediaWiki site. Browser editing tools such as [Wikiplus-highlight](https://www.npmjs.com/package/wikiplus-highlight) and an [InPageEdit plugin](https://github.com/inpageedit/Plugins/blob/master/src/plugins/code-mirror/cm6.js) are built upon it. Please refer to a separate [README](./mw/README.md) file for the information.
12
+
5
13
  <details>
6
14
  <summary>Expand</summary>
7
15
 
8
- - [Description](#description)
9
16
  - [Installation](#installation)
10
17
  - [Browser Usage](#browser-usage)
11
18
  - [Download JavaScript](#download-javascript)
@@ -18,6 +25,11 @@
18
25
  - [lua](#lua)
19
26
  - [mediawiki](#mediawiki)
20
27
  - [vue](#vue)
28
+ - [Other languages](#other-languages)
29
+ - [Themes](#themes)
30
+ - [light](#light)
31
+ - [nord](#nord)
32
+ - [Other themes](#other-themes)
21
33
  - [Constructor](#constructor)
22
34
  - [Accessors](#accessors)
23
35
  - [dialect](#dialect)
@@ -39,6 +51,7 @@
39
51
  - [setIndent](#setindent)
40
52
  - [setLanguage](#setlanguage)
41
53
  - [setLineWrapping](#setlinewrapping)
54
+ - [setTheme](#settheme)
42
55
  - [toggle](#toggle)
43
56
  - [update](#update)
44
57
  - [Static methods](#static-methods)
@@ -68,14 +81,6 @@
68
81
 
69
82
  </details>
70
83
 
71
- # Description
72
-
73
- This repository contains a modified version of the frontend scripts and styles from [MediaWiki extension CodeMirror](https://www.mediawiki.org/wiki/Extension:CodeMirror). The goal is to support a standalone integration between [CodeMirror](https://codemimrror.net) and [Wikitext](https://www.mediawiki.org/wiki/Wikitext), without the need for a [MediaWiki environment](https://doc.wikimedia.org/mediawiki-core/master/js/).
74
-
75
- Here is a [demo](https://bhsd-harry.github.io/codemirror-mediawiki). To experiment with the RTL (right-to-left) support, you can append `?rtl=1` to the URL.
76
-
77
- Nonetheless, this repository also provides a customized version with additional functionality for use on a MediaWiki site. Browser editing tools such as [Wikiplus-highlight](https://github.com/bhsd-harry/Wikiplus-highlight) and an [InPageEdit plugin](https://github.com/inpageedit/Plugins) are built upon it. Please refer to a separate [README](./mw/README.md) file for the information.
78
-
79
84
  # Installation
80
85
 
81
86
  You can install the package via npm and import it as a module:
@@ -234,6 +239,17 @@ import {registerHTMLCore} from '@bhsd/codemirror-mediawiki';
234
239
  registerHTMLCore();
235
240
  ```
236
241
 
242
+ In addition to the common [extensions](#extensions), here are some HTML-specific extensions. Note that these extensions may not take effect if the corresponding common extensions are not registered:
243
+
244
+ ```js
245
+ import {
246
+ registerCloseBracketsForHTML,
247
+ registerColorPickerForHTML,
248
+ } from '@bhsd/codemirror-mediawiki';
249
+ registerCloseBracketsForHTML();
250
+ registerColorPickerForHTML();
251
+ ```
252
+
237
253
  </details>
238
254
 
239
255
  ## javascript
@@ -388,6 +404,41 @@ registerLanguageCore('python', python);
388
404
 
389
405
  </details>
390
406
 
407
+ # Themes
408
+
409
+ ## light
410
+
411
+ This is the default theme, which is a light theme.
412
+
413
+ ## nord
414
+
415
+ <details>
416
+ <summary>Expand</summary>
417
+
418
+ This is a dark theme created by [Takuya Matsuyama](https://www.npmjs.com/package/cm6-theme-nord) and [鬼影233](https://zh.moegirl.org.cn/User:%E9%AC%BC%E5%BD%B1233/Nord). You need to register this theme before using it:
419
+
420
+ ```js
421
+ import {registerTheme, nord} from '@bhsd/codemirror-mediawiki';
422
+ registerTheme('nord', nord);
423
+ ```
424
+
425
+ </details>
426
+
427
+ ## Other themes
428
+
429
+ <details>
430
+ <summary>Expand</summary>
431
+
432
+ You can also register other themes by importing the `registerTheme` function:
433
+
434
+ ```js
435
+ import {registerTheme} from '@bhsd/codemirror-mediawiki';
436
+ import {oneDark} from '@codemirror/theme-one-dark';
437
+ registerTheme('one-dark', oneDark);
438
+ ```
439
+
440
+ </details>
441
+
391
442
  # Constructor
392
443
 
393
444
  <details>
@@ -542,6 +593,23 @@ const tree = cm.getNodeAt(0);
542
593
 
543
594
  </details>
544
595
 
596
+ ## hasPreference
597
+
598
+ <details>
599
+ <summary>Expand</summary>
600
+
601
+ *version added: 3.2.0*
602
+
603
+ **param**: `string` extension name
604
+ **returns**: `boolean`
605
+ Check if the editor enables the given extension.
606
+
607
+ ```js
608
+ const hasAutocompletion = cm.hasPreference('autocompletion');
609
+ ```
610
+
611
+ </details>
612
+
545
613
  ## initialize
546
614
 
547
615
  <details>
@@ -608,7 +676,7 @@ cm.localize({
608
676
 
609
677
  *version added: 2.0.9*
610
678
 
611
- **param**: `string[] | Record<string, boolean>` the preferred [CodeMirror extensions](https://codemirror.net/docs/extensions/)
679
+ **param**: `string[] | Record<string, boolean>` the [extensions](#extensions) to enable
612
680
  Set the preferred CodeMirror extensions. Available extensions are introduced [later](#extensions).
613
681
 
614
682
  ```js
@@ -752,6 +820,24 @@ cm.setLineWrapping(true);
752
820
 
753
821
  </details>
754
822
 
823
+ ## setTheme
824
+
825
+ <details>
826
+ <summary>Expand</summary>
827
+
828
+ *version added: 3.3.0*
829
+
830
+ **param**: `string` the theme name
831
+ Set the theme of the editor. The default theme is `light`, other themes need to be registered using the `registerTheme` function first:
832
+
833
+ ```js
834
+ import {registerTheme, nord} from '@bhsd/codemirror-mediawiki';
835
+ registerTheme('nord', nord);
836
+ cm.setTheme('nord');
837
+ ```
838
+
839
+ </details>
840
+
755
841
  ## toggle
756
842
 
757
843
  <details>
@@ -1151,6 +1237,9 @@ registerSignatureHelp();
1151
1237
 
1152
1238
  ## Syntax Highlighting
1153
1239
 
1240
+ <details>
1241
+ <summary>Expand</summary>
1242
+
1154
1243
  ### Extension
1155
1244
 
1156
1245
  1. [Extension:Translate](https://www.mediawiki.org/wiki/Extension:Translate) is not supported.
@@ -1183,3 +1272,5 @@ registerSignatureHelp();
1183
1272
  ### Language conversion
1184
1273
 
1185
1274
  1. BCP 47 language codes are not supported in language conversion ([Example](https://bhsd-harry.github.io/wikiparser-node/tests.html#Explicit%20definition%20of%20language%20variant%20alternatives%20(BCP%2047%20codes))).
1275
+
1276
+ </details>
@@ -4,17 +4,32 @@ import type { Extension } from '@codemirror/state';
4
4
  import type { SyntaxNode } from '@lezer/common';
5
5
  import type { ConfigData } from 'wikiparser-node';
6
6
  import type { MwConfig } from './token';
7
- import type { DocRange } from './fold';
7
+ import type { DocRange, foldHandler } from './fold';
8
8
  import type { Option, LiveOption } from './linter';
9
9
  import type { LintSource, LintSourceGetter } from './lintsource';
10
+ import type { detectIndent } from './indent';
11
+ import type statusBar from './statusBar';
10
12
  export type AddonMain<T> = (config?: T, cm?: CodeMirror6) => Extension;
11
13
  export type Addon<T> = [AddonMain<T>, Record<string, T>?];
12
14
  export type Dialect = 'sanitized-css' | undefined;
15
+ export interface MenuItem {
16
+ name: string;
17
+ isActionable(this: void, cm: CodeMirror6): boolean;
18
+ getItems(this: void, cm: CodeMirror6): HTMLDivElement[];
19
+ }
20
+ declare interface OptionalFunctions {
21
+ statusBar: typeof statusBar;
22
+ detectIndent: typeof detectIndent;
23
+ foldHandler: typeof foldHandler;
24
+ }
13
25
  export declare const plain: () => Extension;
14
26
  export declare const languages: Record<string, (config?: any) => Extension>;
15
27
  export declare const avail: Record<string, Addon<any>>;
16
28
  export declare const linterRegistry: Record<string, LintSourceGetter>;
29
+ export declare const menuRegistry: MenuItem[];
17
30
  export declare const destroyListeners: ((view: EditorView) => void)[];
31
+ export declare const themes: Record<string, Extension>;
32
+ export declare const optionalFunctions: OptionalFunctions;
18
33
  /** CodeMirror 6 editor */
19
34
  export declare class CodeMirror6 {
20
35
  #private;
@@ -55,6 +70,11 @@ export declare class CodeMirror6 {
55
70
  lint(lintSource?: LintSource): void;
56
71
  /** Update syntax checking immediately */
57
72
  update(): void;
73
+ /**
74
+ * Check if the editor enables a specific extension
75
+ * @param name extension name
76
+ */
77
+ hasPreference(name: string): boolean;
58
78
  /**
59
79
  * Add extensions
60
80
  * @param names extension names
@@ -111,6 +131,12 @@ export declare class CodeMirror6 {
111
131
  anchor: number;
112
132
  head: number;
113
133
  }): void;
134
+ /**
135
+ * Set the editor theme
136
+ * @param theme theme name
137
+ * @since 3.3.0
138
+ */
139
+ setTheme(theme: string): void;
114
140
  /**
115
141
  * Replace the current selection with the result of a function
116
142
  * @param view EditorView instance
@@ -124,3 +150,4 @@ export declare class CodeMirror6 {
124
150
  */
125
151
  abstract static getMwConfig(config: ConfigData): MwConfig;
126
152
  }
153
+ export {};
@@ -4,16 +4,27 @@ import { syntaxHighlighting, defaultHighlightStyle, indentOnInput, indentUnit, e
4
4
  import { defaultKeymap, historyKeymap, history, redo, indentWithTab } from '@codemirror/commands';
5
5
  import { searchKeymap } from '@codemirror/search';
6
6
  import { linter, lintGutter, lintKeymap } from '@codemirror/lint';
7
- import { foldHandler } from './fold';
8
- import statusBar from './statusBar';
9
- import { detectIndent } from './indent';
7
+ import { light } from './theme';
10
8
  export const plain = () => EditorView.contentAttributes.of({ spellcheck: 'true' });
11
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
10
  export const languages = { plain };
13
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
12
  export const avail = {};
15
13
  export const linterRegistry = {};
14
+ export const menuRegistry = [];
16
15
  export const destroyListeners = [];
16
+ export const themes = { light };
17
+ export const optionalFunctions = {
18
+ statusBar() {
19
+ return [];
20
+ },
21
+ detectIndent(_, indent) {
22
+ return indent;
23
+ },
24
+ foldHandler() {
25
+ return () => { };
26
+ },
27
+ };
17
28
  const editExtensions = new Set(['closeBrackets', 'autocompletion', 'signatureHelp']);
18
29
  const linters = {};
19
30
  const phrases = {};
@@ -28,11 +39,13 @@ export class CodeMirror6 {
28
39
  #extraKeys = new Compartment();
29
40
  #phrases = new Compartment();
30
41
  #lineWrapping = new Compartment();
42
+ #theme = new Compartment();
31
43
  #view;
32
44
  #lang;
33
45
  #visible = false;
34
46
  #preferred = new Set();
35
47
  #indentStr = '\t';
48
+ #nestedMWLanguage;
36
49
  /** textarea element */
37
50
  get textarea() {
38
51
  return this.#textarea;
@@ -62,6 +75,15 @@ export class CodeMirror6 {
62
75
  this.initialize(config);
63
76
  }
64
77
  }
78
+ /**
79
+ * 获取语言扩展
80
+ * @param config 语言设置
81
+ */
82
+ #getLanguage(config) {
83
+ const lang = (languages[this.#lang] ?? plain)(config);
84
+ this.#nestedMWLanguage = lang.nestedMWLanguage;
85
+ return lang;
86
+ }
65
87
  /**
66
88
  * Initialize the editor
67
89
  * @param config language configuration
@@ -69,13 +91,14 @@ export class CodeMirror6 {
69
91
  initialize(config) {
70
92
  let timer;
71
93
  const { textarea, lang } = this, { value, dir: d, accessKey, tabIndex, lang: l, readOnly } = textarea, extensions = [
72
- this.#language.of(languages[lang](config)),
94
+ this.#language.of(this.#getLanguage(config)),
73
95
  this.#linter.of(linters[lang] ?? []),
74
96
  this.#extensions.of([]),
75
97
  this.#dir.of(EditorView.editorAttributes.of({ dir: d })),
76
98
  this.#extraKeys.of([]),
77
99
  this.#phrases.of(EditorState.phrases.of(phrases)),
78
100
  this.#lineWrapping.of(EditorView.lineWrapping),
101
+ this.#theme.of(light),
79
102
  syntaxHighlighting(defaultHighlightStyle),
80
103
  EditorView.contentAttributes.of({
81
104
  accesskey: accessKey,
@@ -126,7 +149,7 @@ export class CodeMirror6 {
126
149
  : [
127
150
  history(),
128
151
  indentOnInput(),
129
- this.#indent.of(indentUnit.of(detectIndent(value, this.#indentStr, lang))),
152
+ this.#indent.of(indentUnit.of(optionalFunctions.detectIndent(value, this.#indentStr, lang))),
130
153
  keymap.of([
131
154
  ...historyKeymap,
132
155
  indentWithTab,
@@ -145,7 +168,7 @@ export class CodeMirror6 {
145
168
  this.#view.scrollDOM.style.fontSize = fontSize;
146
169
  this.#view.scrollDOM.style.lineHeight = lineHeight;
147
170
  this.toggle(true);
148
- this.#view.dom.addEventListener('click', foldHandler(this.#view));
171
+ this.#view.dom.addEventListener('click', optionalFunctions.foldHandler(this.#view));
149
172
  this.prefer({});
150
173
  }
151
174
  /**
@@ -175,7 +198,7 @@ export class CodeMirror6 {
175
198
  async setLanguage(lang = 'plain', config) {
176
199
  this.#lang = lang;
177
200
  if (this.#view) {
178
- const ext = (languages[lang] ?? plain)(config);
201
+ const ext = this.#getLanguage(config);
179
202
  this.#effects([
180
203
  this.#language.reconfigure(ext),
181
204
  this.#linter.reconfigure(linters[lang] ?? []),
@@ -202,7 +225,7 @@ export class CodeMirror6 {
202
225
  }),
203
226
  lintGutter(),
204
227
  keymap.of(lintKeymap),
205
- statusBar(lintSource.fixer),
228
+ optionalFunctions.statusBar(this, lintSource.fixer),
206
229
  ]
207
230
  : [];
208
231
  if (lintSource) {
@@ -227,6 +250,13 @@ export class CodeMirror6 {
227
250
  }
228
251
  }
229
252
  }
253
+ /**
254
+ * Check if the editor enables a specific extension
255
+ * @param name extension name
256
+ */
257
+ hasPreference(name) {
258
+ return this.#preferred.has(name);
259
+ }
230
260
  /**
231
261
  * Add extensions
232
262
  * @param names extension names
@@ -259,7 +289,7 @@ export class CodeMirror6 {
259
289
  */
260
290
  setIndent(indent) {
261
291
  if (this.#view) {
262
- this.#effects(this.#indent.reconfigure(indentUnit.of(detectIndent(this.#view.state.doc, indent, this.#lang))));
292
+ this.#effects(this.#indent.reconfigure(indentUnit.of(optionalFunctions.detectIndent(this.#view.state.doc, indent, this.#lang))));
263
293
  }
264
294
  else {
265
295
  this.#indentStr = indent;
@@ -279,7 +309,7 @@ export class CodeMirror6 {
279
309
  * @param opt linter options
280
310
  */
281
311
  async getLinter(opt) {
282
- return linterRegistry[this.#lang]?.(opt, this.#view);
312
+ return linterRegistry[this.#lang]?.(opt, this.#view, this.#nestedMWLanguage);
283
313
  }
284
314
  /**
285
315
  * Set content
@@ -385,6 +415,18 @@ export class CodeMirror6 {
385
415
  this.#view.dispatch({ effects });
386
416
  }
387
417
  }
418
+ /**
419
+ * Set the editor theme
420
+ * @param theme theme name
421
+ * @since 3.3.0
422
+ */
423
+ setTheme(theme) {
424
+ if (theme in themes) {
425
+ this.#view?.dispatch({
426
+ effects: this.#theme.reconfigure(themes[theme]),
427
+ });
428
+ }
429
+ }
388
430
  /**
389
431
  * Replace the current selection with the result of a function
390
432
  * @param view EditorView instance
package/dist/css.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { LanguageSupport } from '@codemirror/language';
2
+ import type { Extension } from '@codemirror/state';
2
3
  import type { Dialect } from './codemirror';
4
+ export declare const cssCompletion: (dialect?: Dialect) => Extension;
3
5
  declare const _default: (dialect: Dialect) => LanguageSupport;
4
6
  export default _default;
package/dist/css.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { cssLanguage, cssCompletionSource } from '@codemirror/lang-css';
2
2
  import { LanguageSupport, syntaxTree } from '@codemirror/language';
3
- export default (dialect) => new LanguageSupport(cssLanguage, cssLanguage.data.of({
3
+ export const cssCompletion = (dialect) => cssLanguage.data.of({
4
4
  autocomplete(context) {
5
5
  const { state, pos } = context, node = syntaxTree(state).resolveInner(pos, -1), result = cssCompletionSource(context);
6
6
  if (result) {
@@ -27,4 +27,5 @@ export default (dialect) => new LanguageSupport(cssLanguage, cssLanguage.data.of
27
27
  }
28
28
  return result;
29
29
  },
30
- }));
30
+ });
31
+ export default (dialect) => new LanguageSupport(cssLanguage, cssCompletion(dialect));
package/dist/escape.js CHANGED
@@ -2,7 +2,7 @@ import { keymap } from '@codemirror/view';
2
2
  import { EditorSelection } from '@codemirror/state';
3
3
  import { indentMore, indentLess } from '@codemirror/commands';
4
4
  import { getLSP } from '@bhsd/browser';
5
- import { CodeMirror6 } from './codemirror';
5
+ import { CodeMirror6, menuRegistry } from './codemirror';
6
6
  const entity = { '"': 'quot', "'": 'apos', '<': 'lt', '>': 'gt', '&': 'amp', ' ': 'nbsp' };
7
7
  /**
8
8
  * 根据函数转换选中文本
@@ -32,35 +32,76 @@ export const escapeHTML = (str) => [...str].map(c => {
32
32
  }
33
33
  return encodeURIComponent(str);
34
34
  };
35
+ const escapeWiki = (cm) => {
36
+ const view = cm.view, { state } = view, { ranges } = state.selection, lsp = getLSP(view, false, cm.getWikiConfig);
37
+ if (lsp && 'provideRefactoringAction' in lsp && ranges.some(({ empty }) => !empty)) {
38
+ (async () => {
39
+ const replacements = new WeakMap();
40
+ for (const range of ranges) {
41
+ // eslint-disable-next-line no-await-in-loop
42
+ const [action] = await lsp.provideRefactoringAction(state.sliceDoc(range.from, range.to));
43
+ replacements.set(range, action?.edit.changes[''][0].newText);
44
+ }
45
+ view.dispatch(state.changeByRange(range => {
46
+ const insert = replacements.get(range);
47
+ if (insert === undefined) {
48
+ return { range };
49
+ }
50
+ return {
51
+ range: EditorSelection.range(range.from, range.from + insert.length),
52
+ changes: { from: range.from, to: range.to, insert },
53
+ };
54
+ }));
55
+ })();
56
+ return true;
57
+ }
58
+ return false;
59
+ };
60
+ const handlerBase = (view, e) => {
61
+ e.stopPropagation();
62
+ view.focus();
63
+ };
64
+ let items;
65
+ menuRegistry.push({
66
+ name: 'escape',
67
+ isActionable({ lang, view }) {
68
+ return lang === 'mediawiki' && view.state.selection.ranges.some(({ empty }) => !empty);
69
+ },
70
+ getItems(cm) {
71
+ if (!items) {
72
+ const view = cm.view, btnHTML = document.createElement('div'), btnURI = document.createElement('div');
73
+ btnHTML.textContent = 'HTML escape';
74
+ btnHTML.addEventListener('click', e => {
75
+ CodeMirror6.replaceSelections(view, escapeHTML);
76
+ handlerBase(view, e);
77
+ });
78
+ btnURI.textContent = 'URI encode/decode';
79
+ btnURI.addEventListener('click', e => {
80
+ CodeMirror6.replaceSelections(view, escapeURI);
81
+ handlerBase(view, e);
82
+ });
83
+ items = [btnHTML, btnURI];
84
+ const lsp = getLSP(view, false, cm.getWikiConfig);
85
+ if (lsp && 'provideRefactoringAction' in lsp) {
86
+ const btnWiki = document.createElement('div');
87
+ btnWiki.textContent = 'Escape with magic words';
88
+ btnWiki.addEventListener('click', e => {
89
+ escapeWiki(cm);
90
+ handlerBase(view, e);
91
+ });
92
+ items.unshift(btnWiki);
93
+ }
94
+ }
95
+ return items;
96
+ },
97
+ });
35
98
  export default (cm) => keymap.of([
36
99
  { key: 'Mod-[', run: convert(escapeHTML, indentLess) },
37
100
  { key: 'Mod-]', run: convert(escapeURI, indentMore) },
38
101
  {
39
102
  key: 'Mod-\\',
40
- run(view) {
41
- const { state } = view, { ranges } = state.selection, lsp = getLSP(view, false, cm.getWikiConfig);
42
- if (lsp && 'provideRefactoringAction' in lsp && ranges.some(({ empty }) => !empty)) {
43
- (async () => {
44
- const replacements = new WeakMap();
45
- for (const range of ranges) {
46
- // eslint-disable-next-line no-await-in-loop
47
- const [action] = await lsp.provideRefactoringAction(state.sliceDoc(range.from, range.to));
48
- replacements.set(range, action?.edit.changes[''][0].newText);
49
- }
50
- view.dispatch(state.changeByRange(range => {
51
- const insert = replacements.get(range);
52
- if (insert === undefined) {
53
- return { range };
54
- }
55
- return {
56
- range: EditorSelection.range(range.from, range.from + insert.length),
57
- changes: { from: range.from, to: range.to, insert },
58
- };
59
- }));
60
- })();
61
- return true;
62
- }
63
- return false;
103
+ run() {
104
+ return escapeWiki(cm);
64
105
  },
65
106
  },
66
107
  ]);
package/dist/fold.js CHANGED
@@ -323,7 +323,7 @@ const markers = /* @__PURE__ */ ViewPlugin.fromClass(class {
323
323
  }
324
324
  }
325
325
  });
326
- const defaultFoldExtension = [foldGutter(), keymap.of(foldKeymap)];
326
+ const defaultFoldExtension = /* @__PURE__ */ (() => [foldGutter(), keymap.of(foldKeymap)])();
327
327
  /**
328
328
  * 生成折叠命令
329
329
  * @param refOnly 是否仅检查`<ref>`标签
package/dist/html.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { LanguageSupport } from '@codemirror/language';
2
+ import type { MwConfig } from './token';
3
+ declare const _default: (config: MwConfig) => LanguageSupport;
4
+ export default _default;
package/dist/html.js ADDED
@@ -0,0 +1,31 @@
1
+ import { configureNesting } from '@lezer/html';
2
+ import { htmlPlain, htmlCompletionSourceWith } from '@codemirror/lang-html';
3
+ import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
4
+ import { cssLanguage } from '@codemirror/lang-css';
5
+ import { LanguageSupport } from '@codemirror/language';
6
+ import { jsCompletion } from './javascript';
7
+ import { mediawiki } from './mediawiki';
8
+ import { cssCompletion } from './css';
9
+ export default (config) => {
10
+ const { language, support } = mediawiki(config), lang = new LanguageSupport(htmlPlain.configure({
11
+ wrap: configureNesting([
12
+ { tag: 'script', parser: javascriptLanguage.parser },
13
+ { tag: 'style', parser: cssLanguage.parser },
14
+ { tag: 'noinclude', parser: language.parser },
15
+ ], [{ name: 'style', parser: cssLanguage.parser.configure({ top: 'Styles' }) }]),
16
+ }), [
17
+ htmlPlain.data.of({
18
+ autocomplete: htmlCompletionSourceWith({
19
+ extraTags: {
20
+ noinclude: { globalAttrs: false },
21
+ },
22
+ }),
23
+ }),
24
+ javascript().support,
25
+ jsCompletion,
26
+ cssCompletion(),
27
+ support,
28
+ ]);
29
+ Object.assign(lang, { nestedMWLanguage: language });
30
+ return lang;
31
+ };
package/dist/indent.js CHANGED
@@ -1,4 +1,4 @@
1
- const noDetectionLangs = new Set(['plain', 'mediawiki', 'html']);
1
+ const noDetectionLangs = new Set(['plain', 'mediawiki']);
2
2
  const getLines = (text) => text.children?.flatMap(getLines) ?? text.text;
3
3
  /**
4
4
  * 检测文本的缩进方式
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CodeMirror6 } from './codemirror';
2
+ import type { Extension } from '@codemirror/state';
2
3
  import type { LanguageSupport } from '@codemirror/language';
3
4
  import type { MwConfig } from './token';
4
5
  import type { LintSourceGetter } from './lintsource';
@@ -54,7 +55,11 @@ export declare const registerCodeFoldingForMediaWiki: () => void;
54
55
  export declare const registerMediaWikiCore: () => void;
55
56
  /** Register mixed MediaWiki-HTML language support */
56
57
  export declare const registerHTML: () => void;
57
- /** Register HTML core language support */
58
+ /** Register the `closeBrackets` extension for mixed MediaWiki-HTML */
59
+ export declare const registerCloseBracketsForHTML: () => void;
60
+ /** Register the `colorPicker` extension for mixed MediaWiki-HTML */
61
+ export declare const registerColorPickerForHTML: () => void;
62
+ /** Register mixed MediaWiki-HTML core language support */
58
63
  export declare const registerHTMLCore: () => void;
59
64
  /** Register JavaScript language support */
60
65
  export declare const registerJavaScript: () => void;
@@ -96,3 +101,5 @@ export declare const registerLanguage: (name: string, lang: (config?: unknown) =
96
101
  * @param lintSource optional linter
97
102
  */
98
103
  export declare const registerLanguageCore: (name: string, lang: (config?: unknown) => LanguageSupport, lintSource?: LintSourceGetter) => void;
104
+ export declare const registerTheme: (name: string, theme: Extension) => void;
105
+ export { nord } from './theme';