@bhsd/codemirror-mediawiki 2.19.9 → 2.20.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/mwConfig.mjs CHANGED
@@ -11,27 +11,29 @@ var setObject = (key, value) => {
11
11
 
12
12
  // src/static.ts
13
13
  var getStaticMwConfig = ({
14
+ variable,
14
15
  parserFunction: [p0, p1, ...p2],
15
16
  protocol,
16
17
  nsid,
17
18
  variants,
18
19
  redirection,
19
20
  ext,
20
- doubleUnderscore: [d0, d1, d2],
21
+ doubleUnderscore: [d0, d1, d2, d3],
21
22
  img
22
23
  }, modes) => ({
23
24
  tags: Object.fromEntries(ext.map((s) => [s, true])),
24
25
  tagModes: modes,
25
26
  doubleUnderscore: [
26
27
  Object.fromEntries((d2 && d0.length === 0 ? Object.keys(d2) : d0).map((s) => [`__${s}__`, true])),
27
- Object.fromEntries(d1.map((s) => [`__${s}__`, true]))
28
+ Object.fromEntries((d3 && d1.length === 0 ? Object.keys(d3) : d1).map((s) => [`__${s}__`, true]))
28
29
  ],
30
+ variableIDs: variable,
29
31
  functionSynonyms: [
30
32
  {
31
33
  ...p0,
32
34
  ...Object.fromEntries(p2.flat().map((s) => [s, s]))
33
35
  },
34
- Object.fromEntries(p1.map((s) => [s, true]))
36
+ Array.isArray(p1) ? Object.fromEntries(p1.map((s) => [s, s.toLowerCase()])) : { ...p1 }
35
37
  ],
36
38
  urlProtocols: `${protocol}|//`,
37
39
  nsid,
@@ -57,6 +59,7 @@ var setConfig = (config) => {
57
59
  mw.config.set("extCodeMirrorConfig", config);
58
60
  };
59
61
  var getMwConfig = async (modes) => {
62
+ var _a2;
60
63
  if (mw.loader.getState("ext.CodeMirror") !== null && !VALID) {
61
64
  await mw.loader.using(mw.loader.getState("ext.CodeMirror.data") ? "ext.CodeMirror.data" : "ext.CodeMirror");
62
65
  }
@@ -66,13 +69,13 @@ var getMwConfig = async (modes) => {
66
69
  setConfig(config);
67
70
  }
68
71
  const isIPE = config && Object.values(config.functionSynonyms[0]).includes(true), nsid = mw.config.get("wgNamespaceIds");
69
- if ((config == null ? void 0 : config.img) && config.redirection && config.variants && !isIPE) {
72
+ if ((config == null ? void 0 : config.img) && config.redirection && config.variants && config.variableIDs && !isIPE) {
70
73
  config.urlProtocols = config.urlProtocols.replace(/\\:/gu, ":");
71
74
  config.tagModes = modes;
72
75
  return { ...config, nsid };
73
76
  } else if (location.hostname.endsWith(".moegirl.org.cn")) {
74
77
  const parserConfig = await (await fetch(
75
- `${CDN}/npm/wikiparser-node@browser/config/moegirl.json`
78
+ `${CDN}/npm/wikiparser-node/config/moegirl.json`
76
79
  )).json();
77
80
  setObject("wikilintConfig", parserConfig);
78
81
  config = getStaticMwConfig(parserConfig, modes);
@@ -83,7 +86,8 @@ var getMwConfig = async (modes) => {
83
86
  siprop: [
84
87
  "general",
85
88
  "magicwords",
86
- ...config && !isIPE ? [] : ["extensiontags", "functionhooks", "variables"]
89
+ ...config && !isIPE ? [] : ["extensiontags", "functionhooks"],
90
+ ...(config == null ? void 0 : config.variableIDs) && !isIPE ? [] : ["variables"]
87
91
  ],
88
92
  formatversion: "2"
89
93
  });
@@ -113,6 +117,7 @@ var getMwConfig = async (modes) => {
113
117
  config.variants = variants ? variants.map(({ code }) => code) : [];
114
118
  config.redirection = magicwords.find(({ name }) => name === "redirect").aliases;
115
119
  config.urlProtocols = mw.config.get("wgUrlProtocols").replace(/\\:/gu, ":");
120
+ (_a2 = config.variableIDs) != null ? _a2 : config.variableIDs = variables;
116
121
  }
117
122
  setConfig(config);
118
123
  ALL_SETTINGS_CACHE[SITE_ID] = { config, time: Date.now() };
@@ -120,39 +125,36 @@ var getMwConfig = async (modes) => {
120
125
  return { ...config, nsid };
121
126
  };
122
127
  var getParserConfig = (minConfig, mwConfig) => {
123
- var _a2;
124
128
  let config = getObject("wikilintConfig");
125
129
  if (config) {
126
130
  return config;
127
131
  }
132
+ const { tags, nsid, doubleUnderscore, variants, urlProtocols, redirection, functionSynonyms, img } = mwConfig, [insensitive, sensitive] = functionSynonyms;
128
133
  config = {
129
134
  ...minConfig,
130
- ext: Object.keys(mwConfig.tags),
135
+ ext: Object.keys(tags),
131
136
  namespaces: mw.config.get("wgFormattedNamespaces"),
132
- nsid: mwConfig.nsid,
133
- doubleUnderscore: mwConfig.doubleUnderscore.map(
137
+ nsid,
138
+ doubleUnderscore: doubleUnderscore.map(
134
139
  (obj) => Object.keys(obj).map((s) => s.slice(2, -2))
135
140
  ),
136
- variants: mwConfig.variants,
137
- protocol: mwConfig.urlProtocols.replace(/\|\\?\/\\?\//u, ""),
138
- redirection: (_a2 = mwConfig.redirection) != null ? _a2 : minConfig.redirection
141
+ variants,
142
+ protocol: urlProtocols.replace(/\|\\?\/\\?\//u, ""),
143
+ redirection: redirection != null ? redirection : minConfig.redirection
139
144
  };
140
145
  if (location.hostname.endsWith(".moegirl.org.cn")) {
141
146
  config.html[2].push("img");
142
147
  }
143
- [config.parserFunction[0]] = mwConfig.functionSynonyms;
148
+ config.parserFunction[0] = insensitive;
144
149
  if (mw.loader.getState("ext.CodeMirror") === null) {
145
- for (const [key, val] of Object.entries(mwConfig.functionSynonyms[0])) {
150
+ for (const [key, val] of Object.entries(insensitive)) {
146
151
  if (!key.startsWith("#")) {
147
152
  config.parserFunction[0][`#${key}`] = val;
148
153
  }
149
154
  }
150
155
  }
151
- config.parserFunction[1] = [
152
- ...Object.keys(mwConfig.functionSynonyms[1]),
153
- "="
154
- ];
155
- for (const [key, val] of Object.entries(mwConfig.img)) {
156
+ config.parserFunction[1] = Object.values(sensitive).includes(true) ? [...Object.keys(sensitive), "="] : { ...sensitive, "=": "=" };
157
+ for (const [key, val] of Object.entries(img)) {
156
158
  config.img[key] = val.slice(4);
157
159
  }
158
160
  return config;
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: ({ parserFunction: [p0, p1, ...p2], protocol, nsid, variants, redirection, ext, doubleUnderscore: [d0, d1, d2], img, }: Config, modes: Record<string, string>) => MwConfig;
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;
package/dist/token.d.ts CHANGED
@@ -56,9 +56,10 @@ export interface MwConfig {
56
56
  readonly tags: Record<string, true>;
57
57
  tagModes: Record<string, string>;
58
58
  urlProtocols: string;
59
- functionSynonyms: [Record<string, string>, Record<string, unknown>];
59
+ functionSynonyms: [Record<string, string>, Record<string, string>];
60
60
  doubleUnderscore: [Record<string, unknown>, Record<string, unknown>];
61
61
  nsid: Record<string, number>;
62
+ variableIDs?: string[];
62
63
  variants?: string[];
63
64
  img?: Record<string, string>;
64
65
  redirection?: string[];