@bhsd/codemirror-mediawiki 2.0.8 → 2.0.9

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