@bhsd/codemirror-mediawiki 3.6.2 → 3.6.4
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/fold.d.ts +1 -1
- package/dist/fold.js +15 -2
- package/dist/main.min.js +21 -21
- package/dist/mediawiki.d.ts +5 -0
- package/dist/mediawiki.js +23 -11
- package/dist/mw.min.js +28 -28
- package/dist/theme.js +2 -0
- package/dist/token.js +1 -2
- package/dist/wiki.min.js +28 -28
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +4 -4
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,7 +103,7 @@ 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;
|
|
@@ -157,8 +162,8 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
157
162
|
/** 自动补全魔术字和标签名 */
|
|
158
163
|
get completionSource() {
|
|
159
164
|
return async (context) => {
|
|
160
|
-
const { state, pos, explicit } = context, node = syntaxTree(state).resolve(pos, -1), types = new Set(
|
|
161
|
-
/** 开头不包含` `,但可能包含`_` */ 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;
|
|
162
167
|
let { prevSibling } = node;
|
|
163
168
|
if (explicit || isParserFunction && search.includes('#') || isWMF) {
|
|
164
169
|
const validFor = isWMF ? null : { validFor: /^[^|{}<>[\]#]*$/u };
|
|
@@ -182,16 +187,20 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
182
187
|
}
|
|
183
188
|
const isPage = hasTag(types, 'pageName') && hasTag(types, 'parserFunction') || 0;
|
|
184
189
|
if (isPage && search.trim() || hasTag(types, 'linkPageName')) {
|
|
185
|
-
|
|
190
|
+
const isLink = isWikiLink(n);
|
|
191
|
+
let prefix = '', ns = 0;
|
|
186
192
|
if (isPage) {
|
|
187
|
-
prefix = this.autocompleteNamespaces[[...types].find(
|
|
193
|
+
prefix = this.autocompleteNamespaces[[...types].find(type => type.startsWith('mw-function-'))
|
|
188
194
|
.slice(12)];
|
|
189
195
|
}
|
|
190
|
-
|
|
196
|
+
else if (hasTag(types, 'mw-tag-gallery') && !isLink) {
|
|
197
|
+
ns = 6;
|
|
198
|
+
}
|
|
199
|
+
const suggestions = await this.#linkSuggest(prefix + search, ns);
|
|
191
200
|
if (!suggestions) {
|
|
192
201
|
return null;
|
|
193
202
|
}
|
|
194
|
-
else if (!isPage) {
|
|
203
|
+
else if (!isPage && isLink) {
|
|
195
204
|
suggestions.options = suggestions.options.map((option) => ({ ...option, apply }));
|
|
196
205
|
}
|
|
197
206
|
else if (prefix === 'Module:') {
|
|
@@ -233,7 +242,7 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
233
242
|
({ prevSibling } = prevSibling);
|
|
234
243
|
}
|
|
235
244
|
if (prevSibling && page) {
|
|
236
|
-
const equal = isArgument && state.sliceDoc(pos,
|
|
245
|
+
const equal = isArgument && state.sliceDoc(pos, t).trim() === '=' ? '' : '=', suggestions = await this.#paramSuggest(isDelimiter ? '' : search, page, equal);
|
|
237
246
|
if (suggestions && suggestions.options.length > 0) {
|
|
238
247
|
return {
|
|
239
248
|
from: isDelimiter ? pos : start + suggestions.offset,
|
|
@@ -247,7 +256,7 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
247
256
|
const isTagName = hasTag(types, ['htmlTagName', 'extTagName']), explicitMatch = explicit && context.matchBefore(/\s$/u), validForAttr = /^[a-z]*$/iu;
|
|
248
257
|
if (isTagName && explicitMatch
|
|
249
258
|
|| hasTag(types, ['htmlTagAttribute', 'extTagAttribute', 'tableDefinition'])) {
|
|
250
|
-
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);
|
|
251
260
|
return mt && (mt.from < start || /^\s/u.test(mt.text))
|
|
252
261
|
? {
|
|
253
262
|
from: mt.from + 1,
|
|
@@ -264,7 +273,7 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
264
273
|
: null;
|
|
265
274
|
}
|
|
266
275
|
else if (explicit && hasTag(types, ['tableTd', 'tableTh', 'tableCaption'])) {
|
|
267
|
-
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);
|
|
268
277
|
if (mt && (mt.from < start || /^\s/u.test(mt.text))) {
|
|
269
278
|
return {
|
|
270
279
|
from: mt.from + 1,
|
|
@@ -295,7 +304,7 @@ export class FullMediaWiki extends MediaWiki {
|
|
|
295
304
|
};
|
|
296
305
|
}
|
|
297
306
|
mt = context.matchBefore(/<\/?[a-z\d]*$/iu);
|
|
298
|
-
const extTags = [...types].filter(
|
|
307
|
+
const extTags = [...types].filter(type => type.startsWith('mw-tag-'))
|
|
299
308
|
.map(s => s.slice(7));
|
|
300
309
|
if (mt && (explicit || mt.to - mt.from > 1)) {
|
|
301
310
|
const validFor = /^[a-z\d]*$/iu;
|
|
@@ -491,6 +500,9 @@ const theme = /* @__PURE__ */ EditorView.theme({
|
|
|
491
500
|
[getSelector(['pre', 'nowiki'], 'tag-')]: {
|
|
492
501
|
backgroundColor: 'rgb(0,0,0,.04)',
|
|
493
502
|
},
|
|
503
|
+
'.cm-mw-tag-ref': {
|
|
504
|
+
backgroundColor: 'var(--cm-ref)',
|
|
505
|
+
},
|
|
494
506
|
[`${isolateSelector}, &[dir="rtl"] .cm-mw-template-name`]: {
|
|
495
507
|
unicodeBidi: 'isolate',
|
|
496
508
|
},
|