wikilint 2.47.0 → 2.48.1
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/config/.schema.json +1 -1
- package/config/default.json +1 -0
- package/config/enwiki.json +1 -0
- package/config/jawiki.json +1 -0
- package/config/zhwiki.json +1 -0
- package/data/signatures.json +20 -0
- package/dist/base.d.mts +16 -1
- package/dist/base.d.ts +16 -1
- package/dist/bin/cli.js +6 -7
- package/dist/bin/config.js +2 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -2
- package/dist/lib/document.d.ts +8 -8
- package/dist/lib/document.js +2 -4
- package/dist/lib/lsp.d.ts +9 -1
- package/dist/lib/lsp.js +106 -100
- package/dist/lib/node.js +1 -1
- package/dist/lib/text.d.ts +2 -3
- package/dist/lib/text.js +4 -5
- package/dist/parser/braces.js +3 -4
- package/dist/src/attribute.js +13 -13
- package/dist/src/converterFlags.js +14 -13
- package/dist/src/converterRule.js +1 -1
- package/dist/src/extLink.js +1 -0
- package/dist/src/index.js +3 -2
- package/dist/src/link/base.js +3 -3
- package/dist/src/link/categorytree.js +3 -4
- package/dist/src/link/file.js +8 -7
- package/dist/src/multiLine/gallery.js +1 -1
- package/dist/src/table/index.d.ts +1 -1
- package/dist/src/table/td.js +2 -2
- package/dist/src/transclude.d.ts +2 -1
- package/dist/src/transclude.js +11 -7
- package/dist/util/ajv.js +26 -0
- package/dist/util/constants.js +1 -6
- package/dist/util/string.js +1 -0
- package/package.json +18 -18
package/dist/lib/lsp.js
CHANGED
|
@@ -106,28 +106,33 @@ const createNodeRange = (token) => {
|
|
|
106
106
|
* @param pos.line line number
|
|
107
107
|
* @param pos.character character number
|
|
108
108
|
* @param extra extra text
|
|
109
|
-
* @param getDoc documentation method
|
|
110
109
|
*/
|
|
111
|
-
const getCompletion = (words, kind, mt, { line, character }, extra = ''
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
start: { line, character: character - mt.length },
|
|
119
|
-
end: { line, character },
|
|
120
|
-
},
|
|
121
|
-
newText: w + extra,
|
|
122
|
-
},
|
|
123
|
-
...doc && {
|
|
124
|
-
documentation: {
|
|
125
|
-
kind: 'markdown',
|
|
126
|
-
value: doc,
|
|
127
|
-
},
|
|
110
|
+
const getCompletion = (words, kind, mt, { line, character }, extra = '') => [...new Set(words)].map((w) => ({
|
|
111
|
+
label: w,
|
|
112
|
+
kind,
|
|
113
|
+
textEdit: {
|
|
114
|
+
range: {
|
|
115
|
+
start: { line, character: character - mt.length },
|
|
116
|
+
end: { line, character },
|
|
128
117
|
},
|
|
129
|
-
|
|
130
|
-
}
|
|
118
|
+
newText: w + extra,
|
|
119
|
+
},
|
|
120
|
+
}));
|
|
121
|
+
/**
|
|
122
|
+
* Normalize a magic word.
|
|
123
|
+
* @param word magic word
|
|
124
|
+
* @param insensitive dictionary of insensitive magic words
|
|
125
|
+
* @param sensitive dictionary of sensitive magic words
|
|
126
|
+
*/
|
|
127
|
+
const normalizeMagicWord = (word, insensitive, sensitive) => {
|
|
128
|
+
if (Object.hasOwn(insensitive, word)) {
|
|
129
|
+
word = insensitive[word];
|
|
130
|
+
}
|
|
131
|
+
else if (Object.hasOwn(sensitive, word)) {
|
|
132
|
+
word = sensitive[word];
|
|
133
|
+
}
|
|
134
|
+
return word.toLowerCase();
|
|
135
|
+
};
|
|
131
136
|
/**
|
|
132
137
|
* Get the caret position at the position from a word.
|
|
133
138
|
* @param root root token
|
|
@@ -380,30 +385,42 @@ class LanguageService {
|
|
|
380
385
|
/** @private */
|
|
381
386
|
config;
|
|
382
387
|
/** @private */
|
|
383
|
-
data;
|
|
388
|
+
static data;
|
|
384
389
|
/* NOT FOR BROWSER ONLY */
|
|
385
390
|
/** @private */
|
|
386
391
|
// @ts-expect-error lazy initialization
|
|
387
392
|
lilypond;
|
|
388
393
|
#lilypondData;
|
|
389
394
|
#mathData;
|
|
395
|
+
static {
|
|
396
|
+
this.data = require(path_1.default.join('..', '..', 'data', 'signatures.json'));
|
|
397
|
+
}
|
|
390
398
|
/* NOT FOR BROWSER ONLY END */
|
|
399
|
+
/**
|
|
400
|
+
* 检索状态开关
|
|
401
|
+
* @param name 魔术字名
|
|
402
|
+
*/
|
|
403
|
+
static #getBehaviorSwitch(name) {
|
|
404
|
+
return this.data.behaviorSwitches.find(({ aliases }) => aliases.includes(name));
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* 检索解析器函数
|
|
408
|
+
* @param name 函数名
|
|
409
|
+
*/
|
|
410
|
+
static #getParserFunction(name) {
|
|
411
|
+
return this.data.parserFunctions
|
|
412
|
+
.find(({ aliases }) => aliases.some(alias => alias.replace(/^#/u, '') === name));
|
|
413
|
+
}
|
|
391
414
|
/** @param uri 任务标识 */
|
|
392
415
|
constructor(uri) {
|
|
393
416
|
exports.tasks.set(uri, this);
|
|
417
|
+
Object.defineProperties(this, {
|
|
418
|
+
config: { enumerable: false },
|
|
419
|
+
});
|
|
394
420
|
/* NOT FOR BROWSER ONLY */
|
|
395
421
|
const dataDir = path_1.default.join('..', '..', 'data'), extDir = path_1.default.join(dataDir, 'ext');
|
|
396
422
|
this.#lilypondData = require(path_1.default.join(extDir, 'score.json'));
|
|
397
423
|
this.#mathData = require(path_1.default.join(extDir, 'math.json'));
|
|
398
|
-
/* NOT FOR BROWSER ONLY END */
|
|
399
|
-
Object.defineProperties(this, {
|
|
400
|
-
config: { enumerable: false },
|
|
401
|
-
data: {
|
|
402
|
-
enumerable: false,
|
|
403
|
-
/* NOT FOR BROWSER ONLY */
|
|
404
|
-
value: require(path_1.default.join(dataDir, 'signatures.json')),
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
424
|
}
|
|
408
425
|
/** @implements */
|
|
409
426
|
async destroy() {
|
|
@@ -608,28 +625,14 @@ class LanguageService {
|
|
|
608
625
|
* @param position position / 位置
|
|
609
626
|
*/
|
|
610
627
|
async provideCompletionItems(text, position) {
|
|
611
|
-
const { re, allTags, functions, switches, jaSwitches, protocols, params, tags, ext, } = this.#prepareCompletionConfig(), { line, character } = position, curLine = text.split(/\r?\n/u, line + 1)[line], mt = re.exec(curLine?.slice(0, character) ?? '')
|
|
628
|
+
const { re, allTags, functions, switches, jaSwitches, protocols, params, tags, ext, } = this.#prepareCompletionConfig(), { line, character } = position, curLine = text.split(/\r?\n/u, line + 1)[line], mt = re.exec(curLine?.slice(0, character) ?? '');
|
|
612
629
|
if (mt?.[1] !== undefined) { // tag
|
|
613
630
|
const closing = mt[1].startsWith('/');
|
|
614
631
|
return getCompletion(allTags, 'Class', mt[1].slice(closing ? 1 : 0), position, closing && !curLine?.slice(character).trimStart().startsWith('>') ? '>' : '');
|
|
615
632
|
}
|
|
616
633
|
else if (mt?.[4] || mt?.[5] && jaSwitches.length > 0) { // behavior switch
|
|
617
634
|
const isJa = mt[5] !== undefined;
|
|
618
|
-
return getCompletion(isJa ? jaSwitches : switches, 'Constant', mt[isJa ? 5 : 4], position
|
|
619
|
-
if (!this.data) {
|
|
620
|
-
return undefined;
|
|
621
|
-
}
|
|
622
|
-
else if (!isJa) {
|
|
623
|
-
name = name.slice(2, -2);
|
|
624
|
-
}
|
|
625
|
-
if (Object.hasOwn(iAlias, name)) {
|
|
626
|
-
name = iAlias[name];
|
|
627
|
-
}
|
|
628
|
-
else if (Object.hasOwn(sAlias, name)) {
|
|
629
|
-
name = sAlias[name];
|
|
630
|
-
}
|
|
631
|
-
return this.#getBehaviorSwitch(name.toLowerCase());
|
|
632
|
-
});
|
|
635
|
+
return getCompletion(isJa ? jaSwitches : switches, 'Constant', mt[isJa ? 5 : 4], position);
|
|
633
636
|
}
|
|
634
637
|
else if (mt?.[6] !== undefined) { // protocol
|
|
635
638
|
return getCompletion(protocols, 'Reference', mt[6], position);
|
|
@@ -643,7 +646,7 @@ class LanguageService {
|
|
|
643
646
|
return getCompletion(root.querySelectorAll('arg').filter(token => token.name && token !== cur)
|
|
644
647
|
.map(({ name }) => name), 'Variable', match, position);
|
|
645
648
|
}
|
|
646
|
-
const
|
|
649
|
+
const colon = match.startsWith(':'), str = colon ? match.slice(1).trimStart() : match;
|
|
647
650
|
if (mt[2] === '[[') { // link
|
|
648
651
|
return getCompletion(root.querySelectorAll('link,file,category,redirect-target').filter(token => token !== cur).map(({ name }) => name), 'Folder', str, position);
|
|
649
652
|
}
|
|
@@ -657,18 +660,7 @@ class LanguageService {
|
|
|
657
660
|
words = functions.filter(s => s.endsWith(':')).map(s => s.slice(0, -1));
|
|
658
661
|
}
|
|
659
662
|
return [
|
|
660
|
-
...getCompletion(words, 'Function', match, position,
|
|
661
|
-
if (!this.data) {
|
|
662
|
-
return undefined;
|
|
663
|
-
}
|
|
664
|
-
else if (Object.hasOwn(insensitive, name)) {
|
|
665
|
-
name = insensitive[name];
|
|
666
|
-
}
|
|
667
|
-
else if (Object.hasOwn(sensitive, name)) {
|
|
668
|
-
name = sensitive[name];
|
|
669
|
-
}
|
|
670
|
-
return this.#getParserFunction(name.toLowerCase());
|
|
671
|
-
}),
|
|
663
|
+
...getCompletion(words, 'Function', match, position),
|
|
672
664
|
...match.startsWith('#')
|
|
673
665
|
? []
|
|
674
666
|
: getCompletion(root.querySelectorAll('template').filter(token => token !== cur).map(token => {
|
|
@@ -806,6 +798,36 @@ class LanguageService {
|
|
|
806
798
|
}
|
|
807
799
|
return undefined;
|
|
808
800
|
}
|
|
801
|
+
/**
|
|
802
|
+
* Add additional information to a completion item
|
|
803
|
+
*
|
|
804
|
+
* 为自动补全项添加额外信息
|
|
805
|
+
* @param item completion item / 自动补全项
|
|
806
|
+
* @since v1.48.0
|
|
807
|
+
*/
|
|
808
|
+
resolveCompletionItem(item) {
|
|
809
|
+
if (!LanguageService.data) {
|
|
810
|
+
return item;
|
|
811
|
+
}
|
|
812
|
+
this.config ??= index_1.default.getConfig();
|
|
813
|
+
const { kind } = item, Constant = 21, Function = 3;
|
|
814
|
+
let { label } = item, doc;
|
|
815
|
+
if (kind === 'Constant' || kind === Constant) {
|
|
816
|
+
const [, , insensitive, sensitive] = this.config.doubleUnderscore;
|
|
817
|
+
if (label.endsWith('_')) {
|
|
818
|
+
label = label.slice(2, -2);
|
|
819
|
+
}
|
|
820
|
+
doc = LanguageService.#getBehaviorSwitch(normalizeMagicWord(label, insensitive, sensitive));
|
|
821
|
+
}
|
|
822
|
+
else if ((kind === 'Function' || kind === Function) && !label.startsWith('/')) {
|
|
823
|
+
const [insensitive, sensitive] = this.config.parserFunction;
|
|
824
|
+
doc = LanguageService.#getParserFunction(normalizeMagicWord(label, insensitive, sensitive));
|
|
825
|
+
}
|
|
826
|
+
if (doc?.description) {
|
|
827
|
+
item.documentation = { kind: 'markdown', value: doc.description };
|
|
828
|
+
}
|
|
829
|
+
return item;
|
|
830
|
+
}
|
|
809
831
|
/**
|
|
810
832
|
* Provide grammar check
|
|
811
833
|
*
|
|
@@ -1157,26 +1179,25 @@ class LanguageService {
|
|
|
1157
1179
|
*/
|
|
1158
1180
|
async provideDocumentHighlights(text, position) {
|
|
1159
1181
|
const root = await this.#queue(text), index = root.indexFromPos(position.line, position.character), node = root.elementFromIndex(index), type = node?.type;
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1182
|
+
return !node || (type === 'ext' || type === 'html') && !/\w/u.test(text.charAt(index))
|
|
1183
|
+
? undefined
|
|
1184
|
+
: getMatchingTokens(root, node, highlightTypes)?.map((token) => {
|
|
1185
|
+
const range = createNodeRange(token);
|
|
1186
|
+
if (type === 'ext' || type === 'html') {
|
|
1187
|
+
const { start } = range;
|
|
1188
|
+
start.character += token.closing ? 2 : 1;
|
|
1189
|
+
return {
|
|
1190
|
+
range: {
|
|
1191
|
+
start,
|
|
1192
|
+
end: {
|
|
1193
|
+
line: start.line,
|
|
1194
|
+
character: start.character + token.name.length,
|
|
1195
|
+
},
|
|
1174
1196
|
},
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
});
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
return { range };
|
|
1200
|
+
});
|
|
1180
1201
|
}
|
|
1181
1202
|
/**
|
|
1182
1203
|
* Provide references
|
|
@@ -1281,21 +1302,6 @@ class LanguageService {
|
|
|
1281
1302
|
},
|
|
1282
1303
|
};
|
|
1283
1304
|
}
|
|
1284
|
-
/**
|
|
1285
|
-
* 检索状态开关
|
|
1286
|
-
* @param name 魔术字名
|
|
1287
|
-
*/
|
|
1288
|
-
#getBehaviorSwitch(name) {
|
|
1289
|
-
return this.data.behaviorSwitches.find(({ aliases }) => aliases.includes(name));
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* 检索解析器函数
|
|
1293
|
-
* @param name 函数名
|
|
1294
|
-
*/
|
|
1295
|
-
#getParserFunction(name) {
|
|
1296
|
-
return this.data.parserFunctions
|
|
1297
|
-
.find(({ aliases }) => aliases.some(alias => alias.replace(/^#/u, '') === name));
|
|
1298
|
-
}
|
|
1299
1305
|
/**
|
|
1300
1306
|
* Provide hover information
|
|
1301
1307
|
*
|
|
@@ -1305,7 +1311,7 @@ class LanguageService {
|
|
|
1305
1311
|
*/
|
|
1306
1312
|
async provideHover(text, position) {
|
|
1307
1313
|
/* c8 ignore next 3 */
|
|
1308
|
-
if (!
|
|
1314
|
+
if (!LanguageService.data) {
|
|
1309
1315
|
return undefined;
|
|
1310
1316
|
}
|
|
1311
1317
|
const root = await this.#queue(text);
|
|
@@ -1317,23 +1323,23 @@ class LanguageService {
|
|
|
1317
1323
|
const { type, parentNode, length, name } = offsetNode;
|
|
1318
1324
|
let info, f, colon, range;
|
|
1319
1325
|
if (offsetNode.is('double-underscore') && offset > 0) {
|
|
1320
|
-
info =
|
|
1326
|
+
info = LanguageService.#getBehaviorSwitch(offsetNode.name);
|
|
1321
1327
|
}
|
|
1322
1328
|
else if (type === 'magic-word-name') {
|
|
1323
|
-
info =
|
|
1329
|
+
info = LanguageService.#getParserFunction(parentNode.name);
|
|
1324
1330
|
f = offsetNode.text().trim();
|
|
1325
1331
|
colon = parentNode.getAttribute('colon');
|
|
1326
1332
|
}
|
|
1327
1333
|
else if (length === 1 && offsetNode.is('magic-word') && !offsetNode.modifier
|
|
1328
1334
|
&& (offset > 0 || root.posFromIndex(offsetNode.getAbsoluteIndex()).left === position.character)) {
|
|
1329
|
-
info =
|
|
1335
|
+
info = LanguageService.#getParserFunction(name);
|
|
1330
1336
|
f = offsetNode.firstChild.text().trim();
|
|
1331
1337
|
colon = offsetNode.getAttribute('colon');
|
|
1332
1338
|
}
|
|
1333
1339
|
else if ((offsetNode.is('magic-word') || offsetNode.is('template'))
|
|
1334
1340
|
&& offsetNode.modifier && offset >= 2 && offsetNode.getRelativeIndex(0) > offset) {
|
|
1335
1341
|
f = offsetNode.modifier.trim().slice(0, -1);
|
|
1336
|
-
info =
|
|
1342
|
+
info = LanguageService.#getParserFunction(f.toLowerCase());
|
|
1337
1343
|
colon = ':';
|
|
1338
1344
|
if (info) {
|
|
1339
1345
|
const aIndex = offsetNode.getAbsoluteIndex();
|
|
@@ -1403,14 +1409,14 @@ class LanguageService {
|
|
|
1403
1409
|
*/
|
|
1404
1410
|
async provideSignatureHelp(text, position) {
|
|
1405
1411
|
/* c8 ignore next 3 */
|
|
1406
|
-
if (!
|
|
1412
|
+
if (!LanguageService.data) {
|
|
1407
1413
|
return undefined;
|
|
1408
1414
|
}
|
|
1409
1415
|
const { line, character } = position, curLine = text.split(/\r?\n/u, line + 1)[line], { lastChild } = await this.#queueSignature(`${curLine.slice(0, character + (0, common_1.numLeadingSpaces)(curLine.slice(character), /[{}<]|$/u))}}}`);
|
|
1410
1416
|
if (!lastChild.is('magic-word') || lastChild.length === 1) {
|
|
1411
1417
|
return undefined;
|
|
1412
1418
|
}
|
|
1413
|
-
const { name, childNodes, firstChild } = lastChild, info =
|
|
1419
|
+
const { name, childNodes, firstChild } = lastChild, info = LanguageService.#getParserFunction(name);
|
|
1414
1420
|
if (!info?.signatures) {
|
|
1415
1421
|
return undefined;
|
|
1416
1422
|
}
|
package/dist/lib/node.js
CHANGED
|
@@ -90,7 +90,7 @@ let AstNode = (() => {
|
|
|
90
90
|
/** @private */
|
|
91
91
|
getChildNodes() {
|
|
92
92
|
const { childNodes } = this;
|
|
93
|
-
if (Object.isFrozen(childNodes)) {
|
|
93
|
+
if (Object.isFrozen(childNodes)) { // eslint-disable-line unicorn/prefer-ternary
|
|
94
94
|
return [...childNodes];
|
|
95
95
|
}
|
|
96
96
|
return childNodes;
|
package/dist/lib/text.d.ts
CHANGED
|
@@ -24,8 +24,7 @@ export declare class AstText extends AstNode {
|
|
|
24
24
|
*
|
|
25
25
|
* 将文本子节点分裂为两部分
|
|
26
26
|
* @param offset position to be splitted at / 分裂位置
|
|
27
|
-
* @throws `
|
|
28
|
-
* @throws `Error` 没有父节点
|
|
27
|
+
* @throws `Error` if the text node has no parent node
|
|
29
28
|
*/
|
|
30
29
|
splitText(offset: number): AstText;
|
|
31
30
|
/**
|
|
@@ -33,7 +32,7 @@ export declare class AstText extends AstNode {
|
|
|
33
32
|
*
|
|
34
33
|
* 转义 `=` 和 `|`
|
|
35
34
|
* @since v1.1.4
|
|
36
|
-
* @throws `Error`
|
|
35
|
+
* @throws `Error` if the text node has no parent node
|
|
37
36
|
*/
|
|
38
37
|
escape(): void;
|
|
39
38
|
}
|
package/dist/lib/text.js
CHANGED
|
@@ -70,7 +70,7 @@ class AstText extends node_1.AstNode {
|
|
|
70
70
|
}
|
|
71
71
|
/** @private */
|
|
72
72
|
toString(skip) {
|
|
73
|
-
if (skip && !this.parentNode?.getAttribute('built')) {
|
|
73
|
+
if (skip && !this.parentNode?.getAttribute('built')) { // eslint-disable-line unicorn/prefer-ternary
|
|
74
74
|
return (0, string_1.removeComment)(this.data);
|
|
75
75
|
}
|
|
76
76
|
return this.data;
|
|
@@ -249,7 +249,7 @@ class AstText extends node_1.AstNode {
|
|
|
249
249
|
if (!/(?:^|[^=])=+\s*(?:\S\s*)?$/u.test(line)) {
|
|
250
250
|
continue;
|
|
251
251
|
}
|
|
252
|
-
if (lineEnd === -1) {
|
|
252
|
+
else if (lineEnd === -1) {
|
|
253
253
|
endIndex = sibling.getAbsoluteIndex() + line.length;
|
|
254
254
|
({ top: endLine, left: endCol } = root.posFromIndex(endIndex));
|
|
255
255
|
}
|
|
@@ -322,8 +322,7 @@ class AstText extends node_1.AstNode {
|
|
|
322
322
|
*
|
|
323
323
|
* 将文本子节点分裂为两部分
|
|
324
324
|
* @param offset position to be splitted at / 分裂位置
|
|
325
|
-
* @throws `
|
|
326
|
-
* @throws `Error` 没有父节点
|
|
325
|
+
* @throws `Error` if the text node has no parent node
|
|
327
326
|
*/
|
|
328
327
|
splitText(offset) {
|
|
329
328
|
LSP: {
|
|
@@ -343,7 +342,7 @@ class AstText extends node_1.AstNode {
|
|
|
343
342
|
*
|
|
344
343
|
* 转义 `=` 和 `|`
|
|
345
344
|
* @since v1.1.4
|
|
346
|
-
* @throws `Error`
|
|
345
|
+
* @throws `Error` if the text node has no parent node
|
|
347
346
|
*/
|
|
348
347
|
escape() {
|
|
349
348
|
LSP: {
|
package/dist/parser/braces.js
CHANGED
|
@@ -57,8 +57,7 @@ const getSymbol = (s) => {
|
|
|
57
57
|
* @param wikitext
|
|
58
58
|
* @param config
|
|
59
59
|
* @param accum
|
|
60
|
-
* @throws `RangeError`
|
|
61
|
-
* @throws `TranscludeToken.constructor()`
|
|
60
|
+
* @throws `RangeError` if maximum iteration exceeded
|
|
62
61
|
*/
|
|
63
62
|
const parseBraces = (wikitext, config, accum) => {
|
|
64
63
|
const source = String.raw `${config.excludes.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, [, , , subst] = config.parserFunction, stack = [], linkStack = [];
|
|
@@ -91,7 +90,7 @@ const parseBraces = (wikitext, config, accum) => {
|
|
|
91
90
|
}
|
|
92
91
|
catch (e) {
|
|
93
92
|
/* c8 ignore next 3 */
|
|
94
|
-
if (!(e instanceof SyntaxError) || e.message !==
|
|
93
|
+
if (!(e instanceof SyntaxError) || e.message !== transclude_1.invalidTemplateMsg) {
|
|
95
94
|
throw e;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
@@ -170,7 +169,7 @@ const parseBraces = (wikitext, config, accum) => {
|
|
|
170
169
|
}
|
|
171
170
|
catch (e) {
|
|
172
171
|
/* c8 ignore next 3 */
|
|
173
|
-
if (!(e instanceof SyntaxError && e.message ===
|
|
172
|
+
if (!(e instanceof SyntaxError && e.message === transclude_1.invalidTemplateMsg)) {
|
|
174
173
|
throw e;
|
|
175
174
|
}
|
|
176
175
|
skip = true;
|
package/dist/src/attribute.js
CHANGED
|
@@ -99,7 +99,7 @@ class AttributeToken extends index_2.Token {
|
|
|
99
99
|
/** @private */
|
|
100
100
|
afterBuild() {
|
|
101
101
|
if (this.#equal.includes('\0')) {
|
|
102
|
-
this.#equal = this.buildFromStr(this.#equal,
|
|
102
|
+
this.#equal = this.buildFromStr(this.#equal, 0 /* BuildMethod.String */);
|
|
103
103
|
}
|
|
104
104
|
if (this.parentNode) {
|
|
105
105
|
this.#tag = this.parentNode.name;
|
|
@@ -178,19 +178,19 @@ class AttributeToken extends index_2.Token {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
else
|
|
182
|
-
||
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
181
|
+
else {
|
|
182
|
+
let valueIssue = (/^xmlns:[\w:.-]+$/u.test(name) || urlAttrs.has(name)) && evil.test(value)
|
|
183
|
+
|| simple
|
|
184
|
+
&& (name === 'href' || type === 'ext-attr' && tag === 'img' && name === 'src')
|
|
185
|
+
&& !new RegExp(String.raw `^(?:${this.getAttribute('config').protocol}|//)\S+$`, 'iu')
|
|
186
|
+
.test(value);
|
|
187
|
+
if (simple && !valueIssue && type !== 'ext-attr') {
|
|
188
|
+
const data = (0, lint_1.provideValues)(tag, name), v = value.toLowerCase();
|
|
189
|
+
if (data.length > 0 && data.every(n => n !== v)) {
|
|
190
|
+
valueIssue = true;
|
|
191
|
+
}
|
|
189
192
|
}
|
|
190
|
-
|
|
191
|
-
else if (simple && type !== 'ext-attr') {
|
|
192
|
-
const data = (0, lint_1.provideValues)(tag, name), v = value.toLowerCase();
|
|
193
|
-
if (data.length > 0 && data.every(n => n !== v)) {
|
|
193
|
+
if (valueIssue) {
|
|
194
194
|
LINT: {
|
|
195
195
|
const s = lintConfig.getSeverity(rule, 'value');
|
|
196
196
|
return s && (0, lint_1.generateForChild)(lastChild, rect, rule, 'illegal-attribute-value', s);
|
|
@@ -126,21 +126,22 @@ let ConverterFlagsToken = (() => {
|
|
|
126
126
|
const rect = new rect_1.BoundingRect(this, start), { childNodes, length } = this;
|
|
127
127
|
for (let i = length - 1; i >= 0; i--) {
|
|
128
128
|
const child = childNodes[i], flag = child.text().trim();
|
|
129
|
-
if (flag
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
129
|
+
if (!flag
|
|
130
|
+
|| variantFlags.has(flag.toLowerCase())
|
|
131
|
+
|| unknownFlags.has(flag)
|
|
132
|
+
|| variantFlags.size === 0 && definedFlags.has(flag)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const e = (0, lint_1.generateForChild)(child, rect, rule, 'invalid-conversion-flag', s);
|
|
136
|
+
if (computeEditInfo || fix) {
|
|
137
|
+
if (variantFlags.size === 0 && definedFlags.has(flag.toUpperCase())) {
|
|
138
|
+
e.fix = (0, lint_1.fixByUpper)(e, flag);
|
|
139
|
+
}
|
|
140
|
+
else if (computeEditInfo) {
|
|
141
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e, i && -1)];
|
|
141
142
|
}
|
|
142
|
-
errors.push(e);
|
|
143
143
|
}
|
|
144
|
+
errors.push(e);
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
return errors;
|
|
@@ -86,7 +86,7 @@ let ConverterRuleToken = (() => {
|
|
|
86
86
|
*/
|
|
87
87
|
constructor(rule, hasColon = true, config = index_1.default.getConfig(), accum = []) {
|
|
88
88
|
super(undefined, config, accum, {});
|
|
89
|
-
const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ?
|
|
89
|
+
const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = rule.slice(j === -1 ? 0 : j + 2, i);
|
|
90
90
|
if (hasColon && config.variants.includes(v.trim())) {
|
|
91
91
|
super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
|
|
92
92
|
super.insertAt(getRuleFromTo(rule.slice(i + 1), 'to', config, accum));
|
package/dist/src/extLink.js
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -113,6 +113,7 @@ class Token extends element_1.AstElement {
|
|
|
113
113
|
return this;
|
|
114
114
|
}
|
|
115
115
|
/* c8 ignore start */
|
|
116
|
+
// eslint-disable-next-line unicorn/prefer-combined-guards
|
|
116
117
|
if (this.#stage >= constants_1.MAX_STAGE) {
|
|
117
118
|
return this;
|
|
118
119
|
}
|
|
@@ -175,10 +176,10 @@ class Token extends element_1.AstElement {
|
|
|
175
176
|
const n = Number(s.slice(0, -1));
|
|
176
177
|
return this.#accum[n];
|
|
177
178
|
}).filter(node => node !== '');
|
|
178
|
-
if (type ===
|
|
179
|
+
if (type === 0 /* BuildMethod.String */) {
|
|
179
180
|
return nodes.map(String).join('');
|
|
180
181
|
}
|
|
181
|
-
else if (type ===
|
|
182
|
+
else if (type === 1 /* BuildMethod.Text */) {
|
|
182
183
|
return (0, string_1.text)(nodes);
|
|
183
184
|
}
|
|
184
185
|
return nodes;
|
package/dist/src/link/base.js
CHANGED
|
@@ -103,7 +103,7 @@ let LinkBaseToken = (() => {
|
|
|
103
103
|
afterBuild() {
|
|
104
104
|
this.#title = this.getTitle();
|
|
105
105
|
if (this.#delimiter.includes('\0')) {
|
|
106
|
-
this.#delimiter = this.buildFromStr(this.#delimiter,
|
|
106
|
+
this.#delimiter = this.buildFromStr(this.#delimiter, 0 /* BuildMethod.String */);
|
|
107
107
|
}
|
|
108
108
|
this.#setName();
|
|
109
109
|
super.afterBuild();
|
|
@@ -124,7 +124,7 @@ let LinkBaseToken = (() => {
|
|
|
124
124
|
/** @private */
|
|
125
125
|
toString(skip) {
|
|
126
126
|
const str = super.toString(skip, this.#delimiter);
|
|
127
|
-
if (this.#bracket) {
|
|
127
|
+
if (this.#bracket) { // eslint-disable-line unicorn/prefer-ternary
|
|
128
128
|
return `[[${str}]]`;
|
|
129
129
|
}
|
|
130
130
|
return str;
|
|
@@ -137,7 +137,7 @@ let LinkBaseToken = (() => {
|
|
|
137
137
|
'trim']()
|
|
138
138
|
: `${target.trim()}|${(0, string_1.text)(childNodes.slice(1)
|
|
139
139
|
.filter(({ type: t, name }) => t !== 'image-parameter' || name !== 'invalid'), '|')}`;
|
|
140
|
-
if (this.#bracket) {
|
|
140
|
+
if (this.#bracket) { // eslint-disable-line unicorn/prefer-ternary
|
|
141
141
|
return `[[${str}]]`;
|
|
142
142
|
}
|
|
143
143
|
return str;
|
|
@@ -80,10 +80,9 @@ let CategorytreeToken = (() => {
|
|
|
80
80
|
lint(start = this.getAbsoluteIndex()) {
|
|
81
81
|
LINT: {
|
|
82
82
|
const rule = 'no-ignored', s = index_1.default.lintConfig.getSeverity(rule, 'categorytree');
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return super.lint(start, false);
|
|
83
|
+
return s && this.#lint()
|
|
84
|
+
? [(0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-category', s)]
|
|
85
|
+
: super.lint(start, false);
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
88
|
/** 无效的分类名 */
|
package/dist/src/link/file.js
CHANGED
|
@@ -177,14 +177,15 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
177
177
|
...relevantArgs.slice(-1),
|
|
178
178
|
];
|
|
179
179
|
}
|
|
180
|
-
if (relevantArgs.length
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
if (relevantArgs.length < 2) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
let severity = !isCaption || !extension || constants_1.extensions.has(extension);
|
|
184
|
+
if (isCaption && severity) {
|
|
185
|
+
const plainArgs = filterArgs(relevantArgs, transclusion);
|
|
186
|
+
severity = plainArgs.length > 1 && ((arg) => plainArgs.includes(arg));
|
|
187
187
|
}
|
|
188
|
+
Array.prototype.push.apply(errors, generate(relevantArgs, 'duplicate', key, severity));
|
|
188
189
|
}
|
|
189
190
|
if (frameKeys.length > 1) {
|
|
190
191
|
Array.prototype.push.apply(errors, generate(args.filter(({ name }) => frame.has(name)), 'conflicting', 'frame'));
|
|
@@ -28,7 +28,7 @@ class GalleryToken extends index_2.MultiLineToken {
|
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
30
30
|
const [, file, alt] = matches;
|
|
31
|
-
if (this.#checkFile(file)) {
|
|
31
|
+
if (this.#checkFile(file)) { // eslint-disable-line unicorn/prefer-ternary
|
|
32
32
|
// @ts-expect-error abstract class
|
|
33
33
|
super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
|
|
34
34
|
}
|
|
@@ -55,5 +55,5 @@ export declare abstract class TableToken extends TrBaseToken {
|
|
|
55
55
|
* 获取第n行
|
|
56
56
|
* @param n row number / 行号
|
|
57
57
|
*/
|
|
58
|
-
getNthRow(n: number, force?: boolean, insert?: false): TrToken | this
|
|
58
|
+
getNthRow(n: number, force?: boolean, insert?: false): TrToken | this;
|
|
59
59
|
}
|
package/dist/src/table/td.js
CHANGED
|
@@ -43,7 +43,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
44
|
exports.TdToken = void 0;
|
|
45
45
|
const lint_1 = require("../../util/lint");
|
|
46
|
-
const constants_1 = require("../../util/constants");
|
|
47
46
|
const rect_1 = require("../../lib/rect");
|
|
48
47
|
const cached_1 = require("../../mixin/cached");
|
|
49
48
|
const index_1 = __importDefault(require("../../index"));
|
|
@@ -124,7 +123,7 @@ let TdToken = (() => {
|
|
|
124
123
|
/** @private */
|
|
125
124
|
afterBuild() {
|
|
126
125
|
if (this.#innerSyntax.includes('\0')) {
|
|
127
|
-
this.#innerSyntax = this.buildFromStr(this.#innerSyntax,
|
|
126
|
+
this.#innerSyntax = this.buildFromStr(this.#innerSyntax, 0 /* BuildMethod.String */);
|
|
128
127
|
}
|
|
129
128
|
super.afterBuild();
|
|
130
129
|
}
|
|
@@ -140,6 +139,7 @@ let TdToken = (() => {
|
|
|
140
139
|
}
|
|
141
140
|
/** @private */
|
|
142
141
|
getGaps(i) {
|
|
142
|
+
// eslint-disable-next-line unicorn/prefer-ternary
|
|
143
143
|
if (i === 1) {
|
|
144
144
|
return this.#innerSyntax.length;
|
|
145
145
|
}
|