@bhsd/codemirror-mediawiki 2.0.8 → 2.0.10

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
@@ -1,8 +1,162 @@
1
1
  [![npm version](https://badge.fury.io/js/@bhsd%2Fcodemirror-mediawiki.svg)](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki)
2
2
  [![CodeQL](https://github.com/bhsd-harry/codemirror-mediawiki/actions/workflows/codeql.yml/badge.svg)](https://github.com/bhsd-harry/codemirror-mediawiki/actions/workflows/codeql.yml)
3
3
 
4
+ <details>
5
+ <summary>Expand</summary>
6
+
7
+ - [Description](#description)
8
+ - [Usage](#usage)
9
+ - [constructor](#constructor)
10
+ - [textarea](#textarea)
11
+ - [view](#view)
12
+ - [lint](#lint)
13
+ - [prefer](#prefer)
14
+ - [setIndent](#setindent)
15
+ - [setLanguage](#setlanguage)
16
+ - [update](#update)
17
+
18
+ </details>
19
+
4
20
  # Description
5
21
 
6
22
  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/).
7
23
 
8
- Here is a [demo](https://bhsd-harry.github.io/wikiparser-node/index.html#linter) when the option "with syntax highlighting" is checked.
24
+ Here is a [demo](https://bhsd-harry.github.io/codemirror-mediawiki).
25
+
26
+ # Usage
27
+
28
+ You can download the code via CDN, for example:
29
+
30
+ ```js
31
+ // static import
32
+ import { CodeMirror6 } from 'https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.0.8/dist/main.min.js';
33
+ ```
34
+
35
+ or
36
+
37
+ ```js
38
+ // dynamic import
39
+ const { CodeMirror6 } = await import( 'https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.0.8/dist/main.min.js' );
40
+ ```
41
+
42
+ ## constructor
43
+
44
+ <details>
45
+ <summary>Expand</summary>
46
+
47
+ **param**: `HTMLTextAreaElement` the textarea element to be replaced by CodeMirror
48
+ **param**: `string` the language mode to be used, default as plain text
49
+ **param**: `unknown` the optional language configuration
50
+
51
+ ```js
52
+ const cm = new CodeMirror6( textarea, 'css' );
53
+ ```
54
+
55
+ </details>
56
+
57
+ ## textarea
58
+
59
+ <details>
60
+ <summary>Expand</summary>
61
+
62
+ **type**: `HTMLTextAreaElement`
63
+ The textarea element replaced by CodeMirror.
64
+
65
+ </details>
66
+
67
+ ## view
68
+
69
+ <details>
70
+ <summary>Expand</summary>
71
+
72
+ **type**: [`EditorView`](https://codemirror.net/6/docs/ref/#view.EditorView)
73
+ The CodeMirror EditorView instance.
74
+
75
+ </details>
76
+
77
+ ## lint
78
+
79
+ <details>
80
+ <summary>Expand</summary>
81
+
82
+ **param**: `(str: string) => Diagnostic[] | Promise<Diagnostic[]>` the linting function
83
+ Set the linting function.
84
+
85
+ ```js
86
+ cm.lint( ( str ) => [
87
+ /**
88
+ * @type {Diagnostic}
89
+ * @see https://codemirror.net/docs/ref/#lint.Diagnostic
90
+ */
91
+ {
92
+ from: 0,
93
+ to: str.length,
94
+ message: 'error message',
95
+ severity: 'error',
96
+ },
97
+ ] );
98
+ ```
99
+
100
+ </details>
101
+
102
+ ## prefer
103
+
104
+ <details>
105
+ <summary>Expand</summary>
106
+
107
+ **param**: `string` the preferred [CodeMirror extensions](https://codemirror.net/docs/extensions/)
108
+ Set the preferred CodeMirror extensions.
109
+
110
+ ```js
111
+ cm.prefer( [
112
+ 'bracketMatching',
113
+ 'closeBrackets',
114
+ 'highlightActiveLine',
115
+ 'highlightSpecialChars',
116
+ 'highlightTrailingWhitespace',
117
+ ] );
118
+ ```
119
+
120
+ </details>
121
+
122
+ ## setIndent
123
+
124
+ <details>
125
+ <summary>Expand</summary>
126
+
127
+ **param**: `string` the indentation string, default as tab
128
+ Set the indentation string.
129
+
130
+ ```js
131
+ cm.setIndent( ' '.repeat( 2 ) );
132
+ ```
133
+
134
+ </details>
135
+
136
+ ## setLanguage
137
+
138
+ <details>
139
+ <summary>Expand</summary>
140
+
141
+ **param**: `string` the language mode to be used, default as plain text
142
+ **param**: `unknown` the optional language configuration
143
+ Set the language mode.
144
+
145
+ ```js
146
+ cm.setLanguage( 'css' );
147
+ ```
148
+
149
+ </details>
150
+
151
+ ## update
152
+
153
+ <details>
154
+ <summary>Expand</summary>
155
+
156
+ Refresh linting immediately.
157
+
158
+ ```js
159
+ cm.update();
160
+ ```
161
+
162
+ </details>
@@ -1,13 +1,10 @@
1
- import { Compartment } from '@codemirror/state';
2
1
  import { EditorView } from '@codemirror/view';
3
2
  import type { Diagnostic } from '@codemirror/lint';
4
3
  export type { MwConfig } from './mediawiki';
5
4
  export declare class CodeMirror6 {
6
- textarea: HTMLTextAreaElement;
7
- language: Compartment;
8
- linter: Compartment;
9
- extensions: Compartment;
10
- view: EditorView;
5
+ #private;
6
+ get textarea(): HTMLTextAreaElement;
7
+ get view(): EditorView;
11
8
  /**
12
9
  * @param textarea 文本框
13
10
  * @param lang 语言
@@ -27,8 +24,8 @@ export declare class CodeMirror6 {
27
24
  lint(lintSource?: (str: string) => Diagnostic[] | Promise<Diagnostic[]>): void;
28
25
  /** 立即更新语法检查 */
29
26
  update(): void;
30
- /** 保存至文本框 */
31
- save(): void;
32
27
  /** 添加扩展 */
33
28
  prefer(names: string[]): void;
29
+ /** 设置缩进 */
30
+ setIndent(indent: string): void;
34
31
  }