@bhsd/codemirror-mediawiki 2.19.10 → 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/i18n/en.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.19.10",
2
+ "version": "2.20.0",
3
3
  "lang": "en",
4
4
  "i18n-failed": "Failed to fetch the translation file in $1.",
5
5
  "title": "CodeMirror Addons",
package/i18n/zh-hans.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.19.10",
2
+ "version": "2.20.0",
3
3
  "lang": "zh-hans",
4
4
  "i18n-failed": "获取 $1 的语言文件失败。",
5
5
  "title": "CodeMirror插件",
package/i18n/zh-hant.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.19.10",
2
+ "version": "2.20.0",
3
3
  "lang": "zh-hant",
4
4
  "i18n-failed": "取得 $1 的語言檔案失敗。",
5
5
  "title": "CodeMirror外掛程式",
package/mediawiki.css CHANGED
@@ -1,6 +1,9 @@
1
1
  .cm-editor {
2
2
  background-color: #fff;
3
3
  }
4
+ .cm-editor .cm-lineNumbers .cm-gutterElement {
5
+ text-align: end;
6
+ }
4
7
  .cm-panel .cm-textfield,
5
8
  .cm-panel .cm-button,
6
9
  .cm-panels > .cm-search.cm-panel label,
package/mw/config.ts CHANGED
@@ -67,13 +67,13 @@ export const getMwConfig = async (modes: Record<string, string>): Promise<MwConf
67
67
  const isIPE = config && Object.values(config.functionSynonyms[0]).includes(true as unknown as string),
68
68
  nsid = mw.config.get('wgNamespaceIds');
69
69
  // 情形1:config已更新,可能来自localStorage
70
- if (config?.img && config.redirection && config.variants && !isIPE) {
70
+ if (config?.img && config.redirection && config.variants && config.variableIDs && !isIPE) {
71
71
  config.urlProtocols = config.urlProtocols.replace(/\\:/gu, ':');
72
72
  config.tagModes = modes;
73
73
  return {...config, nsid};
74
74
  } else if (location.hostname.endsWith('.moegirl.org.cn')) {
75
75
  const parserConfig: Config = await (await fetch(
76
- `${CDN}/npm/wikiparser-node@browser/config/moegirl.json`,
76
+ `${CDN}/npm/wikiparser-node/config/moegirl.json`,
77
77
  )).json();
78
78
  setObject('wikilintConfig', parserConfig);
79
79
  config = getStaticMwConfig(parserConfig, modes);
@@ -96,7 +96,8 @@ export const getMwConfig = async (modes: Record<string, string>): Promise<MwConf
96
96
  siprop: [
97
97
  'general',
98
98
  'magicwords',
99
- ...config && !isIPE ? [] : ['extensiontags', 'functionhooks', 'variables'],
99
+ ...config && !isIPE ? [] : ['extensiontags', 'functionhooks'],
100
+ ...config?.variableIDs && !isIPE ? [] : ['variables'],
100
101
  ],
101
102
  formatversion: '2',
102
103
  }) as any; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -129,6 +130,7 @@ export const getMwConfig = async (modes: Record<string, string>): Promise<MwConf
129
130
  config!.variants = variants ? variants.map(({code}) => code) : [];
130
131
  config!.redirection = magicwords.find(({name}) => name === 'redirect')!.aliases;
131
132
  config!.urlProtocols = mw.config.get('wgUrlProtocols').replace(/\\:/gu, ':');
133
+ config!.variableIDs ??= variables;
132
134
  }
133
135
  setConfig(config!);
134
136
  ALL_SETTINGS_CACHE[SITE_ID] = {config: config!, time: Date.now()};
@@ -146,34 +148,35 @@ export const getParserConfig = (minConfig: Config, mwConfig: MwConfig): Config =
146
148
  if (config) {
147
149
  return config;
148
150
  }
