wikiparser-node 1.24.1 → 1.25.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 +9 -4
- package/bundle/bundle-es8.min.js +24 -23
- package/bundle/bundle-lsp.min.js +28 -27
- package/bundle/bundle.min.js +25 -25
- package/dist/addon/token.js +1 -1
- package/dist/base.d.mts +2 -1
- package/dist/base.d.ts +2 -1
- package/dist/bin/config.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +85 -55
- package/dist/lib/element.js +33 -29
- package/dist/lib/text.js +174 -171
- package/dist/mixin/hidden.js +1 -1
- package/dist/mixin/noEscape.js +9 -7
- package/dist/parser/links.js +10 -4
- package/dist/src/arg.js +39 -33
- package/dist/src/attribute.js +52 -38
- package/dist/src/attributes.js +54 -51
- package/dist/src/commented.js +2 -1
- package/dist/src/converterFlags.js +20 -18
- package/dist/src/converterRule.js +6 -3
- package/dist/src/extLink.js +6 -4
- package/dist/src/gallery.js +48 -42
- package/dist/src/heading.js +65 -61
- package/dist/src/html.js +75 -71
- package/dist/src/imageParameter.js +17 -15
- package/dist/src/imagemap.js +20 -18
- package/dist/src/index.js +100 -99
- package/dist/src/link/base.js +38 -33
- package/dist/src/link/category.js +11 -6
- package/dist/src/link/file.js +87 -76
- package/dist/src/link/galleryImage.js +8 -6
- package/dist/src/link/index.js +8 -6
- package/dist/src/link/redirectTarget.js +10 -8
- package/dist/src/magicLink.js +22 -20
- package/dist/src/nested.js +29 -27
- package/dist/src/nowiki/comment.js +11 -9
- package/dist/src/nowiki/index.js +9 -7
- package/dist/src/nowiki/listBase.js +8 -5
- package/dist/src/nowiki/quote.js +29 -25
- package/dist/src/paramTag/index.js +24 -22
- package/dist/src/parameter.js +29 -23
- package/dist/src/pre.js +1 -1
- package/dist/src/redirect.js +5 -3
- package/dist/src/syntax.js +1 -1
- package/dist/src/table/index.js +35 -31
- package/dist/src/table/td.js +24 -19
- package/dist/src/table/trBase.js +13 -11
- package/dist/src/tagPair/ext.js +13 -10
- package/dist/src/tagPair/include.js +13 -11
- package/dist/src/transclude.js +39 -37
- package/dist/util/constants.js +3 -1
- package/dist/util/lint.js +12 -9
- package/extensions/dist/base.js +4 -1
- package/i18n/en.json +77 -0
- package/i18n/zh-hans.json +71 -56
- package/i18n/zh-hant.json +71 -56
- package/package.json +2 -2
package/dist/lib/text.js
CHANGED
|
@@ -52,13 +52,13 @@ const constants_1 = require("../util/constants");
|
|
|
52
52
|
const readOnly_1 = require("../mixin/readOnly");
|
|
53
53
|
const cached_1 = require("../mixin/cached");
|
|
54
54
|
/* NOT FOR BROWSER END */
|
|
55
|
-
const sp = String.raw `[${string_1.zs}\t]
|
|
55
|
+
const sp = /* #__PURE__ */ (() => String.raw `[${string_1.zs}\t]*`)(), anySp = /* #__PURE__ */ (() => String.raw `[^\S\n]*`)(), source = /* #__PURE__ */ (() => String.raw `<${anySp}(?:/${anySp})?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|(?:rfc|pmid)(?=[-::]?${sp}\d)|isbn(?=[-::]?${sp}(?:\d(?:${sp}|-)){6})`)();
|
|
56
56
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
57
57
|
/<[^\S\n]*(?:\/[^\S\n]*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu;
|
|
58
|
-
const errorSyntax = new RegExp(String.raw `${source}|https?[:/]/+`, 'giu');
|
|
58
|
+
const errorSyntax = /* #__PURE__ */ (() => new RegExp(String.raw `${source}|https?[:/]/+`, 'giu'))();
|
|
59
59
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
60
60
|
/^https?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\t\n\p{Zs}]*\.(?:gif|png|jpg|jpeg)$/iu;
|
|
61
|
-
const errorSyntaxUrl = new RegExp(source, 'giu'), noLinkTypes = new Set(['attr-value', 'ext-link-text', 'link-text']), regexes = {
|
|
61
|
+
const errorSyntaxUrl = /* #__PURE__ */ new RegExp(source, 'giu'), noLinkTypes = new Set(['attr-value', 'ext-link-text', 'link-text']), regexes = {
|
|
62
62
|
'[': /[[\]]/u,
|
|
63
63
|
'{': /[{}]/u,
|
|
64
64
|
']': /[[\]](?=[^[\]]*$)/u,
|
|
@@ -115,14 +115,15 @@ const errorSyntaxUrl = new RegExp(source, 'giu'), noLinkTypes = new Set(['attr-v
|
|
|
115
115
|
'param',
|
|
116
116
|
'xmp',
|
|
117
117
|
]);
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
catch /* istanbul ignore next */ {
|
|
124
|
-
|
|
125
|
-
}
|
|
118
|
+
const wordRegex = /* #__PURE__ */ (() => {
|
|
119
|
+
try {
|
|
120
|
+
// eslint-disable-next-line prefer-regex-literals
|
|
121
|
+
return new RegExp(String.raw `[\p{L}\p{N}_]`, 'u');
|
|
122
|
+
}
|
|
123
|
+
catch /* istanbul ignore next */ {
|
|
124
|
+
return /\w/u;
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
126
127
|
/**
|
|
127
128
|
* text node
|
|
128
129
|
*
|
|
@@ -191,184 +192,186 @@ let AstText = (() => {
|
|
|
191
192
|
}
|
|
192
193
|
/** @private */
|
|
193
194
|
lint(start = this.getAbsoluteIndex(), errorRegex) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
const { data, parentNode, nextSibling, previousSibling } = this;
|
|
198
|
-
/* istanbul ignore if */
|
|
199
|
-
if (!parentNode) {
|
|
200
|
-
throw new Error('An isolated text node cannot be linted!');
|
|
201
|
-
}
|
|
202
|
-
const { type, name, parentNode: grandparent } = parentNode;
|
|
203
|
-
if (type === 'attr-value') {
|
|
204
|
-
const { name: grandName, tag } = grandparent;
|
|
205
|
-
if (tag === 'ref' && (grandName === 'name' || grandName === 'follow')
|
|
206
|
-
|| grandName === 'group' && (tag === 'ref' || tag === 'references')
|
|
207
|
-
|| tag === 'choose' && (grandName === 'before' || grandName === 'after')) {
|
|
195
|
+
LINT: { // eslint-disable-line no-unused-labels
|
|
196
|
+
if (errorRegex === false) {
|
|
208
197
|
return [];
|
|
209
198
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|| type === 'image-parameter' && name === 'link'
|
|
215
|
-
|| type === 'attr-value'
|
|
216
|
-
? errorSyntaxUrl
|
|
217
|
-
: errorSyntax;
|
|
218
|
-
if (data.search(errorRegex) === -1) {
|
|
219
|
-
return [];
|
|
220
|
-
}
|
|
221
|
-
errorRegex.lastIndex = 0;
|
|
222
|
-
const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), rootStr = root.toString(), { ext, html, variants } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), lintConfig = index_1.default.lintConfig['tag-like'], specified = typeof lintConfig === 'number'
|
|
223
|
-
? new Set()
|
|
224
|
-
: new Set(Object.keys(lintConfig[1]).filter(tag => tag !== 'invalid' && tag !== 'disallowed')), tags = new Set([
|
|
225
|
-
'onlyinclude',
|
|
226
|
-
'noinclude',
|
|
227
|
-
'includeonly',
|
|
228
|
-
...ext,
|
|
229
|
-
...html[0],
|
|
230
|
-
...html[1],
|
|
231
|
-
...html[2],
|
|
232
|
-
...specified,
|
|
233
|
-
...disallowedTags,
|
|
234
|
-
]);
|
|
235
|
-
for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
|
|
236
|
-
const [, tag, prefix] = mt;
|
|
237
|
-
let { index, 0: error } = mt;
|
|
238
|
-
if (prefix && prefix !== ']') {
|
|
239
|
-
const { length } = prefix;
|
|
240
|
-
index += length;
|
|
241
|
-
error = error.slice(length);
|
|
242
|
-
}
|
|
243
|
-
error = error.toLowerCase();
|
|
244
|
-
const [char] = error, magicLink = char === 'r' || char === 'p' || char === 'i', lbrace = char === '{', rbrace = char === '}', lbrack = char === '[', rbrack = char === ']';
|
|
245
|
-
let { length } = error;
|
|
246
|
-
if (char === '<' && !tags.has(tag.toLowerCase())
|
|
247
|
-
|| lbrack && type === 'ext-link-text' && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
248
|
-
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
249
|
-
&& nextSibling.innerText?.includes(']'))
|
|
250
|
-
|| magicLink && (!parentNode.isPlain() || noLinkTypes.has(type))) {
|
|
251
|
-
continue;
|
|
199
|
+
const { data, parentNode, nextSibling, previousSibling } = this;
|
|
200
|
+
/* istanbul ignore if */
|
|
201
|
+
if (!parentNode) {
|
|
202
|
+
throw new Error('An isolated text node cannot be linted!');
|
|
252
203
|
}
|
|
253
|
-
|
|
254
|
-
|
|
204
|
+
const { type, name, parentNode: grandparent } = parentNode;
|
|
205
|
+
if (type === 'attr-value') {
|
|
206
|
+
const { name: grandName, tag } = grandparent;
|
|
207
|
+
if (tag === 'ref' && (grandName === 'name' || grandName === 'follow')
|
|
208
|
+
|| grandName === 'group' && (tag === 'ref' || tag === 'references')
|
|
209
|
+
|| tag === 'choose' && (grandName === 'before' || grandName === 'after')) {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
255
212
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
||
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
213
|
+
errorRegex ??= type === 'free-ext-link'
|
|
214
|
+
|| type === 'ext-link-url'
|
|
215
|
+
|| type === 'ext-link-text'
|
|
216
|
+
|| type === 'image-parameter' && name === 'link'
|
|
217
|
+
|| type === 'attr-value'
|
|
218
|
+
? errorSyntaxUrl
|
|
219
|
+
: errorSyntax;
|
|
220
|
+
if (data.search(errorRegex) === -1) {
|
|
221
|
+
return [];
|
|
265
222
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
223
|
+
errorRegex.lastIndex = 0;
|
|
224
|
+
const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), rootStr = root.toString(), { ext, html, variants } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), lintConfig = index_1.default.lintConfig['tag-like'], specified = typeof lintConfig === 'number'
|
|
225
|
+
? new Set()
|
|
226
|
+
: new Set(Object.keys(lintConfig[1]).filter(tag => tag !== 'invalid' && tag !== 'disallowed')), tags = new Set([
|
|
227
|
+
'onlyinclude',
|
|
228
|
+
'noinclude',
|
|
229
|
+
'includeonly',
|
|
230
|
+
...ext,
|
|
231
|
+
...html[0],
|
|
232
|
+
...html[1],
|
|
233
|
+
...html[2],
|
|
234
|
+
...specified,
|
|
235
|
+
...disallowedTags,
|
|
236
|
+
]);
|
|
237
|
+
for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
|
|
238
|
+
const [, tag, prefix] = mt;
|
|
239
|
+
let { index, 0: error } = mt;
|
|
240
|
+
if (prefix && prefix !== ']') {
|
|
241
|
+
const { length } = prefix;
|
|
242
|
+
index += length;
|
|
243
|
+
error = error.slice(length);
|
|
271
244
|
}
|
|
272
|
-
|
|
273
|
-
|
|
245
|
+
error = error.toLowerCase();
|
|
246
|
+
const [char] = error, magicLink = char === 'r' || char === 'p' || char === 'i', lbrace = char === '{', rbrace = char === '}', lbrack = char === '[', rbrack = char === ']';
|
|
247
|
+
let { length } = error;
|
|
248
|
+
if (char === '<' && !tags.has(tag.toLowerCase())
|
|
249
|
+
|| lbrack && type === 'ext-link-text' && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
250
|
+
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
251
|
+
&& nextSibling.innerText?.includes(']'))
|
|
252
|
+
|| magicLink && (!parentNode.isPlain() || noLinkTypes.has(type))) {
|
|
253
|
+
continue;
|
|
274
254
|
}
|
|
275
|
-
else if (
|
|
276
|
-
|
|
255
|
+
else if (rbrack && (index || length > 1)) {
|
|
256
|
+
errorRegex.lastIndex--;
|
|
277
257
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
length = 2;
|
|
258
|
+
// Rule & Severity
|
|
259
|
+
let startIndex = start + index, endIndex = startIndex + length, rule, severity;
|
|
260
|
+
const nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], leftBracket = lbrace || lbrack, lConverter = lbrace && previousChar === '-' && variants.length > 0, rConverter = rbrace && nextChar === '-' && variants.length > 0, brokenExtLink = lbrack && nextType === 'free-ext-link' && !data.slice(index + 1).trim()
|
|
261
|
+
|| rbrack && previousType === 'free-ext-link'
|
|
262
|
+
&& !data.slice(0, index).includes(']');
|
|
263
|
+
if (magicLink) {
|
|
264
|
+
rule = 'lonely-http';
|
|
265
|
+
error = error.toUpperCase();
|
|
266
|
+
severity = index_1.default.lintConfig.getSeverity(rule, error);
|
|
288
267
|
}
|
|
289
|
-
else if (
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
268
|
+
else if (char === '<') {
|
|
269
|
+
rule = 'tag-like';
|
|
270
|
+
let key;
|
|
271
|
+
if (/^<\/?\s/u.test(error) || !/[\s/>]/u.test(nextChar ?? '')) {
|
|
272
|
+
key = 'invalid';
|
|
273
|
+
}
|
|
274
|
+
else if (specified.has(tag)) {
|
|
275
|
+
key = tag;
|
|
276
|
+
}
|
|
277
|
+
else if (disallowedTags.has(tag) && !ext.includes(tag)) {
|
|
278
|
+
key = 'disallowed';
|
|
279
|
+
}
|
|
280
|
+
severity = index_1.default.lintConfig.getSeverity(rule, key);
|
|
293
281
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
282
|
+
else if (lConverter || rConverter) {
|
|
283
|
+
rule = 'lonely-bracket';
|
|
284
|
+
severity = index_1.default.lintConfig.getSeverity(rule, 'converter');
|
|
285
|
+
if (lConverter && index > 0) {
|
|
286
|
+
error = '-{';
|
|
287
|
+
index--;
|
|
288
|
+
startIndex--;
|
|
289
|
+
length = 2;
|
|
290
|
+
}
|
|
291
|
+
else if (rConverter && index < data.length - 1) {
|
|
292
|
+
error = '}-';
|
|
293
|
+
endIndex++;
|
|
294
|
+
length = 2;
|
|
295
|
+
}
|
|
303
296
|
}
|
|
304
|
-
else {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
297
|
+
else if (brokenExtLink) {
|
|
298
|
+
rule = 'lonely-bracket';
|
|
299
|
+
severity = index_1.default.lintConfig.getSeverity(rule, 'extLink');
|
|
300
|
+
}
|
|
301
|
+
else if (leftBracket || rbrace || rbrack) {
|
|
302
|
+
rule = 'lonely-bracket';
|
|
303
|
+
if (length > 1 || lbrace && nextChar === char || rbrace && previousChar === char) {
|
|
304
|
+
severity = index_1.default.lintConfig.getSeverity(rule, 'double');
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
if (!lbrack || type !== 'ext-link-text') {
|
|
308
|
+
const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
|
|
309
|
+
if (lbrace && regex.exec(remains)?.[0] === '}'
|
|
310
|
+
|| rbrace && regex.exec(remains)?.[0] === '{') {
|
|
318
311
|
continue;
|
|
319
312
|
}
|
|
313
|
+
else if (!remains.includes(char)) {
|
|
314
|
+
const sibling = leftBracket ? 'nextSibling' : 'previousSibling';
|
|
315
|
+
let cur = this[sibling];
|
|
316
|
+
while (cur && (cur.type !== 'text' || !regex.test(cur.data))) {
|
|
317
|
+
cur = cur[sibling];
|
|
318
|
+
}
|
|
319
|
+
if (cur && regex.exec(cur.data)[0] !== char) {
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
320
323
|
}
|
|
324
|
+
severity = index_1.default.lintConfig.getSeverity(rule, 'single');
|
|
321
325
|
}
|
|
322
|
-
severity = index_1.default.lintConfig.getSeverity(rule, 'single');
|
|
323
326
|
}
|
|
327
|
+
else {
|
|
328
|
+
rule = 'lonely-http';
|
|
329
|
+
severity = index_1.default.lintConfig.getSeverity(rule);
|
|
330
|
+
}
|
|
331
|
+
if (!severity) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
// LintError
|
|
335
|
+
const pos = this.posFromIndex(index), { line: startLine, character: startCol } = (0, lint_1.getEndPos)(top, left, pos.top + 1, pos.left), e = {
|
|
336
|
+
rule,
|
|
337
|
+
message: index_1.default.msg('lonely', magicLink || char === 'h' || lConverter || rConverter ? error : char),
|
|
338
|
+
severity,
|
|
339
|
+
startIndex,
|
|
340
|
+
endIndex,
|
|
341
|
+
startLine,
|
|
342
|
+
endLine: startLine,
|
|
343
|
+
startCol,
|
|
344
|
+
endCol: startCol + length,
|
|
345
|
+
};
|
|
346
|
+
// Suggestions
|
|
347
|
+
if (char === '<') {
|
|
348
|
+
e.suggestions = [(0, lint_1.fixByEscape)(startIndex, '<')];
|
|
349
|
+
}
|
|
350
|
+
else if (char === 'h' && type !== 'link-text' && wordRegex.test(previousChar || '')) {
|
|
351
|
+
e.suggestions = [(0, lint_1.fixBySpace)(startIndex)];
|
|
352
|
+
}
|
|
353
|
+
else if (lbrack && type === 'ext-link-text') {
|
|
354
|
+
const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
|
|
355
|
+
e.suggestions = [(0, lint_1.fixByEscape)(i, ']')];
|
|
356
|
+
}
|
|
357
|
+
else if (rbrack && brokenExtLink) {
|
|
358
|
+
const i = start - previousSibling.toString().length;
|
|
359
|
+
e.suggestions = [(0, lint_1.fixByInsert)(i, 'left-bracket', '[')];
|
|
360
|
+
}
|
|
361
|
+
else if (magicLink) {
|
|
362
|
+
e.suggestions = [
|
|
363
|
+
...mt[0] === error
|
|
364
|
+
? []
|
|
365
|
+
: [(0, lint_1.fixByUpper)(e, error)],
|
|
366
|
+
...nextChar === ':' || nextChar === ':'
|
|
367
|
+
? [(0, lint_1.fixBySpace)(endIndex, 1)]
|
|
368
|
+
: [],
|
|
369
|
+
];
|
|
370
|
+
}
|
|
371
|
+
errors.push(e);
|
|
324
372
|
}
|
|
325
|
-
|
|
326
|
-
rule = 'lonely-http';
|
|
327
|
-
severity = index_1.default.lintConfig.getSeverity(rule);
|
|
328
|
-
}
|
|
329
|
-
if (!severity) {
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
// LintError
|
|
333
|
-
const pos = this.posFromIndex(index), { line: startLine, character: startCol } = (0, lint_1.getEndPos)(top, left, pos.top + 1, pos.left), e = {
|
|
334
|
-
rule,
|
|
335
|
-
message: index_1.default.msg('lonely "$1"', magicLink || char === 'h' || lConverter || rConverter ? error : char),
|
|
336
|
-
severity,
|
|
337
|
-
startIndex,
|
|
338
|
-
endIndex,
|
|
339
|
-
startLine,
|
|
340
|
-
endLine: startLine,
|
|
341
|
-
startCol,
|
|
342
|
-
endCol: startCol + length,
|
|
343
|
-
};
|
|
344
|
-
// Suggestions
|
|
345
|
-
if (char === '<') {
|
|
346
|
-
e.suggestions = [(0, lint_1.fixByEscape)(startIndex, '<')];
|
|
347
|
-
}
|
|
348
|
-
else if (char === 'h' && type !== 'link-text' && wordRegex.test(previousChar || '')) {
|
|
349
|
-
e.suggestions = [(0, lint_1.fixBySpace)(startIndex)];
|
|
350
|
-
}
|
|
351
|
-
else if (lbrack && type === 'ext-link-text') {
|
|
352
|
-
const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
|
|
353
|
-
e.suggestions = [(0, lint_1.fixByEscape)(i, ']')];
|
|
354
|
-
}
|
|
355
|
-
else if (rbrack && brokenExtLink) {
|
|
356
|
-
const i = start - previousSibling.toString().length;
|
|
357
|
-
e.suggestions = [(0, lint_1.fixByInsert)(i, 'left bracket', '[')];
|
|
358
|
-
}
|
|
359
|
-
else if (magicLink) {
|
|
360
|
-
e.suggestions = [
|
|
361
|
-
...mt[0] === error
|
|
362
|
-
? []
|
|
363
|
-
: [(0, lint_1.fixByUpper)(e, error)],
|
|
364
|
-
...nextChar === ':' || nextChar === ':'
|
|
365
|
-
? [(0, lint_1.fixBySpace)(endIndex, 1)]
|
|
366
|
-
: [],
|
|
367
|
-
];
|
|
368
|
-
}
|
|
369
|
-
errors.push(e);
|
|
373
|
+
return errors;
|
|
370
374
|
}
|
|
371
|
-
return errors;
|
|
372
375
|
}
|
|
373
376
|
/**
|
|
374
377
|
* 修改内容
|
package/dist/mixin/hidden.js
CHANGED
|
@@ -64,7 +64,7 @@ const hiddenToken = (linter = true, html = true) => (constructor) => {
|
|
|
64
64
|
}
|
|
65
65
|
lint(start) {
|
|
66
66
|
// @ts-expect-error private argument
|
|
67
|
-
return linter ? [] : super.lint(start);
|
|
67
|
+
LINT: return linter ? [] : super.lint(start); // eslint-disable-line no-unused-labels
|
|
68
68
|
}
|
|
69
69
|
/* NOT FOR BROWSER */
|
|
70
70
|
dispatchEvent() {
|
package/dist/mixin/noEscape.js
CHANGED
|
@@ -10,15 +10,17 @@ const constants_1 = require("../util/constants");
|
|
|
10
10
|
* @ignore
|
|
11
11
|
*/
|
|
12
12
|
const noEscape = (constructor) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
LSP: { // eslint-disable-line no-unused-labels
|
|
14
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
15
|
+
class NoEscapeToken extends constructor {
|
|
16
|
+
escape() {
|
|
17
|
+
//
|
|
18
|
+
}
|
|
17
19
|
}
|
|
20
|
+
/* eslint-enable jsdoc/require-jsdoc */
|
|
21
|
+
(0, debug_1.mixin)(NoEscapeToken, constructor);
|
|
22
|
+
return NoEscapeToken;
|
|
18
23
|
}
|
|
19
|
-
/* eslint-enable jsdoc/require-jsdoc */
|
|
20
|
-
(0, debug_1.mixin)(NoEscapeToken, constructor);
|
|
21
|
-
return NoEscapeToken;
|
|
22
24
|
};
|
|
23
25
|
exports.noEscape = noEscape;
|
|
24
26
|
constants_1.mixins['noEscape'] = __filename;
|
package/dist/parser/links.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseLinks = void 0;
|
|
7
|
+
const string_1 = require("../util/string");
|
|
7
8
|
const index_1 = __importDefault(require("../index"));
|
|
8
9
|
const quotes_1 = require("./quotes");
|
|
9
10
|
const externalLinks_1 = require("./externalLinks");
|
|
@@ -24,9 +25,9 @@ const regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)([\s\S]*)$/u;
|
|
|
24
25
|
const parseLinks = (wikitext, config, accum, tidy) => {
|
|
25
26
|
/^\s*(?:ftp:\/\/|\/\/)/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
|
|
26
27
|
config.regexLinks ??= new RegExp(String.raw `^\s*(?:${config.protocol}|//)`, 'iu');
|
|
27
|
-
const regex =
|
|
28
|
+
const regex = config.inExt
|
|
28
29
|
? /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)([\s\S]*?[^\]]))?\]\]([\s\S]*)$/u
|
|
29
|
-
: /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])
|
|
30
|
+
: /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])*)(?:(\||\0\d+!\x7F)([\s\S]*?[^\]])?)?\]\]([\s\S]*)$/u, bits = wikitext.split('[[');
|
|
30
31
|
let s = bits.shift();
|
|
31
32
|
for (let i = 0; i < bits.length; i++) {
|
|
32
33
|
let mightBeImg = false, link, delimiter, text, after;
|
|
@@ -49,14 +50,16 @@ const parseLinks = (wikitext, config, accum, tidy) => {
|
|
|
49
50
|
s += `[[${x}`;
|
|
50
51
|
continue;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
// eslint-disable-next-line prefer-const
|
|
54
|
+
let trimmed = (0, string_1.removeComment)(link).trim();
|
|
55
|
+
const force = trimmed.startsWith(':');
|
|
53
56
|
if (force && mightBeImg) {
|
|
54
57
|
s += `[[${x}`;
|
|
55
58
|
continue;
|
|
56
59
|
}
|
|
57
60
|
const { ns, valid,
|
|
58
61
|
/* NOT FOR BROWSER */
|
|
59
|
-
interwiki, } = index_1.default.normalizeTitle(
|
|
62
|
+
interwiki, } = index_1.default.normalizeTitle(trimmed, 0, false, config, { halfParsed: true, temporary: true, decode: true, selfLink: true });
|
|
60
63
|
if (!valid) {
|
|
61
64
|
s += `[[${x}`;
|
|
62
65
|
continue;
|
|
@@ -103,6 +106,9 @@ const parseLinks = (wikitext, config, accum, tidy) => {
|
|
|
103
106
|
SomeLinkToken = category_1.CategoryToken;
|
|
104
107
|
}
|
|
105
108
|
}
|
|
109
|
+
if (text === undefined && delimiter) {
|
|
110
|
+
text = '';
|
|
111
|
+
}
|
|
106
112
|
s += `\0${accum.length}l\x7F${after}`;
|
|
107
113
|
// @ts-expect-error abstract class
|
|
108
114
|
new SomeLinkToken(link, text, config, accum, delimiter);
|
package/dist/src/arg.js
CHANGED
|
@@ -82,10 +82,12 @@ let ArgToken = (() => {
|
|
|
82
82
|
get type() {
|
|
83
83
|
return 'arg';
|
|
84
84
|
}
|
|
85
|
+
/* PRINT ONLY */
|
|
85
86
|
/** default value / 预设值 */
|
|
86
87
|
get default() {
|
|
87
|
-
return this.childNodes[1]?.text() ?? false;
|
|
88
|
+
LSP: return this.childNodes[1]?.text() ?? false; // eslint-disable-line no-unused-labels
|
|
88
89
|
}
|
|
90
|
+
/* PRINT ONLY END */
|
|
89
91
|
/* NOT FOR BROWSER */
|
|
90
92
|
set default(value) {
|
|
91
93
|
this.setDefault(value);
|
|
@@ -147,39 +149,41 @@ let ArgToken = (() => {
|
|
|
147
149
|
}
|
|
148
150
|
/** @private */
|
|
149
151
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const index = start + 4 + argName.toString().length;
|
|
155
|
-
argDefault.setAttribute('aIndex', index);
|
|
156
|
-
const childErrors = argDefault.lint(index, re);
|
|
157
|
-
if (childErrors.length > 0) {
|
|
158
|
-
errors.push(...childErrors);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const rules = ['no-ignored', 'no-arg'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule, 'arg'));
|
|
162
|
-
if (s[0] && rest.length > 0) {
|
|
163
|
-
const rect = new rect_1.BoundingRect(this, start);
|
|
164
|
-
errors.push(...rest.map(child => {
|
|
165
|
-
const e = (0, lint_1.generateForChild)(child, rect, rules[0], 'invisible content inside triple braces', s[0]);
|
|
166
|
-
e.startIndex--;
|
|
167
|
-
e.startCol--;
|
|
168
|
-
e.suggestions = [
|
|
169
|
-
(0, lint_1.fixByRemove)(e),
|
|
170
|
-
(0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
|
|
171
|
-
];
|
|
172
|
-
return e;
|
|
173
|
-
}));
|
|
174
|
-
}
|
|
175
|
-
if (s[1] && !this.getAttribute('include')) {
|
|
176
|
-
const e = (0, lint_1.generateForSelf)(this, { start }, rules[1], 'unexpected template argument', s[1]);
|
|
152
|
+
LINT: { // eslint-disable-line no-unused-labels
|
|
153
|
+
const { childNodes: [argName, argDefault, ...rest] } = this;
|
|
154
|
+
argName.setAttribute('aIndex', start + 3);
|
|
155
|
+
const errors = argName.lint(start + 3, re);
|
|
177
156
|
if (argDefault) {
|
|
178
|
-
|
|
157
|
+
const index = start + 4 + argName.toString().length;
|
|
158
|
+
argDefault.setAttribute('aIndex', index);
|
|
159
|
+
const childErrors = argDefault.lint(index, re);
|
|
160
|
+
if (childErrors.length > 0) {
|
|
161
|
+
errors.push(...childErrors);
|
|
162
|
+
}
|
|
179
163
|
}
|
|
180
|
-
|
|
164
|
+
const rules = ['no-ignored', 'no-arg'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule, 'arg'));
|
|
165
|
+
if (s[0] && rest.length > 0) {
|
|
166
|
+
const rect = new rect_1.BoundingRect(this, start);
|
|
167
|
+
errors.push(...rest.map(child => {
|
|
168
|
+
const e = (0, lint_1.generateForChild)(child, rect, rules[0], 'invisible-triple-braces', s[0]);
|
|
169
|
+
e.startIndex--;
|
|
170
|
+
e.startCol--;
|
|
171
|
+
e.suggestions = [
|
|
172
|
+
(0, lint_1.fixByRemove)(e),
|
|
173
|
+
(0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
|
|
174
|
+
];
|
|
175
|
+
return e;
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
if (s[1] && !this.getAttribute('include')) {
|
|
179
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, rules[1], 'unexpected-argument', s[1]);
|
|
180
|
+
if (argDefault) {
|
|
181
|
+
e.suggestions = [(0, lint_1.fixBy)(e, 'expand', argDefault.text())];
|
|
182
|
+
}
|
|
183
|
+
errors.push(e);
|
|
184
|
+
}
|
|
185
|
+
return errors;
|
|
181
186
|
}
|
|
182
|
-
return errors;
|
|
183
187
|
}
|
|
184
188
|
/** @private */
|
|
185
189
|
print() {
|
|
@@ -188,8 +192,10 @@ let ArgToken = (() => {
|
|
|
188
192
|
/** @private */
|
|
189
193
|
json(_, start = this.getAbsoluteIndex()) {
|
|
190
194
|
const json = super.json(undefined, start);
|
|
191
|
-
|
|
192
|
-
|
|
195
|
+
LSP: { // eslint-disable-line no-unused-labels
|
|
196
|
+
json['default'] = this.default;
|
|
197
|
+
return json;
|
|
198
|
+
}
|
|
193
199
|
}
|
|
194
200
|
/* NOT FOR BROWSER */
|
|
195
201
|
cloneNode() {
|