@bhsd/codemirror-mediawiki 2.24.1 → 2.24.3

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.
@@ -0,0 +1,15 @@
1
+ import type { ConfigData } from 'wikiparser-node';
2
+ import type { MwConfig } from './token';
3
+ /**
4
+ * 加载CodeMirror的mediawiki模块需要的设置
5
+ * @param modes tagModes
6
+ */
7
+ export type MwConfigGetter = (modes: Record<string, string>) => Promise<MwConfig>;
8
+ export declare const getMwConfig: MwConfigGetter;
9
+ /**
10
+ * 将MwConfig转换为Config
11
+ * @param minConfig 基础Config
12
+ * @param mwConfig
13
+ */
14
+ export type ParserConfigGetter = (minConfig: ConfigData, mwConfig: MwConfig) => ConfigData;
15
+ export declare const getParserConfig: ParserConfigGetter;
package/dist/mwConfig.mjs CHANGED
@@ -22,7 +22,15 @@ var getConfig = (magicWords, rule, flip) => {
22
22
  );
23
23
  };
24
24
  var getParserConfig = (minConfig, mwConfig) => {
25
- const { tags, doubleUnderscore, urlProtocols, functionSynonyms, variableIDs } = mwConfig, [insensitive, sensitive] = functionSynonyms, behaviorSwitch = doubleUnderscore.map(
25
+ const {
26
+ tags,
27
+ doubleUnderscore,
28
+ urlProtocols,
29
+ functionSynonyms,
30
+ variableIDs,
31
+ functionHooks,
32
+ redirection
33
+ } = mwConfig, [insensitive, sensitive] = functionSynonyms, behaviorSwitch = doubleUnderscore.map(
26
34
  (obj, i) => Object.entries(obj).map(([k, v]) => [
27
35
  k.slice(2, -2),
28
36
  i && typeof v === "string" ? v.toUpperCase() : v
@@ -44,7 +52,9 @@ var getParserConfig = (minConfig, mwConfig) => {
44
52
  ...behaviorSwitch.map(Object.fromEntries)
45
53
  ],
46
54
  protocol: urlProtocols.replace(/\|\\?\/\\?\/$|\\(?=[:/])/gu, ""),
47
- ...variableIDs && { variable: [.../* @__PURE__ */ new Set([...variableIDs, "="])] }
55
+ ...variableIDs && { variable: [.../* @__PURE__ */ new Set([...variableIDs, "="])] },
56
+ ...functionHooks && { functionHook: [.../* @__PURE__ */ new Set([...functionHooks.map((s) => s.toLowerCase()), "msgnw"])] },
57
+ ...redirection && { redirection: redirection.map((s) => s.toLowerCase()) }
48
58
  };
49
59
  };
50
60
  var getVariants = (variants) => {
@@ -137,9 +147,9 @@ var getMwConfig = async (modes) => {
137
147
  siprop: [
138
148
  "general",
139
149
  "magicwords",
140
- ...config && !isIPE ? [] : ["extensiontags", "functionhooks"],
141
- ...(config == null ? void 0 : config.variableIDs) && !isIPE ? [] : ["variables"],
142
- ...config && !isIPE && !config.functionHooks ? ["functionhooks"] : []
150
+ ...config && !isIPE ? [] : ["extensiontags"],
151
+ ...(config == null ? void 0 : config.variableIDs) ? [] : ["variables"],
152
+ ...(config == null ? void 0 : config.functionHooks) ? [] : ["functionhooks"]
143
153
  ],
144
154
  formatversion: "2"
145
155
  });
@@ -150,7 +160,7 @@ var getMwConfig = async (modes) => {
150
160
  }
151
161
  } else {
152
162
  const functions = /* @__PURE__ */ new Set([
153
- ...functionhooks,
163
+ ...functionhooks.map((s) => s.toLowerCase()),
154
164
  ...variables,
155
165
  ...others
156
166
  ]);
@@ -170,7 +180,10 @@ var getMwConfig = async (modes) => {
170
180
  urlProtocols: mw.config.get("wgUrlProtocols").replace(/\\:/gu, ":")
171
181
  });
172
182
  (_a2 = config.variableIDs) != null ? _a2 : config.variableIDs = variables;
173
- (_b = config.functionHooks) != null ? _b : config.functionHooks = [...functionhooks, "msgnw"];
183
+ (_b = config.functionHooks) != null ? _b : config.functionHooks = functionhooks.map((s) => s.toLowerCase());
184
+ if (!config.functionHooks.includes("msgnw")) {
185
+ config.functionHooks.push("msgnw");
186
+ }
174
187
  }
175
188
  setConfig(config);
176
189
  ALL_SETTINGS_CACHE[SITE_ID] = { config, time: Date.now() };
@@ -182,14 +195,12 @@ var getParserConfig2 = (minConfig, mwConfig) => {
182
195
  if (config) {
183
196
  return config;
184
197
  }
185
- const { nsid, variants, redirection, functionSynonyms, functionHooks, img } = mwConfig, [insensitive, sensitive] = functionSynonyms;
198
+ const { nsid, variants, functionSynonyms, img } = mwConfig, [insensitive, sensitive] = functionSynonyms;
186
199
  config = {
187
200
  ...getParserConfig(minConfig, mwConfig),
188
201
  namespaces: mw.config.get("wgFormattedNamespaces"),
189
202
  nsid,
190
- variants,
191
- redirection: redirection != null ? redirection : minConfig.redirection,
192
- ...functionHooks && { functionHook: functionHooks }
203
+ variants
193
204
  };
194
205
  if (location.hostname.endsWith(".moegirl.org.cn")) {
195
206
  config.html[2].push("img");
package/dist/token.d.ts CHANGED
@@ -58,10 +58,8 @@ export type ApiSuggestions = [string, string?][];
58
58
  export type ApiSuggest = (search: string, namespace?: number, subpage?: boolean) => ApiSuggestions | Promise<ApiSuggestions>;
59
59
  export interface MwConfig extends MwConfigBase {
60
60
  nsid: Record<string, number>;
61
- functionHooks?: string[];
62
61
  variants?: string[];
63
62
  img?: Record<string, string>;
64
- redirection?: string[];
65
63
  permittedHtmlTags?: string[];
66
64
  implicitlyClosedHtmlTags?: string[];
67
65
  linkSuggest?: ApiSuggest;