@bhsd/codemirror-mediawiki 3.6.1 → 3.6.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.
- package/README.md +1 -0
- package/dist/escape.js +0 -1
- package/dist/fold.d.ts +1 -1
- package/dist/fold.js +16 -5
- package/dist/linter.d.ts +1 -1
- package/dist/linter.js +2 -3
- package/dist/lua.js +1 -7
- package/dist/main.min.js +26 -26
- package/dist/matchBrackets.js +2 -4
- package/dist/mediawiki.d.ts +5 -0
- package/dist/mediawiki.js +23 -13
- package/dist/mw.min.js +27 -27
- package/dist/statusBar.js +0 -1
- package/dist/theme.js +2 -0
- package/dist/token.js +17 -30
- package/dist/wiki.min.js +27 -27
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +25 -25
package/dist/matchBrackets.js
CHANGED
|
@@ -10,14 +10,12 @@ export const findEnclosingBrackets = (node, pos, brackets) => {
|
|
|
10
10
|
return { start: firstChild, end: lastChild, matched: true };
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
({ parent } = parent);
|
|
13
|
+
({ parent } = parent);
|
|
14
14
|
}
|
|
15
15
|
return undefined;
|
|
16
16
|
};
|
|
17
17
|
export const findEnclosingPlainBrackets = (state, pos, config) => {
|
|
18
|
-
const { brackets, maxScanDistance } = config, re = new RegExp(`[${
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-spread
|
|
20
|
-
[...brackets].filter((_, i) => i % 2).map(c => c === ']' ? String.raw `\]` : c).join('')}]`, 'gu'), str = state.sliceDoc(pos, pos + maxScanDistance);
|
|
18
|
+
const { brackets, maxScanDistance } = config, re = new RegExp(`[${[...brackets].filter((_, i) => i % 2).map(c => c === ']' ? String.raw `\]` : c).join('')}]`, 'gu'), str = state.sliceDoc(pos, pos + maxScanDistance);
|
|
21
19
|
let mt = re.exec(str);
|
|
22
20
|
while (mt) {
|
|
23
21
|
const result = matchBrackets(state, pos + mt.index + 1, -1, config), left = result?.end?.to;
|
package/dist/mediawiki.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ import { MediaWiki } from './token';
|
|
|
8
8
|
import type { StreamParser, TagStyle } from '@codemirror/language';
|
|
9
9
|
import type { CompletionSource, Completion } from '@codemirror/autocomplete';
|
|
10
10
|
import type { MwConfig } from './token';
|
|
11
|
+
/**
|
|
12
|
+
* 是否是普通维基链接
|
|
13
|
+
* @param name 节点名称
|
|
14
|
+
*/
|
|
15
|
+
export declare const isWikiLink: (name: string) => boolean;
|
|
11
16
|
export declare class FullMediaWiki extends MediaWiki {
|
|
12
17
|
#private;
|
|
13
18
|
readonly nsRegex: RegExp;
|
package/dist/mediawiki.js
CHANGED
|
@@ -12,6 +12,11 @@ import { isolateSelector, ltrSelector, isWMF } from './constants';
|
|
|
12
12
|
import { MediaWiki } from './token';
|
|
13
13
|
import { braceStackUpdate, hasTag } from './util';
|
|
14
14
|
import { EditorView } from '@codemirror/view';
|
|
15
|
+
/**
|
|
16
|
+
* 是否是普通维基链接
|
|
17
|
+
* @param name 节点名称
|
|
18
|
+
*/
|
|
19
|
+
export const isWikiLink = (name) => /mw-[\w-]*link-ground/u.test(name);
|
|
15
20
|
/**
|
|
16
21
|
* 检查首字母大小写并插入正确的自动填充内容
|
|
17
22
|
* @param view
|
|
@@ -98,13 +103,12 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
98
103
|
* @param str 搜索字符串,开头不包含` `,但可能包含`_`
|
|
99
104
|
* @param ns 命名空间
|
|
100
105
|
*/
|
|
101
|
-
async #linkSuggest(str, ns
|
|
106
|
+
async #linkSuggest(str, ns) {
|
|
102
107
|
const { config: { linkSuggest, nsid }, nsRegex } = this;
|
|
103
108
|
if (typeof linkSuggest !== 'function' || /[|{}<>[\]#]/u.test(str)) {
|
|
104
109
|
return undefined;
|
|
105
110
|
}
|
|
106
111
|
let subpage = false, search = str, offset = 0;
|
|
107
|
-
/* eslint-disable no-param-reassign */
|
|
108
112
|
if (search.startsWith('/')) {
|
|
109
113
|
ns = 0;
|
|
110
114
|
subpage = true;
|
|
@@ -131,7 +135,6 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
131
135
|
search = `${ns === -2 ? 'File' : prefix}:${search.slice(length)}`;
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
|
-
/* eslint-enable no-param-reassign */
|
|
135
138
|
const underscore = str.slice(offset).includes('_');
|
|
136
139
|
return {
|
|
137
140
|
offset,
|
|
@@ -159,8 +162,8 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
159
162
|
/** 自动补全魔术字和标签名 */
|
|
160
163
|
get completionSource() {
|
|
161
164
|
return async (context) => {
|
|
162
|
-
const { state, pos, explicit } = context, node = syntaxTree(state).resolve(pos, -1), types = new Set(
|
|
163
|
-
/** 开头不包含` `,但可能包含`_` */ search = state.sliceDoc(
|
|
165
|
+
const { state, pos, explicit } = context, node = syntaxTree(state).resolve(pos, -1), { name: n, from: f, to: t } = node, types = new Set(n.split('_')), isParserFunction = hasTag(types, 'parserFunctionName'),
|
|
166
|
+
/** 开头不包含` `,但可能包含`_` */ search = state.sliceDoc(f, pos).trimStart(), start = pos - search.length;
|
|
164
167
|
let { prevSibling } = node;
|
|
165
168
|
if (explicit || isParserFunction && search.includes('#') || isWMF) {
|
|
166
169
|
const validFor = isWMF ? null : { validFor: /^[^|{}<>[\]#]*$/u };
|
|
@@ -184,16 +187,20 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
184
187
|
}
|
|
185
188
|
const isPage = hasTag(types, 'pageName') && hasTag(types, 'parserFunction') || 0;
|
|
186
189
|
if (isPage && search.trim() || hasTag(types, 'linkPageName')) {
|
|
187
|
-
|
|
190
|
+
const isLink = isWikiLink(n);
|
|
191
|
+
let prefix = '', ns = 0;
|
|
188
192
|
if (isPage) {
|
|
189
|
-
prefix = this.autocompleteNamespaces[[...types].find(
|
|
193
|
+
prefix = this.autocompleteNamespaces[[...types].find(type => type.startsWith('mw-function-'))
|
|
190
194
|
.slice(12)];
|
|
191
195
|
}
|
|
192
|
-
|
|
196
|
+
else if (hasTag(types, 'mw-tag-gallery') && !isLink) {
|
|
197
|
+
ns = 6;
|
|
198
|
+
}
|
|
199
|
+
const suggestions = await this.#linkSuggest(prefix + search, ns);
|
|
193
200
|
if (!suggestions) {
|
|
194
201
|
return null;
|
|
195
202
|
}
|
|
196
|
-
else if (!isPage) {
|
|
203
|
+
else if (!isPage && isLink) {
|
|
197
204
|
suggestions.options = suggestions.options.map((option) => ({ ...option, apply }));
|
|
198
205
|
}
|
|
199
206
|
else if (prefix === 'Module:') {
|
|
@@ -235,7 +242,7 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
235
242
|
({ prevSibling } = prevSibling);
|
|
236
243
|
}
|
|
237
244
|
if (prevSibling && page) {
|
|
238
|
-
const equal = isArgument && state.sliceDoc(pos,
|
|
245
|
+
const equal = isArgument && state.sliceDoc(pos, t).trim() === '=' ? '' : '=', suggestions = await this.#paramSuggest(isDelimiter ? '' : search, page, equal);
|
|
239
246
|
if (suggestions && suggestions.options.length > 0) {
|
|
240
247
|
return {
|
|
241
248
|
from: isDelimiter ? pos : start + suggestions.offset,
|
|
@@ -249,7 +256,7 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
249
256
|
const isTagName = hasTag(types, ['htmlTagName', 'extTagName']), explicitMatch = explicit && context.matchBefore(/\s$/u), validForAttr = /^[a-z]*$/iu;
|
|
250
257
|
if (isTagName && explicitMatch
|
|
251
258
|
|| hasTag(types, ['htmlTagAttribute', 'extTagAttribute', 'tableDefinition'])) {
|
|
252
|
-
const tagName = isTagName ? search.trim() : /mw-(?:ext|html)-([a-z]+)/u.exec(
|
|
259
|
+
const tagName = isTagName ? search.trim() : /mw-(?:ext|html)-([a-z]+)/u.exec(n)[1], mt = explicitMatch || context.matchBefore(hasTag(types, 'tableDefinition') ? /[\s|-][a-z]+$/iu : /\s[a-z]+$/iu);
|
|
253
260
|
return mt && (mt.from < start || /^\s/u.test(mt.text))
|
|
254
261
|
? {
|
|
255
262
|
from: mt.from + 1,
|
|
@@ -266,7 +273,7 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
266
273
|
: null;
|
|
267
274
|
}
|
|
268
275
|
else if (explicit && hasTag(types, ['tableTd', 'tableTh', 'tableCaption'])) {
|
|
269
|
-
const [, tagName] = /mw-table-([a-z]+)/u.exec(
|
|
276
|
+
const [, tagName] = /mw-table-([a-z]+)/u.exec(n), mt = context.matchBefore(/[\s|!+][a-z]*$/iu);
|
|
270
277
|
if (mt && (mt.from < start || /^\s/u.test(mt.text))) {
|
|
271
278
|
return {
|
|
272
279
|
from: mt.from + 1,
|
|
@@ -297,7 +304,7 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
297
304
|
};
|
|
298
305
|
}
|
|
299
306
|
mt = context.matchBefore(/<\/?[a-z\d]*$/iu);
|
|
300
|
-
const extTags = [...types].filter(
|
|
307
|
+
const extTags = [...types].filter(type => type.startsWith('mw-tag-'))
|
|
301
308
|
.map(s => s.slice(7));
|
|
302
309
|
if (mt && (explicit || mt.to - mt.from > 1)) {
|
|
303
310
|
const validFor = /^[a-z\d]*$/iu;
|
|
@@ -493,6 +500,9 @@ const theme = /* @__PURE__ */ EditorView.theme({
|
|
|
493
500
|
[getSelector(['pre', 'nowiki'], 'tag-')]: {
|
|
494
501
|
backgroundColor: 'rgb(0,0,0,.04)',
|
|
495
502
|
},
|
|
503
|
+
'.cm-mw-tag-ref': {
|
|
504
|
+
backgroundColor: 'var(--cm-ref)',
|
|
505
|
+
},
|
|
496
506
|
[`${isolateSelector}, &[dir="rtl"] .cm-mw-template-name`]: {
|
|
497
507
|
unicodeBidi: 'isolate',
|
|
498
508
|
},
|