@bhsd/codemirror-mediawiki 2.0.7 → 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 +175 -1
- package/dist/codemirror.d.ts +33 -0
- package/dist/config.d.ts +191 -0
- package/dist/main.min.js +2 -1
- package/dist/main.min.js.LICENSE.txt +5 -0
- package/dist/mediawiki.d.ts +18 -0
- package/dist/plugins.d.ts +3 -0
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,2 +1,176 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki)
|
|
2
|
+
[](https://github.com/bhsd-harry/codemirror-mediawiki/actions/workflows/codeql.yml)
|
|
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
|
+
|
|
1
21
|
# Description
|
|
2
|
-
|
|
22
|
+
|
|
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/).
|
|
24
|
+
|
|
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>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
import type { Diagnostic } from '@codemirror/lint';
|
|
3
|
+
export type { MwConfig } from './mediawiki';
|
|
4
|
+
export declare class CodeMirror6 {
|
|
5
|
+
#private;
|
|
6
|
+
get textarea(): HTMLTextAreaElement;
|
|
7
|
+
get view(): EditorView;
|
|
8
|
+
/**
|
|
9
|
+
* @param textarea 文本框
|
|
10
|
+
* @param lang 语言
|
|
11
|
+
* @param config 语言设置
|
|
12
|
+
*/
|
|
13
|
+
constructor(textarea: HTMLTextAreaElement, lang?: string, config?: unknown);
|
|
14
|
+
/**
|
|
15
|
+
* 设置语言
|
|
16
|
+
* @param lang 语言
|
|
17
|
+
* @param config 语言设置
|
|
18
|
+
*/
|
|
19
|
+
setLanguage(lang?: string, config?: unknown): void;
|
|
20
|
+
/**
|
|
21
|
+
* 开始语法检查
|
|
22
|
+
* @param lintSource 语法检查函数
|
|
23
|
+
*/
|
|
24
|
+
lint(lintSource?: (str: string) => Diagnostic[] | Promise<Diagnostic[]>): void;
|
|
25
|
+
/** 立即更新语法检查 */
|
|
26
|
+
update(): void;
|
|
27
|
+
/** 保存至文本框 */
|
|
28
|
+
save(): void;
|
|
29
|
+
/** 添加扩展 */
|
|
30
|
+
prefer(names: string[]): void;
|
|
31
|
+
/** 设置缩进 */
|
|
32
|
+
setIndent(indent: string): void;
|
|
33
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author MusikAnimal and others
|
|
3
|
+
* @license GPL-2.0-or-later
|
|
4
|
+
* @link https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
|
|
5
|
+
*/
|
|
6
|
+
import { HighlightStyle } from '@codemirror/language';
|
|
7
|
+
import { Tag } from '@lezer/highlight';
|
|
8
|
+
import type { StreamParser } from '@codemirror/language';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for the MediaWiki highlighting mode for CodeMirror.
|
|
11
|
+
* This is a separate class mainly to keep static configuration out of
|
|
12
|
+
* the logic in CodeMirrorModeMediaWiki.
|
|
13
|
+
*/
|
|
14
|
+
export declare const modeConfig: {
|
|
15
|
+
/**
|
|
16
|
+
* All HTML/XML tags permitted in MediaWiki Core.
|
|
17
|
+
*
|
|
18
|
+
* Extensions should use the CodeMirrorTagModes extension attribute to register tags
|
|
19
|
+
* instead of adding them here.
|
|
20
|
+
*
|
|
21
|
+
* @see https://www.mediawiki.org/wiki/Extension:CodeMirror#Extension_integration
|
|
22
|
+
*/
|
|
23
|
+
permittedHtmlTags: {
|
|
24
|
+
b: boolean;
|
|
25
|
+
bdi: boolean;
|
|
26
|
+
del: boolean;
|
|
27
|
+
i: boolean;
|
|
28
|
+
ins: boolean;
|
|
29
|
+
u: boolean;
|
|
30
|
+
font: boolean;
|
|
31
|
+
big: boolean;
|
|
32
|
+
small: boolean;
|
|
33
|
+
sub: boolean;
|
|
34
|
+
sup: boolean;
|
|
35
|
+
h1: boolean;
|
|
36
|
+
h2: boolean;
|
|
37
|
+
h3: boolean;
|
|
38
|
+
h4: boolean;
|
|
39
|
+
h5: boolean;
|
|
40
|
+
h6: boolean;
|
|
41
|
+
cite: boolean;
|
|
42
|
+
code: boolean;
|
|
43
|
+
em: boolean;
|
|
44
|
+
s: boolean;
|
|
45
|
+
strike: boolean;
|
|
46
|
+
strong: boolean;
|
|
47
|
+
tt: boolean;
|
|
48
|
+
var: boolean;
|
|
49
|
+
div: boolean;
|
|
50
|
+
center: boolean;
|
|
51
|
+
blockquote: boolean;
|
|
52
|
+
q: boolean;
|
|
53
|
+
ol: boolean;
|
|
54
|
+
ul: boolean;
|
|
55
|
+
dl: boolean;
|
|
56
|
+
table: boolean;
|
|
57
|
+
caption: boolean;
|
|
58
|
+
pre: boolean;
|
|
59
|
+
ruby: boolean;
|
|
60
|
+
rb: boolean;
|
|
61
|
+
rp: boolean;
|
|
62
|
+
rt: boolean;
|
|
63
|
+
rtc: boolean;
|
|
64
|
+
p: boolean;
|
|
65
|
+
span: boolean;
|
|
66
|
+
abbr: boolean;
|
|
67
|
+
dfn: boolean;
|
|
68
|
+
kbd: boolean;
|
|
69
|
+
samp: boolean;
|
|
70
|
+
data: boolean;
|
|
71
|
+
time: boolean;
|
|
72
|
+
mark: boolean;
|
|
73
|
+
br: boolean;
|
|
74
|
+
wbr: boolean;
|
|
75
|
+
hr: boolean;
|
|
76
|
+
li: boolean;
|
|
77
|
+
dt: boolean;
|
|
78
|
+
dd: boolean;
|
|
79
|
+
td: boolean;
|
|
80
|
+
th: boolean;
|
|
81
|
+
tr: boolean;
|
|
82
|
+
noinclude: boolean;
|
|
83
|
+
includeonly: boolean;
|
|
84
|
+
onlyinclude: boolean;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* HTML tags that are only self-closing.
|
|
88
|
+
*/
|
|
89
|
+
implicitlyClosedHtmlTags: Record<string, true>;
|
|
90
|
+
/**
|
|
91
|
+
* Mapping of MediaWiki-esque token identifiers to a standardized lezer highlighting tag.
|
|
92
|
+
* Values are one of the default highlighting tags. The idea is to use as many default tags as
|
|
93
|
+
* possible so that theming (such as dark mode) can be applied with minimal effort. The
|
|
94
|
+
* semantic meaning of the tag may not really match how it is used, but as per CodeMirror docs,
|
|
95
|
+
* this is fine. It's still better to make use of the standard tags in some way.
|
|
96
|
+
*
|
|
97
|
+
* Once we allow use of other themes, we may want to tweak these values for aesthetic reasons.
|
|
98
|
+
* The values here can freely be changed. The actual CSS class used is defined further down
|
|
99
|
+
* in highlightStyle().
|
|
100
|
+
*
|
|
101
|
+
* @see https://lezer.codemirror.net/docs/ref/#highlight.tags
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
tags: {
|
|
105
|
+
apostrophes: string;
|
|
106
|
+
apostrophesBold: string;
|
|
107
|
+
apostrophesItalic: string;
|
|
108
|
+
comment: string;
|
|
109
|
+
doubleUnderscore: string;
|
|
110
|
+
extLink: string;
|
|
111
|
+
extLinkBracket: string;
|
|
112
|
+
extLinkProtocol: string;
|
|
113
|
+
extLinkText: string;
|
|
114
|
+
hr: string;
|
|
115
|
+
htmlTagAttribute: string;
|
|
116
|
+
htmlTagBracket: string;
|
|
117
|
+
htmlTagName: string;
|
|
118
|
+
extTagAttribute: string;
|
|
119
|
+
extTagBracket: string;
|
|
120
|
+
extTagName: string;
|
|
121
|
+
indenting: string;
|
|
122
|
+
linkBracket: string;
|
|
123
|
+
linkDelimiter: string;
|
|
124
|
+
linkText: string;
|
|
125
|
+
linkToSection: string;
|
|
126
|
+
list: string;
|
|
127
|
+
parserFunction: string;
|
|
128
|
+
parserFunctionBracket: string;
|
|
129
|
+
parserFunctionDelimiter: string;
|
|
130
|
+
parserFunctionName: string;
|
|
131
|
+
sectionHeader: string;
|
|
132
|
+
sectionHeader1: string;
|
|
133
|
+
sectionHeader2: string;
|
|
134
|
+
sectionHeader3: string;
|
|
135
|
+
sectionHeader4: string;
|
|
136
|
+
sectionHeader5: string;
|
|
137
|
+
sectionHeader6: string;
|
|
138
|
+
signature: string;
|
|
139
|
+
tableBracket: string;
|
|
140
|
+
tableDefinition: string;
|
|
141
|
+
tableDelimiter: string;
|
|
142
|
+
template: string;
|
|
143
|
+
templateArgumentName: string;
|
|
144
|
+
templateBracket: string;
|
|
145
|
+
templateDelimiter: string;
|
|
146
|
+
templateName: string;
|
|
147
|
+
templateVariable: string;
|
|
148
|
+
templateVariableBracket: string;
|
|
149
|
+
templateVariableName: string;
|
|
150
|
+
section: string;
|
|
151
|
+
em: string;
|
|
152
|
+
error: string;
|
|
153
|
+
extTag: string;
|
|
154
|
+
extGround: string;
|
|
155
|
+
freeExtLink: string;
|
|
156
|
+
freeExtLinkProtocol: string;
|
|
157
|
+
link: string;
|
|
158
|
+
linkGround: string;
|
|
159
|
+
linkPageName: string;
|
|
160
|
+
mnemonic: string;
|
|
161
|
+
pageName: string;
|
|
162
|
+
skipFormatting: string;
|
|
163
|
+
strong: string;
|
|
164
|
+
tableCaption: string;
|
|
165
|
+
templateGround: string;
|
|
166
|
+
templateExtGround: string;
|
|
167
|
+
templateLinkGround: string;
|
|
168
|
+
templateVariableDelimiter: string;
|
|
169
|
+
template2ExtGround: string;
|
|
170
|
+
template2Ground: string;
|
|
171
|
+
template3ExtGround: string;
|
|
172
|
+
template3Ground: string;
|
|
173
|
+
pre: string;
|
|
174
|
+
nowiki: string;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* These are custom tokens (a.k.a. tags) that aren't mapped to any of the standardized tags.
|
|
178
|
+
* Make sure these are also defined in tags() above.
|
|
179
|
+
*
|
|
180
|
+
* @see https://codemirror.net/docs/ref/#language.StreamParser.tokenTable
|
|
181
|
+
* @see https://lezer.codemirror.net/docs/ref/#highlight.Tag%5Edefine
|
|
182
|
+
*/
|
|
183
|
+
readonly tokenTable: Record<string, Tag>;
|
|
184
|
+
/**
|
|
185
|
+
* This defines the actual CSS class assigned to each tag/token.
|
|
186
|
+
* Keep this in sync and in the same order as tags().
|
|
187
|
+
*
|
|
188
|
+
* @see https://codemirror.net/docs/ref/#language.TagStyle
|
|
189
|
+
*/
|
|
190
|
+
getHighlightStyle(context: StreamParser<unknown>): HighlightStyle;
|
|
191
|
+
};
|