@bhsd/codemirror-mediawiki 2.0.14 → 2.1.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/dist/codemirror.d.ts +1 -1
- package/dist/config.d.ts +32 -82
- package/dist/main.min.js +23 -2
- package/dist/mediawiki.d.ts +6 -6
- package/mediawiki.css +4 -5
- package/mw/dist/base.js +49 -35
- package/package.json +16 -12
package/dist/mediawiki.d.ts
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { LanguageSupport } from '@codemirror/language';
|
|
7
7
|
export interface MwConfig {
|
|
8
|
-
urlProtocols: string;
|
|
9
|
-
tags: Record<string, true>;
|
|
10
|
-
tagModes: Record<string, string>;
|
|
11
|
-
functionSynonyms: [Record<string, string
|
|
12
|
-
doubleUnderscore: [Record<string,
|
|
8
|
+
readonly urlProtocols: string;
|
|
9
|
+
readonly tags: Record<string, true>;
|
|
10
|
+
readonly tagModes: Record<string, string>;
|
|
11
|
+
functionSynonyms: [Record<string, string>, Record<string, unknown>];
|
|
12
|
+
doubleUnderscore: [Record<string, unknown>, Record<string, unknown>];
|
|
13
13
|
variants?: string[];
|
|
14
|
-
redirect?: string[];
|
|
15
14
|
img?: Record<string, string>;
|
|
15
|
+
nsid: Record<string, number>;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Gets a LanguageSupport instance for the MediaWiki mode.
|
package/mediawiki.css
CHANGED
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
.cm-mw-skipformatting {
|
|
39
39
|
background-color: #adf;
|
|
40
40
|
}
|
|
41
|
-
.cm-mw-indenting,
|
|
42
41
|
.cm-mw-list {
|
|
43
42
|
color: #08f;
|
|
44
43
|
font-weight: bold;
|
|
@@ -54,14 +53,14 @@
|
|
|
54
53
|
color: #84a0a0;
|
|
55
54
|
font-weight: normal;
|
|
56
55
|
}
|
|
56
|
+
.cm-mw-apostrophes,
|
|
57
57
|
.cm-mw-apostrophes-bold,
|
|
58
58
|
.cm-mw-apostrophes-italic {
|
|
59
59
|
color: #08f;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/* template */
|
|
63
|
-
.cm-mw-template
|
|
64
|
-
.cm-mw-template-name-mnemonic {
|
|
63
|
+
.cm-mw-template {
|
|
65
64
|
font-weight: normal;
|
|
66
65
|
}
|
|
67
66
|
.cm-mw-template-name,
|
|
@@ -154,8 +153,8 @@
|
|
|
154
153
|
font-weight: bold;
|
|
155
154
|
}
|
|
156
155
|
|
|
157
|
-
/*
|
|
158
|
-
.cm-mw-
|
|
156
|
+
/* HTML entity */
|
|
157
|
+
.cm-mw-html-entity {
|
|
159
158
|
color: #84a0a0;
|
|
160
159
|
}
|
|
161
160
|
|
package/mw/dist/base.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.0
|
|
1
|
+
import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.0/dist/main.min.js';
|
|
2
2
|
(() => {
|
|
3
3
|
var _a;
|
|
4
|
-
mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.0
|
|
4
|
+
mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.0/mediawiki.min.css', 'text/css');
|
|
5
5
|
const instances = new WeakMap();
|
|
6
6
|
$.valHooks['textarea'] = {
|
|
7
7
|
get(elem) {
|
|
@@ -12,13 +12,13 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
12
12
|
const cm = instances.get(elem);
|
|
13
13
|
if (cm) {
|
|
14
14
|
cm.view.dispatch({
|
|
15
|
-
changes: { from: 0, to: cm.view.state.doc.length, insert: value }
|
|
15
|
+
changes: { from: 0, to: cm.view.state.doc.length, insert: value },
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
19
|
elem.value = value;
|
|
20
20
|
}
|
|
21
|
-
}
|
|
21
|
+
},
|
|
22
22
|
};
|
|
23
23
|
function getCaretPosition(option) {
|
|
24
24
|
const { view: { state: { selection: { main } } } } = instances.get(this[0]);
|
|
@@ -31,7 +31,7 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
31
31
|
setContents(content) {
|
|
32
32
|
const { view } = instances.get(this[0]);
|
|
33
33
|
view.dispatch({
|
|
34
|
-
changes: { from: 0, to: view.state.doc.length, insert: content }
|
|
34
|
+
changes: { from: 0, to: view.state.doc.length, insert: content },
|
|
35
35
|
});
|
|
36
36
|
return this;
|
|
37
37
|
},
|
|
@@ -42,7 +42,7 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
42
42
|
setSelection({ start, end }) {
|
|
43
43
|
const { view } = instances.get(this[0]);
|
|
44
44
|
view.dispatch({
|
|
45
|
-
selection: { anchor: start, head: end !== null && end !== void 0 ? end : start }
|
|
45
|
+
selection: { anchor: start, head: end !== null && end !== void 0 ? end : start },
|
|
46
46
|
});
|
|
47
47
|
view.focus();
|
|
48
48
|
return this;
|
|
@@ -56,14 +56,14 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
56
56
|
scrollToCaretPosition() {
|
|
57
57
|
instances.get(this[0]).view.dispatch({ scrollIntoView: true });
|
|
58
58
|
return this;
|
|
59
|
-
}
|
|
59
|
+
},
|
|
60
60
|
};
|
|
61
61
|
const USING_LOCAL = mw.loader.getState('ext.CodeMirror') !== null, DATA_MODULE = mw.loader.getState('ext.CodeMirror.data') ? 'ext.CodeMirror.data' : 'ext.CodeMirror', ALL_SETTINGS_CACHE = (_a = JSON.parse(localStorage.getItem('InPageEditMwConfig'))) !== null && _a !== void 0 ? _a : {}, SITE_ID = `${mw.config.get('wgServerName')}${mw.config.get('wgScriptPath')}`, SITE_SETTINGS = ALL_SETTINGS_CACHE[SITE_ID], EXPIRED = !(SITE_SETTINGS && SITE_SETTINGS.time > Date.now() - 86400 * 1000 * 30);
|
|
62
|
-
const getAliases = (words) => words.flatMap(({ aliases, name }) => aliases.map(
|
|
62
|
+
const getAliases = (words) => words.flatMap(({ aliases, name }) => aliases.map(alias => ({ alias, name })));
|
|
63
63
|
const getConfig = (aliases) => {
|
|
64
64
|
const config = {};
|
|
65
65
|
for (const { alias, name } of aliases) {
|
|
66
|
-
config[alias.replace(
|
|
66
|
+
config[alias.replace(/:$/u, '')] = name;
|
|
67
67
|
}
|
|
68
68
|
return config;
|
|
69
69
|
};
|
|
@@ -77,13 +77,20 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
77
77
|
mw.config.set('extCodeMirrorConfig', config);
|
|
78
78
|
}
|
|
79
79
|
const isIPE = config && Object.values(config.functionSynonyms[0]).includes(true);
|
|
80
|
-
if (config && config.
|
|
81
|
-
return
|
|
80
|
+
if (config && config.img && config.variants && !isIPE) {
|
|
81
|
+
return {
|
|
82
|
+
...config,
|
|
83
|
+
nsid: mw.config.get('wgNamespaceIds'),
|
|
84
|
+
};
|
|
82
85
|
}
|
|
83
|
-
const { query: { general: { variants }, magicwords, extensiontags, functionhooks, variables } } = await new mw.Api().get({
|
|
86
|
+
const { query: { general: { variants }, magicwords, extensiontags, functionhooks, variables }, } = await new mw.Api().get({
|
|
84
87
|
meta: 'siteinfo',
|
|
85
|
-
siprop:
|
|
86
|
-
|
|
88
|
+
siprop: [
|
|
89
|
+
'general',
|
|
90
|
+
'magicwords',
|
|
91
|
+
...config && !isIPE ? [] : ['extensiontags', 'functionhooks', 'variables'],
|
|
92
|
+
],
|
|
93
|
+
formatversion: '2',
|
|
87
94
|
});
|
|
88
95
|
const otherMagicwords = new Set(['msg', 'raw', 'msgnw', 'subst', 'safesubst']);
|
|
89
96
|
if (config && !isIPE) {
|
|
@@ -91,36 +98,38 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
91
98
|
if (!('subst' in insensitive)) {
|
|
92
99
|
const aliases = getAliases(magicwords.filter(({ name }) => otherMagicwords.has(name)));
|
|
93
100
|
for (const { alias, name } of aliases) {
|
|
94
|
-
insensitive[alias.replace(
|
|
101
|
+
insensitive[alias.replace(/:$/u, '')] = name;
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
}
|
|
98
105
|
else {
|
|
99
106
|
config = {
|
|
100
107
|
tagModes: {
|
|
101
|
-
|
|
102
|
-
nowiki: 'mw-tag-nowiki',
|
|
103
|
-
ref: 'text/mediawiki'
|
|
108
|
+
ref: 'text/mediawiki',
|
|
104
109
|
},
|
|
105
110
|
tags: {},
|
|
106
|
-
urlProtocols: mw.config.get('wgUrlProtocols')
|
|
111
|
+
urlProtocols: mw.config.get('wgUrlProtocols'),
|
|
107
112
|
};
|
|
108
113
|
for (const tag of extensiontags) {
|
|
109
114
|
config.tags[tag.slice(1, -1)] = true;
|
|
110
115
|
}
|
|
111
|
-
const realMagicwords = new Set([
|
|
116
|
+
const realMagicwords = new Set([
|
|
117
|
+
...functionhooks,
|
|
118
|
+
...variables,
|
|
119
|
+
...otherMagicwords,
|
|
120
|
+
]), allMagicwords = magicwords.filter(({ name, aliases }) => aliases.some(alias => /^__.+__$/u.test(alias)) || realMagicwords.has(name)), sensitive = getAliases(allMagicwords.filter(word => word['case-sensitive'])), insensitive = getAliases(allMagicwords.filter(word => !word['case-sensitive'])).map(({ alias, name }) => ({ alias: alias.toLowerCase(), name }));
|
|
112
121
|
config.doubleUnderscore = [
|
|
113
122
|
getConfig(insensitive.filter(({ alias }) => /^__.+__$/u.test(alias))),
|
|
114
|
-
getConfig(sensitive.filter(({ alias }) => /^__.+__$/u.test(alias)))
|
|
123
|
+
getConfig(sensitive.filter(({ alias }) => /^__.+__$/u.test(alias))),
|
|
115
124
|
];
|
|
116
125
|
config.functionSynonyms = [
|
|
117
126
|
getConfig(insensitive.filter(({ alias }) => !/^__.+__|^#$/u.test(alias))),
|
|
118
|
-
getConfig(sensitive.filter(({ alias }) => !/^__.+__|^#$/u.test(alias)))
|
|
127
|
+
getConfig(sensitive.filter(({ alias }) => !/^__.+__|^#$/u.test(alias))),
|
|
119
128
|
];
|
|
120
129
|
}
|
|
121
|
-
config.redirect = magicwords.find(({ name }) => name === 'redirect').aliases;
|
|
122
130
|
config.img = getConfig(getAliases(magicwords.filter(({ name }) => name.startsWith('img_'))));
|
|
123
131
|
config.variants = variants ? variants.map(({ code }) => code) : [];
|
|
132
|
+
config.nsid = mw.config.get('wgNamespaceIds');
|
|
124
133
|
mw.config.set('extCodeMirrorConfig', config);
|
|
125
134
|
ALL_SETTINGS_CACHE[SITE_ID] = { config: config, time: Date.now() };
|
|
126
135
|
localStorage.setItem('InPageEditMwConfig', JSON.stringify(ALL_SETTINGS_CACHE));
|
|
@@ -144,17 +153,22 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
144
153
|
if (!(lang in linters)) {
|
|
145
154
|
linters[lang] = await this.getLinter();
|
|
146
155
|
if (this.lang === 'mediawiki') {
|
|
147
|
-
const mwConfig = await getMwConfig(), config =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
const mwConfig = await getMwConfig(), config = {
|
|
157
|
+
...await wikiparse.getConfig(),
|
|
158
|
+
ext: Object.keys(mwConfig.tags),
|
|
159
|
+
namespaces: mw.config.get('wgFormattedNamespaces'),
|
|
160
|
+
nsid: mw.config.get('wgNamespaceIds'),
|
|
161
|
+
doubleUnderscore: mwConfig.doubleUnderscore.map(obj => Object.keys(obj).map(s => s.slice(2, -2))),
|
|
162
|
+
variants: mwConfig.variants,
|
|
163
|
+
protocol: mwConfig.urlProtocols,
|
|
164
|
+
};
|
|
165
|
+
[config.parserFunction[0]] = mwConfig.functionSynonyms;
|
|
166
|
+
config.parserFunction[1] = [
|
|
167
|
+
...Object.keys(mwConfig.functionSynonyms[1]),
|
|
168
|
+
'=',
|
|
169
|
+
];
|
|
170
|
+
for (const key of Object.keys(mwConfig.img)) {
|
|
171
|
+
config.img[key] = mwConfig.img[key].slice(4);
|
|
158
172
|
}
|
|
159
173
|
wikiparse.setConfig(config);
|
|
160
174
|
}
|
|
@@ -174,7 +188,7 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
174
188
|
if (e.target instanceof HTMLTextAreaElement && (e.ctrlKey || e.metaKey) && !instances.has(e.target)) {
|
|
175
189
|
e.preventDefault();
|
|
176
190
|
await mw.loader.using('oojs-ui-windows');
|
|
177
|
-
const lang = await OO.ui.prompt('Language:') || undefined, cm = await CodeMirror.fromTextArea(e.target, lang);
|
|
191
|
+
const lang = await OO.ui.prompt('Language:') || undefined, cm = await CodeMirror.fromTextArea(e.target, lang === null || lang === void 0 ? void 0 : lang.toLowerCase());
|
|
178
192
|
void cm.defaultLint(true);
|
|
179
193
|
}
|
|
180
194
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-mediawiki",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"url": "git+https://github.com/bhsd-harry/codemirror-mediawiki.git"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build:core": "
|
|
27
|
+
"build:core": "esbuild ./src/codemirror.ts --bundle --minify --target=es2018 --format=esm --outfile=dist/main.min.js; tsc --emitDeclarationOnly; rm dist/gh-page.d.ts",
|
|
28
28
|
"build:mw": "bash build.sh mw/base.ts mw/dist/base.js",
|
|
29
29
|
"build:gh-page": "bash build.sh src/gh-page.ts gh-page.js",
|
|
30
30
|
"build": "npm run build:core && npm run build:mw",
|
|
31
31
|
"lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && eslint --cache .",
|
|
32
32
|
"lint:css": "stylelint *.css",
|
|
33
33
|
"lint": "npm run lint:ts && npm run lint:css",
|
|
34
|
-
"server": "http-server -c-1 --cors &",
|
|
35
|
-
"test": "npm run server; open http://127.0.0.1:8080/index.html",
|
|
34
|
+
"server": "http-server .. -c-1 --cors &",
|
|
35
|
+
"test": "npm run server; open http://127.0.0.1:8080/codemirror-mediawiki/index.html",
|
|
36
36
|
"test:end": "pkill -x http-server"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
@@ -48,20 +48,24 @@
|
|
|
48
48
|
"@codemirror/state": "^6.3.3",
|
|
49
49
|
"@codemirror/view": "^6.22.2",
|
|
50
50
|
"@lezer/highlight": "^1.2.0",
|
|
51
|
+
"@stylistic/eslint-plugin": "^1.5.3",
|
|
52
|
+
"@stylistic/stylelint-plugin": "^2.0.0",
|
|
51
53
|
"@types/jquery": "^3.5.29",
|
|
52
54
|
"@types/oojs-ui": "^0.47.6",
|
|
53
|
-
"
|
|
54
|
-
"eslint": "^
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
56
|
+
"@typescript-eslint/parser": "^6.12.0",
|
|
57
|
+
"esbuild": "^0.19.7",
|
|
58
|
+
"eslint": "^8.56.0",
|
|
55
59
|
"eslint-plugin-es-x": "^7.3.0",
|
|
60
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
56
61
|
"eslint-plugin-promise": "^6.1.1",
|
|
57
62
|
"eslint-plugin-regexp": "^2.1.2",
|
|
58
|
-
"eslint-plugin-unicorn": "^
|
|
63
|
+
"eslint-plugin-unicorn": "^50.0.1",
|
|
59
64
|
"http-server": "^14.1.0",
|
|
60
|
-
"stylelint": "^
|
|
61
|
-
"stylelint-config-recommended": "^
|
|
65
|
+
"stylelint": "^16.1.0",
|
|
66
|
+
"stylelint-config-recommended": "^14.0.0",
|
|
62
67
|
"types-mediawiki": "^1.4.0",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"wikilint": "^2.1.5"
|
|
68
|
+
"typescript": "^5.1.6",
|
|
69
|
+
"wikilint": "^2.3.0"
|
|
66
70
|
}
|
|
67
71
|
}
|