@bhsd/codemirror-mediawiki 2.22.1 → 2.23.1
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 +2 -1
- package/dist/hover.d.ts +1 -7
- package/dist/linter.d.ts +22 -15
- package/dist/linter.mjs +50 -62
- package/dist/main.min.js +19 -16
- package/dist/mw.min.js +24 -21
- package/dist/mwConfig.mjs +81 -43
- package/dist/static.d.ts +1 -1
- package/dist/token.d.ts +3 -7
- package/dist/wiki.min.js +24 -21
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +8 -7
package/dist/mwConfig.mjs
CHANGED
|
@@ -10,12 +10,64 @@ var compareVersion = (version, baseVersion) => {
|
|
|
10
10
|
return major > baseMajor || major === baseMajor && minor >= baseMinor;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// ../code-standard/dist/cm.mjs
|
|
14
|
+
var otherParserFunctions = /* @__PURE__ */ new Set(["msg", "raw", "subst", "safesubst"]);
|
|
15
|
+
var getConfig = (magicWords, rule, flip) => {
|
|
16
|
+
const words = magicWords.filter(rule);
|
|
17
|
+
return Object.fromEntries(
|
|
18
|
+
(flip === void 0 ? words : words.filter(({ "case-sensitive": i }) => i !== flip)).flatMap(({ aliases, name: n, "case-sensitive": i }) => aliases.map((alias) => ({
|
|
19
|
+
alias: (i ? alias : alias.toLowerCase()).replace(/:$/u, ""),
|
|
20
|
+
name: n
|
|
21
|
+
}))).map(({ alias, name: n }) => [alias, n])
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
var getParserConfig = (minConfig, mwConfig) => {
|
|
25
|
+
const { tags, doubleUnderscore, urlProtocols, functionSynonyms, variableIDs } = mwConfig, [insensitive, sensitive] = functionSynonyms, behaviorSwitch = doubleUnderscore.map(
|
|
26
|
+
(obj, i) => Object.entries(obj).map(([k, v]) => [
|
|
27
|
+
k.slice(2, -2),
|
|
28
|
+
i && typeof v === "string" ? v.toUpperCase() : v
|
|
29
|
+
])
|
|
30
|
+
);
|
|
31
|
+
for (const [k, v] of Object.entries(insensitive)) {
|
|
32
|
+
if (k in sensitive) {
|
|
33
|
+
delete insensitive[k];
|
|
34
|
+
} else {
|
|
35
|
+
insensitive[k] = v.toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
...minConfig,
|
|
40
|
+
ext: Object.keys(tags),
|
|
41
|
+
parserFunction: [{ ...insensitive }, { ...sensitive, "=": "=" }, [], []],
|
|
42
|
+
doubleUnderscore: [
|
|
43
|
+
...behaviorSwitch.map((entries) => entries.map(([k]) => k)),
|
|
44
|
+
...behaviorSwitch.map(Object.fromEntries)
|
|
45
|
+
],
|
|
46
|
+
protocol: urlProtocols.replace(/\|\\?\/\\?\/$|\\(?=[:/])/gu, ""),
|
|
47
|
+
...variableIDs && { variable: [.../* @__PURE__ */ new Set([...variableIDs, "="])] }
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
var getVariants = (variants) => {
|
|
51
|
+
var _a2;
|
|
52
|
+
return (_a2 = variants == null ? void 0 : variants.map(({ code }) => code)) != null ? _a2 : [];
|
|
53
|
+
};
|
|
54
|
+
var getKeywords = (magicwords, web) => ({
|
|
55
|
+
img: Object.fromEntries(
|
|
56
|
+
magicwords.filter(({ name: n }) => n.startsWith("img_") && n !== "img_lossy").flatMap(({ name: n, aliases }) => {
|
|
57
|
+
const k = web ? n : n.slice(4).replace(/_/gu, "-");
|
|
58
|
+
return (n === "img_alt" ? aliases.filter((alias) => alias.includes("$1")) : aliases).map((alias) => [alias, k]);
|
|
59
|
+
})
|
|
60
|
+
),
|
|
61
|
+
redirection: magicwords.find(({ name: n }) => n === "redirect").aliases.map((s) => s.toLowerCase())
|
|
62
|
+
});
|
|
63
|
+
|
|
13
64
|
// src/static.ts
|
|
14
65
|
var getStaticMwConfig = ({
|
|
15
66
|
variable,
|
|
16
67
|
parserFunction: [p0, p1, ...p2],
|
|
17
68
|
protocol,
|
|
18
69
|
nsid,
|
|
70
|
+
functionHook,
|
|
19
71
|
variants,
|
|
20
72
|
redirection,
|
|
21
73
|
ext,
|
|
@@ -28,6 +80,7 @@ var getStaticMwConfig = ({
|
|
|
28
80
|
Object.fromEntries((d2 && d0.length === 0 ? Object.keys(d2) : d0).map((s) => [`__${s}__`, true])),
|
|
29
81
|
Object.fromEntries((d3 && d1.length === 0 ? Object.keys(d3) : d1).map((s) => [`__${s}__`, true]))
|
|
30
82
|
],
|
|
83
|
+
functionHooks: functionHook,
|
|
31
84
|
variableIDs: variable,
|
|
32
85
|
functionSynonyms: [
|
|
33
86
|
{
|
|
@@ -49,18 +102,13 @@ var ALL_SETTINGS_CACHE = (_a = getObject("InPageEditMwConfig")) != null ? _a : {
|
|
|
49
102
|
var SITE_ID = typeof mw === "object" ? mw.config.get("wgServerName") + mw.config.get("wgScriptPath") : location.origin;
|
|
50
103
|
var SITE_SETTINGS = ALL_SETTINGS_CACHE[SITE_ID];
|
|
51
104
|
var VALID = Number(SITE_SETTINGS == null ? void 0 : SITE_SETTINGS.time) > Date.now() - 86400 * 1e3 * 30;
|
|
52
|
-
var
|
|
53
|
-
magicWords.filter(rule).filter(({ "case-sensitive": i }) => i !== flip).flatMap(({ aliases, name, "case-sensitive": i }) => aliases.map((alias) => ({
|
|
54
|
-
alias: (i ? alias : alias.toLowerCase()).replace(/:$/u, ""),
|
|
55
|
-
name
|
|
56
|
-
}))).map(({ alias, name }) => [alias, name])
|
|
57
|
-
);
|
|
105
|
+
var others = /* @__PURE__ */ new Set([...otherParserFunctions, "msgnw"]);
|
|
58
106
|
var getConfigPair = (magicWords, rule) => [true, false].map((bool) => getConfig(magicWords, rule, bool));
|
|
59
107
|
var setConfig = (config) => {
|
|
60
108
|
mw.config.set("extCodeMirrorConfig", config);
|
|
61
109
|
};
|
|
62
110
|
var getMwConfig = async (modes) => {
|
|
63
|
-
var _a2;
|
|
111
|
+
var _a2, _b;
|
|
64
112
|
if (mw.loader.getState("ext.CodeMirror") !== null && !VALID) {
|
|
65
113
|
await mw.loader.using(
|
|
66
114
|
mw.loader.getState("ext.CodeMirror.data") ? "ext.CodeMirror.data" : "ext.CodeMirror"
|
|
@@ -72,7 +120,7 @@ var getMwConfig = async (modes) => {
|
|
|
72
120
|
setConfig(config);
|
|
73
121
|
}
|
|
74
122
|
const isIPE = config && Object.values(config.functionSynonyms[0]).includes(true), nsid = mw.config.get("wgNamespaceIds");
|
|
75
|
-
if ((config == null ? void 0 : config.img) && config.redirection && config.variants && config.variableIDs && !isIPE) {
|
|
123
|
+
if ((config == null ? void 0 : config.img) && config.redirection && config.variants && config.variableIDs && config.functionHooks && !isIPE) {
|
|
76
124
|
config.urlProtocols = config.urlProtocols.replace(/\\:/gu, ":");
|
|
77
125
|
config.tagModes = modes;
|
|
78
126
|
return { ...config, nsid };
|
|
@@ -90,11 +138,11 @@ var getMwConfig = async (modes) => {
|
|
|
90
138
|
"general",
|
|
91
139
|
"magicwords",
|
|
92
140
|
...config && !isIPE ? [] : ["extensiontags", "functionhooks"],
|
|
93
|
-
...(config == null ? void 0 : config.variableIDs) && !isIPE ? [] : ["variables"]
|
|
141
|
+
...(config == null ? void 0 : config.variableIDs) && !isIPE ? [] : ["variables"],
|
|
142
|
+
...config && !isIPE && !config.functionHooks ? ["functionhooks"] : []
|
|
94
143
|
],
|
|
95
144
|
formatversion: "2"
|
|
96
145
|
});
|
|
97
|
-
const others = /* @__PURE__ */ new Set(["msg", "raw", "msgnw", "subst", "safesubst"]);
|
|
98
146
|
if (config && !isIPE) {
|
|
99
147
|
const { functionSynonyms: [insensitive] } = config;
|
|
100
148
|
if (!("subst" in insensitive)) {
|
|
@@ -115,65 +163,55 @@ var getMwConfig = async (modes) => {
|
|
|
115
163
|
)
|
|
116
164
|
};
|
|
117
165
|
}
|
|
118
|
-
config
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
166
|
+
Object.assign(config, {
|
|
167
|
+
...getKeywords(magicwords, true),
|
|
168
|
+
tagModes: modes,
|
|
169
|
+
variants: getVariants(variants),
|
|
170
|
+
urlProtocols: mw.config.get("wgUrlProtocols").replace(/\\:/gu, ":")
|
|
171
|
+
});
|
|
123
172
|
(_a2 = config.variableIDs) != null ? _a2 : config.variableIDs = variables;
|
|
173
|
+
(_b = config.functionHooks) != null ? _b : config.functionHooks = [...functionhooks, "msgnw"];
|
|
124
174
|
}
|
|
125
175
|
setConfig(config);
|
|
126
176
|
ALL_SETTINGS_CACHE[SITE_ID] = { config, time: Date.now() };
|
|
127
177
|
setObject("InPageEditMwConfig", ALL_SETTINGS_CACHE);
|
|
128
178
|
return { ...config, nsid };
|
|
129
179
|
};
|
|
130
|
-
var
|
|
180
|
+
var getParserConfig2 = (minConfig, mwConfig) => {
|
|
131
181
|
let config = getObject("wikilintConfig");
|
|
132
182
|
if (config) {
|
|
133
183
|
return config;
|
|
134
184
|
}
|
|
135
|
-
const {
|
|
136
|
-
tags,
|
|
137
|
-
nsid,
|
|
138
|
-
doubleUnderscore,
|
|
139
|
-
variants,
|
|
140
|
-
urlProtocols,
|
|
141
|
-
redirection,
|
|
142
|
-
functionSynonyms,
|
|
143
|
-
variableIDs,
|
|
144
|
-
img
|
|
145
|
-
} = mwConfig, [insensitive, sensitive] = functionSynonyms;
|
|
185
|
+
const { nsid, variants, redirection, functionSynonyms, functionHooks, img } = mwConfig, [insensitive, sensitive] = functionSynonyms;
|
|
146
186
|
config = {
|
|
147
|
-
...minConfig,
|
|
148
|
-
ext: Object.keys(tags),
|
|
187
|
+
...getParserConfig(minConfig, mwConfig),
|
|
149
188
|
namespaces: mw.config.get("wgFormattedNamespaces"),
|
|
150
189
|
nsid,
|
|
151
|
-
doubleUnderscore: doubleUnderscore.map(
|
|
152
|
-
(obj) => Object.keys(obj).map((s) => s.slice(2, -2))
|
|
153
|
-
),
|
|
154
190
|
variants,
|
|
155
|
-
protocol: urlProtocols.replace(/\|\\?\/\\?\//u, ""),
|
|
156
191
|
redirection: redirection != null ? redirection : minConfig.redirection,
|
|
157
|
-
...
|
|
192
|
+
...functionHooks && { functionHook: functionHooks }
|
|
158
193
|
};
|
|
159
194
|
if (location.hostname.endsWith(".moegirl.org.cn")) {
|
|
160
195
|
config.html[2].push("img");
|
|
161
196
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
197
|
+
const noCM = mw.loader.getState("ext.CodeMirror") === null;
|
|
198
|
+
for (const [key, val] of Object.entries(insensitive)) {
|
|
199
|
+
if (others.has(val) && val !== "msgnw") {
|
|
200
|
+
delete config.parserFunction[0][key];
|
|
201
|
+
config.parserFunction[val === "msg" || val === "raw" ? 2 : 3].push(key);
|
|
202
|
+
} else if (noCM && !key.startsWith("#")) {
|
|
203
|
+
config.parserFunction[0][`#${key}`] = val;
|
|
168
204
|
}
|
|
169
205
|
}
|
|
170
|
-
|
|
206
|
+
if (typeof wikiparse !== "object" || !compareVersion(wikiparse.version, "1.15") || Object.values(sensitive).includes(true)) {
|
|
207
|
+
config.parserFunction[1] = Object.keys(config.parserFunction[1]);
|
|
208
|
+
}
|
|
171
209
|
for (const [key, val] of Object.entries(img)) {
|
|
172
|
-
config.img[key] = val.slice(4);
|
|
210
|
+
config.img[key] = val.slice(4).replace(/_/gu, "-");
|
|
173
211
|
}
|
|
174
212
|
return config;
|
|
175
213
|
};
|
|
176
214
|
export {
|
|
177
215
|
getMwConfig,
|
|
178
|
-
getParserConfig
|
|
216
|
+
getParserConfig2 as getParserConfig
|
|
179
217
|
};
|
package/dist/static.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export declare const tagModes: {
|
|
|
24
24
|
maplink: string;
|
|
25
25
|
graph: string;
|
|
26
26
|
};
|
|
27
|
-
export declare const getStaticMwConfig: ({ variable, parserFunction: [p0, p1, ...p2], protocol, nsid, variants, redirection, ext, doubleUnderscore: [d0, d1, d2, d3], img, }: Config, modes: Record<string, string>) => MwConfig;
|
|
27
|
+
export declare const getStaticMwConfig: ({ variable, parserFunction: [p0, p1, ...p2], protocol, nsid, functionHook, variants, redirection, ext, doubleUnderscore: [d0, d1, d2, d3], img, }: Config, modes: Record<string, string>) => MwConfig;
|
package/dist/token.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Tag } from '@lezer/highlight';
|
|
7
7
|
import { tokens } from './config';
|
|
8
|
+
import type { MwConfig as MwConfigBase } from '@bhsd/common/dist/cm';
|
|
8
9
|
import type { EditorState } from '@codemirror/state';
|
|
9
10
|
import type { StreamParser, StringStream as StringStreamBase } from '@codemirror/language';
|
|
10
11
|
import type { SyntaxNode } from '@lezer/common';
|
|
@@ -52,14 +53,9 @@ export type ApiSuggestions = [string, string?][];
|
|
|
52
53
|
* @param subpage 是否为子页面
|
|
53
54
|
*/
|
|
54
55
|
export type ApiSuggest = (search: string, namespace?: number, subpage?: boolean) => ApiSuggestions | Promise<ApiSuggestions>;
|
|
55
|
-
export interface MwConfig {
|
|
56
|
-
readonly tags: Record<string, true>;
|
|
57
|
-
tagModes: Record<string, string>;
|
|
58
|
-
urlProtocols: string;
|
|
59
|
-
functionSynonyms: [Record<string, string>, Record<string, string>];
|
|
60
|
-
doubleUnderscore: [Record<string, unknown>, Record<string, unknown>];
|
|
56
|
+
export interface MwConfig extends MwConfigBase {
|
|
61
57
|
nsid: Record<string, number>;
|
|
62
|
-
|
|
58
|
+
functionHooks?: string[];
|
|
63
59
|
variants?: string[];
|
|
64
60
|
img?: Record<string, string>;
|
|
65
61
|
redirection?: string[];
|