151
+ const {tags, nsid, doubleUnderscore, variants, urlProtocols, redirection, functionSynonyms, img} = mwConfig,
152
+ [insensitive, sensitive] = functionSynonyms;
149
153
  config = {
150
154
  ...minConfig,
151
- ext: Object.keys(mwConfig.tags),
155
+ ext: Object.keys(tags),
152
156
  namespaces: mw.config.get('wgFormattedNamespaces'),
153
- nsid: mwConfig.nsid,
154
- doubleUnderscore: mwConfig.doubleUnderscore.map(
157
+ nsid,
158
+ doubleUnderscore: doubleUnderscore.map(
155
159
  obj => Object.keys(obj).map(s => s.slice(2, -2)),
156
160
  ) as [string[], string[]],
157
- variants: mwConfig.variants!,
158
- protocol: mwConfig.urlProtocols.replace(/\|\\?\/\\?\//u, ''),
159
- redirection: mwConfig.redirection ?? minConfig.redirection,
161
+ variants: variants!,
162
+ protocol: urlProtocols.replace(/\|\\?\/\\?\//u, ''),
163
+ redirection: redirection ?? minConfig.redirection,
160
164
  };
161
165
  if (location.hostname.endsWith('.moegirl.org.cn')) {
162
166
  config.html[2].push('img');
163
167
  }
164
- [config.parserFunction[0]] = mwConfig.functionSynonyms;
168
+ config.parserFunction[0] = insensitive;
165
169
  if (mw.loader.getState('ext.CodeMirror') === null) {
166
- for (const [key, val] of Object.entries(mwConfig.functionSynonyms[0])) {
170
+ for (const [key, val] of Object.entries(insensitive)) {
167
171
  if (!key.startsWith('#')) {
168
172
  config.parserFunction[0][`#${key}`] = val;
169
173
  }
170
174
  }
171
175
  }
172
- config.parserFunction[1] = [
173
- ...Object.keys(mwConfig.functionSynonyms[1]),
174
- '=',
175
- ];
176
- for (const [key, val] of Object.entries(mwConfig.img!)) {
176
+ config.parserFunction[1] = Object.values(sensitive as Record<string, unknown>).includes(true)
177
+ ? [...Object.keys(sensitive), '=']
178
+ : {...sensitive, '=': '='};
179
+ for (const [key, val] of Object.entries(img!)) {
177
180
  config.img[key] = val.slice(4);
178
181
  }
179
182
  return config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/codemirror-mediawiki",
3
- "version": "2.19.10",
3
+ "version": "2.20.0",
4
4
  "description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -56,7 +56,7 @@
56
56
  "@codemirror/view": "^6.35.0",
57
57
  "@lezer/common": "^1.2.3",
58
58
  "style-mod": "^4.1.0",
59
- "wikiparser-node": "^1.14.1"
59
+ "wikiparser-node": "^1.15.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@codemirror/autocomplete": "^6.18.3",
package/src/linter.ts CHANGED
@@ -12,7 +12,7 @@ declare type getAsyncLinter<T> = (opt?: Record<string, unknown>) => Promise<T>;
12
12
  * @param opt 选项
13
13
  */
14
14
  export const getWikiLinter: getAsyncLinter<LinterBase> = async opt => {
15
- const REPO = 'npm/wikiparser-node@browser',
15
+ const REPO = 'npm/wikiparser-node',
16
16
  DIR = `${REPO}/extensions/dist`,
17
17
  lang = opt?.['i18n'];
18
18
  await loadScript(`${DIR}/base.min.js`, 'wikiparse');
package/src/static.ts CHANGED
@@ -28,13 +28,14 @@ export const tagModes = {
28
28
 
29
29
  export const getStaticMwConfig = (
30
30
  {
31
+ variable,
31
32
  parserFunction: [p0, p1, ...p2],
32
33
  protocol,
33
34
  nsid,
34
35
  variants,
35
36
  redirection,
36
37
  ext,
37
- doubleUnderscore: [d0, d1, d2],
38
+ doubleUnderscore: [d0, d1, d2, d3],
38
39
  img,
39
40
  }: Config,
40
41
  modes: Record<string, string>,
@@ -43,14 +44,15 @@ export const getStaticMwConfig = (
43
44
  tagModes: modes,
44
45
  doubleUnderscore: [
45
46
  Object.fromEntries((d2 && d0.length === 0 ? Object.keys(d2) : d0).map(s => [`__${s}__`, true])),
46
- Object.fromEntries(d1.map(s => [`__${s}__`, true])),
47
+ Object.fromEntries((d3 && d1.length === 0 ? Object.keys(d3) : d1).map(s => [`__${s}__`, true])),
47
48
  ],
49
+ variableIDs: variable,
48
50
  functionSynonyms: [
49
51
  {
50
52
  ...p0,
51
53
  ...Object.fromEntries(p2.flat().map(s => [s, s])),
52
54
  },
53
- Object.fromEntries(p1.map(s => [s, true])),
55
+ Array.isArray(p1) ? Object.fromEntries(p1.map(s => [s, s.toLowerCase()])) : {...p1},
54
56
  ],
55
57
  urlProtocols: `${protocol}|//`,
56
58
  nsid,