wikiparser-node 1.16.4 → 1.16.6
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 -1
- package/bundle/bundle.es7.js +27 -27
- package/bundle/bundle.lsp.js +30 -30
- package/bundle/bundle.min.js +29 -29
- package/dist/addon/table.js +7 -4
- package/dist/addon/token.js +13 -7
- package/dist/addon/transclude.js +7 -5
- package/dist/base.d.mts +99 -30
- package/dist/base.d.ts +99 -30
- package/dist/index.d.ts +10 -4
- package/dist/index.js +59 -14
- package/dist/lib/attributes.js +2 -2
- package/dist/lib/element.d.ts +96 -42
- package/dist/lib/element.js +98 -45
- package/dist/lib/lsp.d.ts +64 -35
- package/dist/lib/lsp.js +208 -159
- package/dist/lib/node.d.ts +122 -53
- package/dist/lib/node.js +172 -75
- package/dist/lib/range.d.ts +83 -31
- package/dist/lib/range.js +83 -31
- package/dist/lib/ranges.d.ts +1 -1
- package/dist/lib/ranges.js +3 -2
- package/dist/lib/text.d.ts +40 -14
- package/dist/lib/text.js +47 -19
- package/dist/lib/title.d.ts +50 -16
- package/dist/lib/title.js +77 -36
- package/dist/mixin/attributesParent.d.ts +37 -21
- package/dist/mixin/attributesParent.js +0 -2
- package/dist/mixin/flagsParent.d.ts +38 -12
- package/dist/mixin/hidden.d.ts +0 -2
- package/dist/mixin/hidden.js +0 -2
- package/dist/mixin/magicLinkParent.d.ts +11 -5
- package/dist/mixin/singleLine.d.ts +0 -2
- package/dist/mixin/singleLine.js +3 -3
- package/dist/mixin/sol.d.ts +0 -2
- package/dist/mixin/sol.js +2 -3
- package/dist/mixin/syntax.d.ts +0 -2
- package/dist/mixin/syntax.js +0 -2
- package/dist/parser/braces.js +52 -20
- package/dist/parser/commentAndExt.js +19 -6
- package/dist/parser/links.js +13 -7
- package/dist/parser/list.js +3 -1
- package/dist/parser/quotes.js +22 -2
- package/dist/parser/redirect.js +4 -1
- package/dist/src/arg.d.ts +19 -9
- package/dist/src/arg.js +34 -15
- package/dist/src/atom.d.ts +5 -1
- package/dist/src/atom.js +5 -1
- package/dist/src/attribute.d.ts +26 -8
- package/dist/src/attribute.js +30 -11
- package/dist/src/attributes.d.ts +50 -22
- package/dist/src/attributes.js +54 -26
- package/dist/src/converter.d.ts +4 -2
- package/dist/src/converter.js +12 -9
- package/dist/src/converterFlags.d.ts +45 -15
- package/dist/src/converterFlags.js +45 -15
- package/dist/src/converterRule.d.ts +30 -11
- package/dist/src/converterRule.js +46 -16
- package/dist/src/extLink.d.ts +6 -2
- package/dist/src/extLink.js +14 -11
- package/dist/src/gallery.d.ts +13 -9
- package/dist/src/gallery.js +35 -21
- package/dist/src/heading.d.ts +13 -7
- package/dist/src/heading.js +21 -11
- package/dist/src/hidden.d.ts +5 -1
- package/dist/src/hidden.js +7 -3
- package/dist/src/html.d.ts +11 -5
- package/dist/src/html.js +16 -7
- package/dist/src/imageParameter.d.ts +23 -11
- package/dist/src/imageParameter.js +22 -10
- package/dist/src/imagemap.d.ts +4 -4
- package/dist/src/imagemap.js +9 -5
- package/dist/src/imagemapLink.d.ts +3 -1
- package/dist/src/imagemapLink.js +3 -1
- package/dist/src/index.d.ts +65 -20
- package/dist/src/index.js +111 -39
- package/dist/src/link/base.d.ts +14 -6
- package/dist/src/link/base.js +40 -17
- package/dist/src/link/category.d.ts +7 -2
- package/dist/src/link/category.js +20 -4
- package/dist/src/link/file.d.ts +71 -23
- package/dist/src/link/file.js +100 -36
- package/dist/src/link/galleryImage.d.ts +8 -4
- package/dist/src/link/galleryImage.js +15 -8
- package/dist/src/link/index.d.ts +12 -4
- package/dist/src/link/index.js +15 -5
- package/dist/src/link/redirectTarget.d.ts +3 -2
- package/dist/src/link/redirectTarget.js +5 -3
- package/dist/src/magicLink.d.ts +24 -11
- package/dist/src/magicLink.js +36 -19
- package/dist/src/nested.d.ts +5 -3
- package/dist/src/nested.js +9 -6
- package/dist/src/nowiki/base.d.ts +4 -2
- package/dist/src/nowiki/base.js +6 -5
- package/dist/src/nowiki/comment.d.ts +6 -2
- package/dist/src/nowiki/comment.js +8 -3
- package/dist/src/nowiki/dd.d.ts +0 -3
- package/dist/src/nowiki/dd.js +0 -8
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -1
- package/dist/src/nowiki/doubleUnderscore.js +5 -1
- package/dist/src/nowiki/index.d.ts +5 -1
- package/dist/src/nowiki/index.js +5 -1
- package/dist/src/nowiki/list.d.ts +5 -1
- package/dist/src/nowiki/list.js +5 -1
- package/dist/src/nowiki/listBase.d.ts +15 -5
- package/dist/src/nowiki/listBase.js +40 -9
- package/dist/src/nowiki/noinclude.d.ts +5 -1
- package/dist/src/nowiki/noinclude.js +5 -1
- package/dist/src/nowiki/quote.d.ts +15 -8
- package/dist/src/nowiki/quote.js +32 -12
- package/dist/src/onlyinclude.d.ts +4 -2
- package/dist/src/onlyinclude.js +4 -2
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +1 -1
- package/dist/src/parameter.d.ts +24 -12
- package/dist/src/parameter.js +45 -27
- package/dist/src/pre.d.ts +1 -1
- package/dist/src/pre.js +1 -1
- package/dist/src/redirect.d.ts +2 -0
- package/dist/src/redirect.js +2 -0
- package/dist/src/syntax.d.ts +5 -1
- package/dist/src/syntax.js +5 -1
- package/dist/src/table/base.d.ts +5 -1
- package/dist/src/table/base.js +10 -3
- package/dist/src/table/index.d.ts +134 -66
- package/dist/src/table/index.js +150 -81
- package/dist/src/table/td.d.ts +18 -10
- package/dist/src/table/td.js +25 -15
- package/dist/src/table/tr.d.ts +13 -3
- package/dist/src/table/tr.js +14 -6
- package/dist/src/table/trBase.d.ts +28 -12
- package/dist/src/table/trBase.js +28 -18
- package/dist/src/tagPair/ext.d.ts +3 -1
- package/dist/src/tagPair/ext.js +10 -8
- package/dist/src/tagPair/include.d.ts +8 -2
- package/dist/src/tagPair/include.js +8 -2
- package/dist/src/tagPair/index.d.ts +6 -2
- package/dist/src/tagPair/index.js +6 -2
- package/dist/src/transclude.d.ts +102 -33
- package/dist/src/transclude.js +114 -42
- package/dist/util/debug.js +2 -7
- package/dist/util/html.js +1 -18
- package/dist/util/string.js +7 -1
- package/extensions/dist/base.js +27 -16
- package/extensions/dist/codejar.js +2 -1
- package/extensions/dist/lsp.js +5 -10
- package/extensions/es7/base.js +27 -16
- package/extensions/ui.css +1 -162
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +3 -3
package/dist/src/transclude.js
CHANGED
|
@@ -14,8 +14,10 @@ const syntax_1 = require("./syntax");
|
|
|
14
14
|
/* NOT FOR BROWSER */
|
|
15
15
|
const basicMagicWords = new Map([['=', '='], ['!', '|']]);
|
|
16
16
|
/**
|
|
17
|
+
* template or magic word
|
|
18
|
+
*
|
|
17
19
|
* 模板或魔术字
|
|
18
|
-
* @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
|
|
20
|
+
* @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken[], ...ParameterToken[]]}`
|
|
19
21
|
*/
|
|
20
22
|
class TranscludeToken extends index_2.Token {
|
|
21
23
|
modifier = '';
|
|
@@ -30,7 +32,7 @@ class TranscludeToken extends index_2.Token {
|
|
|
30
32
|
return this.#type;
|
|
31
33
|
}
|
|
32
34
|
/* NOT FOR BROWSER */
|
|
33
|
-
/** 是否存在重复参数 */
|
|
35
|
+
/** whether to contain duplicated parameters / 是否存在重复参数 */
|
|
34
36
|
get duplication() {
|
|
35
37
|
return this.isTemplate() && Boolean(this.hasDuplicatedArgs());
|
|
36
38
|
}
|
|
@@ -102,7 +104,7 @@ class TranscludeToken extends index_2.Token {
|
|
|
102
104
|
}
|
|
103
105
|
if (this.type === 'template') {
|
|
104
106
|
const name = (0, string_1.removeComment)(title).trim();
|
|
105
|
-
if (!this.normalizeTitle(name, 10, true).valid) {
|
|
107
|
+
if (!this.normalizeTitle(name, 10, true, true).valid) {
|
|
106
108
|
accum.pop();
|
|
107
109
|
/* NOT FOR BROWSER */
|
|
108
110
|
index_1.default.debug(`Invalid template name: ${(0, string_1.noWrap)(name)}`);
|
|
@@ -137,8 +139,10 @@ class TranscludeToken extends index_2.Token {
|
|
|
137
139
|
this.protectChildren(0);
|
|
138
140
|
}
|
|
139
141
|
/**
|
|
142
|
+
* Set the transclusion modifier
|
|
143
|
+
*
|
|
140
144
|
* 设置引用修饰符
|
|
141
|
-
* @param modifier 引用修饰符
|
|
145
|
+
* @param modifier transclusion modifier / 引用修饰符
|
|
142
146
|
*/
|
|
143
147
|
setModifier(modifier) {
|
|
144
148
|
const { parserFunction: [, , raw, subst] } = this.getAttribute('config'), lcModifier = (0, string_1.removeComment)(modifier).trim();
|
|
@@ -155,16 +159,22 @@ class TranscludeToken extends index_2.Token {
|
|
|
155
159
|
}
|
|
156
160
|
return false;
|
|
157
161
|
}
|
|
158
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* Check if it is a template or a module
|
|
164
|
+
*
|
|
165
|
+
* 是否是模板或模块
|
|
166
|
+
*/
|
|
159
167
|
isTemplate() {
|
|
160
168
|
return this.type === 'template' || this.name === 'invoke';
|
|
161
169
|
}
|
|
162
170
|
/** 获取模板或模块名 */
|
|
163
171
|
#getTitle() {
|
|
164
|
-
const isTemplate = this.type === 'template'
|
|
165
|
-
return this.normalizeTitle(
|
|
172
|
+
const isTemplate = this.type === 'template';
|
|
173
|
+
return this.normalizeTitle(this.childNodes[isTemplate ? 0 : 1].toString(true), isTemplate ? 10 : 828, true);
|
|
166
174
|
}
|
|
167
175
|
/**
|
|
176
|
+
* Get the module name and module function name
|
|
177
|
+
*
|
|
168
178
|
* 获取模块名和模块函数名
|
|
169
179
|
* @throws `Error` 仅用于模块
|
|
170
180
|
*/
|
|
@@ -269,11 +279,15 @@ class TranscludeToken extends index_2.Token {
|
|
|
269
279
|
errors.push((0, lint_1.generateForChild)(childNodes[1], rect, 'invalid-invoke', 'illegal module name'));
|
|
270
280
|
}
|
|
271
281
|
else {
|
|
272
|
-
const child = childNodes[invoke ? 1 : 0], i = child.childNodes
|
|
282
|
+
const child = childNodes[invoke ? 1 : 0], i = child.childNodes
|
|
283
|
+
.findIndex(c => c.type === 'text' && (0, string_1.decodeHtml)(c.data).includes('#')), textNode = child.childNodes[i];
|
|
273
284
|
if (textNode) {
|
|
274
285
|
const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', 'useless fragment');
|
|
275
286
|
e.fix = {
|
|
276
|
-
range: [
|
|
287
|
+
range: [
|
|
288
|
+
e.startIndex + child.getRelativeIndex(i) + textNode.data.indexOf('#'),
|
|
289
|
+
e.endIndex,
|
|
290
|
+
],
|
|
277
291
|
text: '',
|
|
278
292
|
desc: 'remove',
|
|
279
293
|
};
|
|
@@ -284,7 +298,8 @@ class TranscludeToken extends index_2.Token {
|
|
|
284
298
|
errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-invoke', 'missing module function'));
|
|
285
299
|
return errors;
|
|
286
300
|
}
|
|
287
|
-
const duplicatedArgs = this.getDuplicatedArgs()
|
|
301
|
+
const duplicatedArgs = this.getDuplicatedArgs()
|
|
302
|
+
.filter(([, parameter]) => !parameter[0].querySelector('ext'));
|
|
288
303
|
if (duplicatedArgs.length > 0) {
|
|
289
304
|
for (const [, args] of duplicatedArgs) {
|
|
290
305
|
errors.push(...args.map(arg => {
|
|
@@ -325,8 +340,8 @@ class TranscludeToken extends index_2.Token {
|
|
|
325
340
|
}
|
|
326
341
|
/**
|
|
327
342
|
* @override
|
|
328
|
-
* @param token 待插入的子节点
|
|
329
|
-
* @param i 插入位置
|
|
343
|
+
* @param token node to be inserted / 待插入的子节点
|
|
344
|
+
* @param i position to be inserted at / 插入位置
|
|
330
345
|
*/
|
|
331
346
|
insertAt(token, i = this.length) {
|
|
332
347
|
super.insertAt(token, i);
|
|
@@ -340,22 +355,33 @@ class TranscludeToken extends index_2.Token {
|
|
|
340
355
|
}
|
|
341
356
|
return token;
|
|
342
357
|
}
|
|
343
|
-
/**
|
|
358
|
+
/**
|
|
359
|
+
* Get all parameters
|
|
360
|
+
*
|
|
361
|
+
* 获取所有参数
|
|
362
|
+
*/
|
|
344
363
|
getAllArgs() {
|
|
345
364
|
return this.childNodes.filter((0, debug_1.isToken)('parameter'));
|
|
346
365
|
}
|
|
347
|
-
/**
|
|
366
|
+
/**
|
|
367
|
+
* Get all anonymous parameters
|
|
368
|
+
*
|
|
369
|
+
* 获取所有匿名参数
|
|
370
|
+
*/
|
|
348
371
|
getAnonArgs() {
|
|
349
372
|
return this.getAllArgs().filter(({ anon }) => anon);
|
|
350
373
|
}
|
|
351
374
|
/**
|
|
375
|
+
* Get parameters with the specified name
|
|
376
|
+
*
|
|
352
377
|
* 获取指定参数
|
|
353
|
-
* @param key 参数名
|
|
354
|
-
* @param exact 是否匹配匿名性
|
|
355
|
-
* @param copy 是否返回一个备份
|
|
378
|
+
* @param key parameter name / 参数名
|
|
379
|
+
* @param exact whether to match anonymosity / 是否匹配匿名性
|
|
380
|
+
* @param copy whether to return a copy / 是否返回一个备份
|
|
356
381
|
*/
|
|
357
382
|
getArgs(key, exact, copy = true) {
|
|
358
|
-
const keyStr = String(key)
|
|
383
|
+
const keyStr = String(key)
|
|
384
|
+
.replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
|
|
359
385
|
let args;
|
|
360
386
|
if (this.#args.has(keyStr)) {
|
|
361
387
|
args = this.#args.get(keyStr);
|
|
@@ -375,6 +401,8 @@ class TranscludeToken extends index_2.Token {
|
|
|
375
401
|
return args;
|
|
376
402
|
}
|
|
377
403
|
/**
|
|
404
|
+
* Get duplicated parameters
|
|
405
|
+
*
|
|
378
406
|
* 获取重名参数
|
|
379
407
|
* @throws `Error` 仅用于模板
|
|
380
408
|
*/
|
|
@@ -385,6 +413,8 @@ class TranscludeToken extends index_2.Token {
|
|
|
385
413
|
throw new Error('TranscludeToken.getDuplicatedArgs method is only for template!');
|
|
386
414
|
}
|
|
387
415
|
/**
|
|
416
|
+
* Get possible values of some magic words
|
|
417
|
+
*
|
|
388
418
|
* 对特定魔术字获取可能的取值
|
|
389
419
|
* @throws `Error` 不是可接受的魔术字
|
|
390
420
|
*/
|
|
@@ -453,17 +483,25 @@ class TranscludeToken extends index_2.Token {
|
|
|
453
483
|
return token;
|
|
454
484
|
});
|
|
455
485
|
}
|
|
456
|
-
/**
|
|
486
|
+
/**
|
|
487
|
+
* Convert to substitution
|
|
488
|
+
*
|
|
489
|
+
* 替换引用
|
|
490
|
+
*/
|
|
457
491
|
subst() {
|
|
458
492
|
this.setModifier('subst:');
|
|
459
493
|
}
|
|
460
|
-
/**
|
|
494
|
+
/**
|
|
495
|
+
* Convert to safe substitution
|
|
496
|
+
*
|
|
497
|
+
* 安全的替换引用
|
|
498
|
+
*/
|
|
461
499
|
safesubst() {
|
|
462
500
|
this.setModifier('safesubst:');
|
|
463
501
|
}
|
|
464
502
|
/**
|
|
465
503
|
* @override
|
|
466
|
-
* @param i 移除位置
|
|
504
|
+
* @param i position of the child node / 移除位置
|
|
467
505
|
*/
|
|
468
506
|
removeAt(i) {
|
|
469
507
|
const token = super.removeAt(i);
|
|
@@ -480,26 +518,31 @@ class TranscludeToken extends index_2.Token {
|
|
|
480
518
|
return token;
|
|
481
519
|
}
|
|
482
520
|
/**
|
|
521
|
+
* Check if there is a parameter with the specified name
|
|
522
|
+
*
|
|
483
523
|
* 是否具有某参数
|
|
484
|
-
* @param key 参数名
|
|
485
|
-
* @param exact 是否匹配匿名性
|
|
524
|
+
* @param key parameter name / 参数名
|
|
525
|
+
* @param exact whether to match anonymosity / 是否匹配匿名性
|
|
486
526
|
*/
|
|
487
527
|
hasArg(key, exact) {
|
|
488
528
|
return this.getArgs(key, exact, false).size > 0;
|
|
489
529
|
}
|
|
490
530
|
/**
|
|
531
|
+
* Get the effective parameter with the specified name
|
|
532
|
+
*
|
|
491
533
|
* 获取生效的指定参数
|
|
492
|
-
* @param key 参数名
|
|
493
|
-
* @param exact 是否匹配匿名性
|
|
534
|
+
* @param key parameter name / 参数名
|
|
535
|
+
* @param exact whether to match anonymosity / 是否匹配匿名性
|
|
494
536
|
*/
|
|
495
537
|
getArg(key, exact) {
|
|
496
|
-
|
|
497
|
-
return args.at(-1);
|
|
538
|
+
return [...this.getArgs(key, exact, false)].sort((a, b) => a.compareDocumentPosition(b)).at(-1);
|
|
498
539
|
}
|
|
499
540
|
/**
|
|
541
|
+
* Remove parameters with the specified name
|
|
542
|
+
*
|
|
500
543
|
* 移除指定参数
|
|
501
|
-
* @param key 参数名
|
|
502
|
-
* @param exact 是否匹配匿名性
|
|
544
|
+
* @param key parameter name / 参数名
|
|
545
|
+
* @param exact whether to match anonymosity / 是否匹配匿名性
|
|
503
546
|
*/
|
|
504
547
|
removeArg(key, exact) {
|
|
505
548
|
debug_1.Shadow.run(() => {
|
|
@@ -508,7 +551,11 @@ class TranscludeToken extends index_2.Token {
|
|
|
508
551
|
}
|
|
509
552
|
});
|
|
510
553
|
}
|
|
511
|
-
/**
|
|
554
|
+
/**
|
|
555
|
+
* Get all parameter names
|
|
556
|
+
*
|
|
557
|
+
* 获取所有参数名
|
|
558
|
+
*/
|
|
512
559
|
getKeys() {
|
|
513
560
|
const args = this.getAllArgs();
|
|
514
561
|
if (this.#keys.size === 0 && args.length > 0) {
|
|
@@ -519,8 +566,10 @@ class TranscludeToken extends index_2.Token {
|
|
|
519
566
|
return [...this.#keys];
|
|
520
567
|
}
|
|
521
568
|
/**
|
|
569
|
+
* Get parameter values
|
|
570
|
+
*
|
|
522
571
|
* 获取参数值
|
|
523
|
-
* @param key 参数名
|
|
572
|
+
* @param key parameter name / 参数名
|
|
524
573
|
*/
|
|
525
574
|
getValues(key) {
|
|
526
575
|
return [...this.getArgs(key, false, false)].map(token => token.getValue());
|
|
@@ -531,17 +580,21 @@ class TranscludeToken extends index_2.Token {
|
|
|
531
580
|
: this.getArg(key)?.getValue();
|
|
532
581
|
}
|
|
533
582
|
/**
|
|
583
|
+
* Insert an anonymous parameter
|
|
584
|
+
*
|
|
534
585
|
* 插入匿名参数
|
|
535
|
-
* @param val 参数值
|
|
586
|
+
* @param val parameter value / 参数值
|
|
536
587
|
*/
|
|
537
588
|
newAnonArg(val) {
|
|
538
589
|
require('../addon/transclude');
|
|
539
590
|
return this.newAnonArg(val);
|
|
540
591
|
}
|
|
541
592
|
/**
|
|
593
|
+
* Set the parameter value
|
|
594
|
+
*
|
|
542
595
|
* 设置参数值
|
|
543
|
-
* @param key 参数名
|
|
544
|
-
* @param value 参数值
|
|
596
|
+
* @param key parameter name / 参数名
|
|
597
|
+
* @param value parameter value / 参数值
|
|
545
598
|
* @throws `Error` 仅用于模板
|
|
546
599
|
*/
|
|
547
600
|
setValue(key, value) {
|
|
@@ -549,6 +602,8 @@ class TranscludeToken extends index_2.Token {
|
|
|
549
602
|
this.setValue(key, value);
|
|
550
603
|
}
|
|
551
604
|
/**
|
|
605
|
+
* Convert all anonymous parameters to named ones
|
|
606
|
+
*
|
|
552
607
|
* 将匿名参数改写为命名参数
|
|
553
608
|
* @throws `Error` 仅用于模板
|
|
554
609
|
*/
|
|
@@ -561,8 +616,10 @@ class TranscludeToken extends index_2.Token {
|
|
|
561
616
|
}
|
|
562
617
|
}
|
|
563
618
|
/**
|
|
619
|
+
* Replace the template name
|
|
620
|
+
*
|
|
564
621
|
* 替换模板名
|
|
565
|
-
* @param title 模板名
|
|
622
|
+
* @param title template name / 模板名
|
|
566
623
|
* @throws `Error` 仅用于模板
|
|
567
624
|
*/
|
|
568
625
|
replaceTemplate(title) {
|
|
@@ -570,8 +627,10 @@ class TranscludeToken extends index_2.Token {
|
|
|
570
627
|
this.replaceTemplate(title);
|
|
571
628
|
}
|
|
572
629
|
/**
|
|
630
|
+
* Replace the module name
|
|
631
|
+
*
|
|
573
632
|
* 替换模块名
|
|
574
|
-
* @param title 模块名
|
|
633
|
+
* @param title module name / 模块名
|
|
575
634
|
* @throws `Error` 仅用于模块
|
|
576
635
|
*/
|
|
577
636
|
replaceModule(title) {
|
|
@@ -579,8 +638,10 @@ class TranscludeToken extends index_2.Token {
|
|
|
579
638
|
this.replaceModule(title);
|
|
580
639
|
}
|
|
581
640
|
/**
|
|
641
|
+
* Replace the module function
|
|
642
|
+
*
|
|
582
643
|
* 替换模块函数
|
|
583
|
-
* @param func 模块函数名
|
|
644
|
+
* @param func module function name / 模块函数名
|
|
584
645
|
* @throws `Error` 仅用于模块
|
|
585
646
|
* @throws `Error` 尚未指定模块名称
|
|
586
647
|
*/
|
|
@@ -589,6 +650,8 @@ class TranscludeToken extends index_2.Token {
|
|
|
589
650
|
this.replaceFunction(func);
|
|
590
651
|
}
|
|
591
652
|
/**
|
|
653
|
+
* Count duplicated parameters
|
|
654
|
+
*
|
|
592
655
|
* 重复参数计数
|
|
593
656
|
* @throws `Error` 仅用于模板
|
|
594
657
|
*/
|
|
@@ -599,16 +662,25 @@ class TranscludeToken extends index_2.Token {
|
|
|
599
662
|
throw new Error('TranscludeToken.hasDuplicatedArgs method is only for template!');
|
|
600
663
|
}
|
|
601
664
|
/**
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
* `aggressive =
|
|
605
|
-
*
|
|
665
|
+
* Fix duplicated parameters
|
|
666
|
+
* @description
|
|
667
|
+
* - Only empty parameters and identical parameters are removed with `aggressive = false`.
|
|
668
|
+
* Anonymous parameters have a higher precedence, otherwise all anonymous parameters are converted to named ones.
|
|
669
|
+
* - Additionally, consecutive numbered parameters are treated with `aggressive = true`.
|
|
670
|
+
*
|
|
671
|
+
* 修复重名参数
|
|
672
|
+
* @description
|
|
673
|
+
* - `aggressive = false`时只移除空参数和全同参数,优先保留匿名参数,否则将所有匿名参数更改为命名。
|
|
674
|
+
* - `aggressive = true`时还会尝试处理连续的以数字编号的参数。
|
|
675
|
+
* @param aggressive whether to use a more risky approach / 是否使用有更大风险的修复手段
|
|
606
676
|
*/
|
|
607
677
|
fixDuplication(aggressive) {
|
|
608
678
|
require('../addon/transclude');
|
|
609
679
|
return this.fixDuplication(aggressive);
|
|
610
680
|
}
|
|
611
681
|
/**
|
|
682
|
+
* Escape tables inside the template
|
|
683
|
+
*
|
|
612
684
|
* 转义模板内的表格
|
|
613
685
|
* @throws `Error` 转义失败
|
|
614
686
|
*/
|
|
@@ -620,7 +692,7 @@ class TranscludeToken extends index_2.Token {
|
|
|
620
692
|
toHtmlInternal(opt) {
|
|
621
693
|
const { type, name } = this;
|
|
622
694
|
if (type === 'template' && !name.startsWith('Special:')) {
|
|
623
|
-
if (this.normalizeTitle(name, 0, true).valid) {
|
|
695
|
+
if (this.normalizeTitle(name, 0, true, true).valid) {
|
|
624
696
|
const title = name.replaceAll('_', ' ');
|
|
625
697
|
return `<a href="${this.#title.getUrl()}?action=edit&redlink=1" class="new" title="${title} (page does not exist)">${title}</a>`;
|
|
626
698
|
}
|
package/dist/util/debug.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.undo = exports.typeError = exports.mixin = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
|
|
4
|
-
/* NOT FOR BROWSER END */
|
|
5
4
|
exports.Shadow = {
|
|
6
5
|
running: false,
|
|
7
6
|
/** @private */
|
|
@@ -38,11 +37,7 @@ exports.isToken = isToken;
|
|
|
38
37
|
* @param inserted 插入的子节点
|
|
39
38
|
*/
|
|
40
39
|
const setChildNodes = (parent, position, deleteCount, inserted = []) => {
|
|
41
|
-
const
|
|
42
|
-
const { childNodes } = parent, nodes = Object.isFrozen(childNodes)
|
|
43
|
-
|| !Parser.viewOnly
|
|
44
|
-
? [...childNodes]
|
|
45
|
-
: childNodes, removed = nodes.splice(position, deleteCount, ...inserted);
|
|
40
|
+
const nodes = parent.getChildNodes(), removed = nodes.splice(position, deleteCount, ...inserted);
|
|
46
41
|
for (let i = 0; i < inserted.length; i++) {
|
|
47
42
|
const node = inserted[i];
|
|
48
43
|
node.setAttribute('parentNode', parent);
|
|
@@ -69,6 +64,7 @@ const mixin = (target, source) => {
|
|
|
69
64
|
Object.defineProperty(target, 'name', { value: source.name });
|
|
70
65
|
};
|
|
71
66
|
exports.mixin = mixin;
|
|
67
|
+
/* NOT FOR BROWSER */
|
|
72
68
|
/* istanbul ignore next */
|
|
73
69
|
/**
|
|
74
70
|
* 定制TypeError消息
|
|
@@ -81,7 +77,6 @@ const typeError = ({ name }, method, ...args) => {
|
|
|
81
77
|
throw new TypeError(`${name}.${method} method only accepts ${args.join('、')} as input parameters!`);
|
|
82
78
|
};
|
|
83
79
|
exports.typeError = typeError;
|
|
84
|
-
/* NOT FOR BROWSER */
|
|
85
80
|
/**
|
|
86
81
|
* 撤销最近一次Mutation
|
|
87
82
|
* @param e 事件
|
package/dist/util/html.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* NOT FOR BROWSER */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.html = exports.getCommon = void 0;
|
|
5
5
|
/* NOT FOR BROWSER END */
|
|
6
6
|
/**
|
|
7
7
|
* get common prefix length
|
|
@@ -134,20 +134,3 @@ const html = (childNodes, separator = '', opt) => {
|
|
|
134
134
|
return results.join(separator);
|
|
135
135
|
};
|
|
136
136
|
exports.html = html;
|
|
137
|
-
/**
|
|
138
|
-
* wrap text with <b> and <i> tags
|
|
139
|
-
* @param node
|
|
140
|
-
* @param strOrOmit
|
|
141
|
-
*/
|
|
142
|
-
const font = (node, strOrOmit) => {
|
|
143
|
-
const str = strOrOmit ?? '';
|
|
144
|
-
if (node.type === 'html') {
|
|
145
|
-
return str;
|
|
146
|
-
}
|
|
147
|
-
const { font: { bold, italic } } = node, i = str.indexOf('\n');
|
|
148
|
-
const wrap = /** @ignore */ (s) => s === ''
|
|
149
|
-
? ''
|
|
150
|
-
: (italic ? '<i>' : '') + (bold ? '<b>' : '') + (s ?? '') + (bold ? '</b>' : '') + (italic ? '</i>' : '');
|
|
151
|
-
return i === -1 ? wrap(strOrOmit) : wrap(str.slice(0, i)) + str.slice(i);
|
|
152
|
-
};
|
|
153
|
-
exports.font = font;
|
package/dist/util/string.js
CHANGED
|
@@ -37,12 +37,14 @@ const decodeHtmlBasic = factory(/&(?:#(\d+|[Xx][\da-fA-F]+)|([lg]t|[LG]T|[lr]bra
|
|
|
37
37
|
* @param str
|
|
38
38
|
*/
|
|
39
39
|
const decodeHtml = (str) => {
|
|
40
|
+
/* NOT FOR BROWSER ONLY */
|
|
40
41
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
41
42
|
if (typeof process === 'object' && typeof process.versions?.node === 'string') {
|
|
42
43
|
const { decodeHTMLStrict } = require('entities');
|
|
43
44
|
return decodeHTMLStrict(str).replace(/\xA0/gu, ' ');
|
|
44
45
|
}
|
|
45
46
|
/* istanbul ignore next */
|
|
47
|
+
/* NOT FOR BROWSER ONLY END */
|
|
46
48
|
return decodeHtmlBasic(str);
|
|
47
49
|
};
|
|
48
50
|
exports.decodeHtml = decodeHtml;
|
|
@@ -50,6 +52,7 @@ exports.decodeHtml = decodeHtml;
|
|
|
50
52
|
exports.decodeNumber = factory(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number((/^x/iu.test(code) ? '0' : '') + code)));
|
|
51
53
|
/** escape newlines */
|
|
52
54
|
exports.noWrap = factory(/\n/gu, String.raw `\n`);
|
|
55
|
+
/* PRINT ONLY */
|
|
53
56
|
const entities = { '&': 'amp', '<': 'lt', '>': 'gt', '"': 'quot', '\n': '#10' };
|
|
54
57
|
/**
|
|
55
58
|
* replace by HTML entities
|
|
@@ -68,6 +71,7 @@ const print = (childNodes, opt = {}) => {
|
|
|
68
71
|
return pre + childNodes.map(child => child.print()).join(sep) + post;
|
|
69
72
|
};
|
|
70
73
|
exports.print = print;
|
|
74
|
+
/* PRINT ONLY END */
|
|
71
75
|
/* NOT FOR BROWSER */
|
|
72
76
|
/** encode URI */
|
|
73
77
|
exports.encode = factory(/[<>[\]#|=]+/gu, encodeURIComponent);
|
|
@@ -95,7 +99,9 @@ exports.sanitizeId = replaceEntities(/["&]/gu);
|
|
|
95
99
|
* sanitize selected HTML attributes
|
|
96
100
|
* @param str attribute value
|
|
97
101
|
*/
|
|
98
|
-
const sanitizeAlt = (str) => str?.replace(/<\/?[a-z].*?>/gu, '').trim()
|
|
102
|
+
const sanitizeAlt = (str) => str?.replace(/<\/?[a-z].*?>/gu, '').trim()
|
|
103
|
+
.replace(/\s+/gu, ' ')
|
|
104
|
+
.replaceAll('"', '"');
|
|
99
105
|
exports.sanitizeAlt = sanitizeAlt;
|
|
100
106
|
/** escape newline */
|
|
101
107
|
exports.newline = factory(/\n/gu, ' ');
|
package/extensions/dist/base.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
var _a;
|
|
3
|
-
const version = '1.16.
|
|
3
|
+
const version = '1.16.6', src = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.src, file = /\/extensions\/dist\/base\.(?:min\.)?js$/u, CDN = src && file.test(src)
|
|
4
4
|
? src.replace(file, '')
|
|
5
5
|
: `https://testingcf.jsdelivr.net/npm/wikiparser-node@${version}`;
|
|
6
6
|
const workerJS = () => {
|
|
7
7
|
importScripts('$CDN/bundle/bundle.lsp.js');
|
|
8
|
-
const entities = { '&': 'amp', '<': 'lt', '>': 'gt' }, lsps = new Map();
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
id += 0.5;
|
|
8
|
+
const entities = { '&': 'amp', '<': 'lt', '>': 'gt' }, lsps = new Map(), last = { include: true };
|
|
9
|
+
const parse = (wikitext, include = false, stage) => {
|
|
10
|
+
if (stage === undefined && last.wikitext === wikitext && last.include === include) {
|
|
11
|
+
return last.root;
|
|
13
12
|
}
|
|
13
|
+
const root = Parser.parse(wikitext, include, stage);
|
|
14
|
+
if (stage === undefined) {
|
|
15
|
+
last.wikitext = wikitext;
|
|
16
|
+
last.include = include;
|
|
17
|
+
last.root = root;
|
|
18
|
+
}
|
|
19
|
+
return root;
|
|
20
|
+
};
|
|
21
|
+
const getLSP = (qid) => {
|
|
22
|
+
const id = Math.floor(qid);
|
|
14
23
|
if (lsps.has(id)) {
|
|
15
24
|
return lsps.get(id);
|
|
16
25
|
}
|
|
@@ -26,10 +35,12 @@ const workerJS = () => {
|
|
|
26
35
|
parseInt(short ? s.charAt(1).repeat(2) : s.slice(1, 3), 16),
|
|
27
36
|
parseInt(short ? s.charAt(2).repeat(2) : s.slice(3, 5), 16),
|
|
28
37
|
parseInt(short ? s.charAt(3).repeat(2) : s.slice(5, 7), 16),
|
|
29
|
-
parseInt((short ? s.charAt(4).repeat(2) : s.slice(7, 9)) || 'ff', 16)
|
|
38
|
+
parseInt((short ? s.charAt(4).repeat(2) : s.slice(7, 9)) || 'ff', 16)
|
|
39
|
+
/ 255,
|
|
30
40
|
];
|
|
31
41
|
}
|
|
32
|
-
const values = s.slice(s.indexOf('(') + 1, -1).trim()
|
|
42
|
+
const values = s.slice(s.indexOf('(') + 1, -1).trim()
|
|
43
|
+
.split(/\s+(?:[,/]\s*)?|[,/]\s*/u)
|
|
33
44
|
.map(v => parseFloat(v) / (v.endsWith('%') ? 100 : 1));
|
|
34
45
|
return [
|
|
35
46
|
values[0],
|
|
@@ -46,20 +57,21 @@ const workerJS = () => {
|
|
|
46
57
|
break;
|
|
47
58
|
case 'setConfig':
|
|
48
59
|
Parser.config = qid;
|
|
60
|
+
delete last.wikitext;
|
|
49
61
|
break;
|
|
50
62
|
case 'getConfig':
|
|
51
63
|
postMessage([qid, Parser.getConfig()]);
|
|
52
64
|
break;
|
|
53
65
|
case 'json':
|
|
54
|
-
postMessage([qid,
|
|
66
|
+
postMessage([qid, parse(wikitext, include, stage).json()]);
|
|
55
67
|
break;
|
|
56
68
|
case 'lint':
|
|
57
|
-
postMessage([qid,
|
|
69
|
+
postMessage([qid, parse(wikitext, include).lint(), wikitext]);
|
|
58
70
|
break;
|
|
59
71
|
case 'print':
|
|
60
72
|
postMessage([
|
|
61
73
|
qid,
|
|
62
|
-
|
|
74
|
+
parse(wikitext, include, stage).childNodes.map(child => [
|
|
63
75
|
stage !== null && stage !== void 0 ? stage : Infinity,
|
|
64
76
|
String(child),
|
|
65
77
|
child.type === 'text'
|
|
@@ -70,13 +82,10 @@ const workerJS = () => {
|
|
|
70
82
|
break;
|
|
71
83
|
case 'destroy':
|
|
72
84
|
getLSP(qid).destroy();
|
|
73
|
-
getLSP(qid, true).destroy();
|
|
74
85
|
lsps.delete(qid);
|
|
75
|
-
lsps.delete(qid + 0.5);
|
|
76
86
|
break;
|
|
77
87
|
case 'data':
|
|
78
88
|
getLSP(qid).data = wikitext;
|
|
79
|
-
getLSP(qid, true).data = wikitext;
|
|
80
89
|
break;
|
|
81
90
|
case 'colorPresentations':
|
|
82
91
|
postMessage([qid, getLSP(qid).provideColorPresentations(wikitext)]);
|
|
@@ -133,7 +142,7 @@ const workerJS = () => {
|
|
|
133
142
|
break;
|
|
134
143
|
case 'signatureHelp':
|
|
135
144
|
(async () => {
|
|
136
|
-
postMessage([qid, await getLSP(qid
|
|
145
|
+
postMessage([qid, await getLSP(qid).provideSignatureHelp(wikitext, include), wikitext]);
|
|
137
146
|
})();
|
|
138
147
|
break;
|
|
139
148
|
case 'inlayHints':
|
|
@@ -185,7 +194,9 @@ const splitNewLine = (html) => {
|
|
|
185
194
|
cur.append(child.cloneNode(true));
|
|
186
195
|
continue;
|
|
187
196
|
}
|
|
188
|
-
const lines = child.nodeType === Node.TEXT_NODE
|
|
197
|
+
const lines = child.nodeType === Node.TEXT_NODE
|
|
198
|
+
? textContent.split('\n')
|
|
199
|
+
: splitNewLine(child);
|
|
189
200
|
append(cur, lines[0]);
|
|
190
201
|
for (const text of lines.slice(1)) {
|
|
191
202
|
cur = html.cloneNode();
|
|
@@ -24,7 +24,8 @@ const codejar = (async () => {
|
|
|
24
24
|
root.focus();
|
|
25
25
|
});
|
|
26
26
|
const id = wikiparse.id++;
|
|
27
|
-
const highlight = async (e) => (await wikiparse.print(e.textContent, jar.include, undefined, id)).map(([, , printed]) => printed)
|
|
27
|
+
const highlight = async (e) => (await wikiparse.print(e.textContent, jar.include, undefined, id)).map(([, , printed]) => printed)
|
|
28
|
+
.join('');
|
|
28
29
|
const jar = {
|
|
29
30
|
...CodeJar(root, highlight, {
|
|
30
31
|
spellcheck: true,
|
package/extensions/dist/lsp.js
CHANGED
|
@@ -37,23 +37,19 @@ class LanguageService {
|
|
|
37
37
|
return wikiparse.provide('links', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.3, text);
|
|
38
38
|
}
|
|
39
39
|
provideCompletionItems(text, position) {
|
|
40
|
-
return wikiparse
|
|
41
|
-
.provide('completionItems', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.4, text, position);
|
|
40
|
+
return wikiparse.provide('completionItems', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.4, text, position);
|
|
42
41
|
}
|
|
43
42
|
provideReferences(text, position) {
|
|
44
|
-
return wikiparse
|
|
45
|
-
.provide('references', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.5, text, position);
|
|
43
|
+
return wikiparse.provide('references', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.5, text, position);
|
|
46
44
|
}
|
|
47
45
|
provideDefinition(text, position) {
|
|
48
|
-
return wikiparse
|
|
49
|
-
.provide('definition', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.6, text, position);
|
|
46
|
+
return wikiparse.provide('definition', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.6, text, position);
|
|
50
47
|
}
|
|
51
48
|
resolveRenameLocation(text, position) {
|
|
52
49
|
return wikiparse.provide('renameLocation', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.7, text, position);
|
|
53
50
|
}
|
|
54
51
|
provideRenameEdits(text, position, newName) {
|
|
55
|
-
return wikiparse
|
|
56
|
-
.provide('renameEdits', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.8, text, position, newName);
|
|
52
|
+
return wikiparse.provide('renameEdits', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.8, text, position, newName);
|
|
57
53
|
}
|
|
58
54
|
provideDiagnostics(wikitext, warning) {
|
|
59
55
|
return wikiparse.provide('diagnostics', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.9, wikitext, warning);
|
|
@@ -62,8 +58,7 @@ class LanguageService {
|
|
|
62
58
|
return wikiparse.provide('hover', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.05, text, position);
|
|
63
59
|
}
|
|
64
60
|
provideSignatureHelp(text, position) {
|
|
65
|
-
return wikiparse
|
|
66
|
-
.provide('signatureHelp', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.15, text, position);
|
|
61
|
+
return wikiparse.provide('signatureHelp', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.15, text, position);
|
|
67
62
|
}
|
|
68
63
|
provideInlayHints(text) {
|
|
69
64
|
return wikiparse.provide('inlayHints', __classPrivateFieldGet(this, _LanguageService_id, "f") + 0.25, text);
|