wikilint 2.23.0 → 2.25.0
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 +3 -3
- package/bin/config.js +2 -2
- package/config/default.json +6 -0
- package/config/enwiki.json +2 -2
- package/config/llwiki.json +382 -261
- package/config/moegirl.json +325 -325
- package/coverage/badge.svg +1 -1
- package/dist/base.d.mts +20 -2
- package/dist/base.d.ts +20 -2
- package/dist/bin/config.js +17 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.js +32 -12
- package/dist/lib/element.d.ts +0 -7
- package/dist/lib/element.js +7 -13
- package/dist/lib/lintConfig.js +0 -3
- package/dist/lib/lsp.d.ts +19 -1
- package/dist/lib/lsp.js +130 -15
- package/dist/lib/text.d.ts +17 -0
- package/dist/lib/text.js +73 -11
- package/dist/lib/title.js +3 -2
- package/dist/mixin/attributesParent.js +1 -1
- package/dist/mixin/elementLike.d.ts +7 -0
- package/dist/mixin/elementLike.js +7 -0
- package/dist/mixin/noEscape.d.ts +4 -0
- package/dist/mixin/noEscape.js +20 -0
- package/dist/parser/commentAndExt.js +7 -8
- package/dist/parser/externalLinks.js +1 -1
- package/dist/parser/hrAndDoubleUnderscore.js +8 -5
- package/dist/src/arg.js +7 -6
- package/dist/src/attribute.d.ts +1 -0
- package/dist/src/attribute.js +18 -13
- package/dist/src/attributes.js +6 -6
- package/dist/src/converter.js +2 -1
- package/dist/src/converterFlags.js +3 -3
- package/dist/src/extLink.js +1 -1
- package/dist/src/gallery.js +9 -8
- package/dist/src/heading.js +158 -98
- package/dist/src/html.js +20 -18
- package/dist/src/imageParameter.js +4 -4
- package/dist/src/imagemap.js +4 -4
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +2 -2
- package/dist/src/link/base.js +9 -22
- package/dist/src/link/file.js +18 -8
- package/dist/src/link/galleryImage.js +2 -2
- package/dist/src/link/index.d.ts +2 -0
- package/dist/src/link/index.js +10 -1
- package/dist/src/link/redirectTarget.js +2 -2
- package/dist/src/magicLink.js +5 -5
- package/dist/src/nested.js +3 -3
- package/dist/src/nowiki/base.js +61 -10
- package/dist/src/nowiki/comment.js +2 -2
- package/dist/src/nowiki/index.js +3 -3
- package/dist/src/nowiki/quote.js +11 -11
- package/dist/src/onlyinclude.js +2 -1
- package/dist/src/paramTag/index.js +2 -2
- package/dist/src/parameter.js +2 -2
- package/dist/src/redirect.js +2 -1
- package/dist/src/table/base.d.ts +2 -0
- package/dist/src/table/base.js +30 -2
- package/dist/src/table/index.js +4 -5
- package/dist/src/table/td.d.ts +1 -0
- package/dist/src/table/td.js +14 -13
- package/dist/src/table/trBase.js +1 -1
- package/dist/src/tagPair/ext.js +2 -2
- package/dist/src/tagPair/include.js +4 -4
- package/dist/src/tagPair/index.js +2 -1
- package/dist/src/transclude.js +13 -18
- package/dist/util/constants.js +2 -1
- package/dist/util/lint.js +91 -2
- package/dist/util/sharable.js +1 -1
- package/dist/util/sharable.mjs +1 -1
- package/dist/util/string.js +11 -10
- package/i18n/en.json +77 -0
- package/i18n/zh-hans.json +71 -56
- package/i18n/zh-hant.json +71 -56
- package/package.json +8 -9
|
@@ -37,10 +37,10 @@ class RedirectTargetToken extends base_1.LinkBaseToken {
|
|
|
37
37
|
lint(start = this.getAbsoluteIndex()) {
|
|
38
38
|
const errors = super.lint(start, false), rule = 'no-ignored', s = index_1.default.lintConfig.getSeverity(rule, 'redirect');
|
|
39
39
|
if (s && this.length === 2) {
|
|
40
|
-
const e = (0, lint_1.generateForChild)(this.lastChild, { start }, rule, 'useless
|
|
40
|
+
const e = (0, lint_1.generateForChild)(this.lastChild, { start }, rule, 'useless-link-text', s);
|
|
41
41
|
e.startIndex--;
|
|
42
42
|
e.startCol--;
|
|
43
|
-
e.fix =
|
|
43
|
+
e.fix = (0, lint_1.fixByRemove)(e);
|
|
44
44
|
errors.push(e);
|
|
45
45
|
}
|
|
46
46
|
return errors;
|
package/dist/src/magicLink.js
CHANGED
|
@@ -79,7 +79,7 @@ class MagicLinkToken extends index_2.Token {
|
|
|
79
79
|
if (type === 'magic-link') {
|
|
80
80
|
const rule = 'invalid-isbn', s = index_1.default.lintConfig.getSeverity(rule);
|
|
81
81
|
if (s && this.#lint()) {
|
|
82
|
-
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'invalid
|
|
82
|
+
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'invalid-isbn', s));
|
|
83
83
|
}
|
|
84
84
|
return errors;
|
|
85
85
|
}
|
|
@@ -87,12 +87,12 @@ class MagicLinkToken extends index_2.Token {
|
|
|
87
87
|
if (severity) {
|
|
88
88
|
const regex = pipe ? /\|/u : /[,;。:!?()]+/u, child = childNodes.find((c) => c.type === 'text' && regex.test(c.data));
|
|
89
89
|
if (child) {
|
|
90
|
-
const { data } = child, e = (0, lint_1.generateForChild)(child, rect, rule, index_1.default.msg('
|
|
90
|
+
const { data } = child, e = (0, lint_1.generateForChild)(child, rect, rule, index_1.default.msg('in-url', pipe ? '"|"' : 'full-width-punctuation'), severity), { index, 0: s } = regex.exec(data), i = e.startIndex + index;
|
|
91
91
|
e.suggestions = pipe
|
|
92
|
-
? [
|
|
92
|
+
? [(0, lint_1.fixBySpace)(i, 1)]
|
|
93
93
|
: [
|
|
94
|
-
|
|
95
|
-
{ desc: '
|
|
94
|
+
(0, lint_1.fixBySpace)(i),
|
|
95
|
+
{ desc: index_1.default.msg('encode'), range: [i, i + s.length], text: encodeURI(s) },
|
|
96
96
|
];
|
|
97
97
|
errors.push(e);
|
|
98
98
|
}
|
package/dist/src/nested.js
CHANGED
|
@@ -77,10 +77,10 @@ class NestedToken extends index_2.Token {
|
|
|
77
77
|
const str = child.toString().trim();
|
|
78
78
|
return str && !regex.test(str);
|
|
79
79
|
}).map(child => {
|
|
80
|
-
const e = (0, lint_1.generateForChild)(child, rect, rule, index_1.default.msg('invalid
|
|
80
|
+
const e = (0, lint_1.generateForChild)(child, rect, rule, index_1.default.msg('invalid-content', this.name), s);
|
|
81
81
|
e.suggestions = [
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
(0, lint_1.fixByRemove)(e),
|
|
83
|
+
(0, lint_1.fixByComment)(e, child.toString()),
|
|
84
84
|
];
|
|
85
85
|
return e;
|
|
86
86
|
}),
|
package/dist/src/nowiki/base.js
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
2
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
37
|
exports.NowikiBaseToken = void 0;
|
|
38
|
+
const noEscape_1 = require("../../mixin/noEscape");
|
|
4
39
|
const index_1 = require("../index");
|
|
5
40
|
/**
|
|
6
41
|
* text-only token that will not be parsed
|
|
@@ -8,14 +43,30 @@ const index_1 = require("../index");
|
|
|
8
43
|
* 纯文字Token,不会被解析
|
|
9
44
|
* @classdesc `{childNodes: [AstText]}`
|
|
10
45
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
46
|
+
let NowikiBaseToken = (() => {
|
|
47
|
+
let _classDecorators = [noEscape_1.noEscape];
|
|
48
|
+
let _classDescriptor;
|
|
49
|
+
let _classExtraInitializers = [];
|
|
50
|
+
let _classThis;
|
|
51
|
+
let _classSuper = index_1.Token;
|
|
52
|
+
var NowikiBaseToken = class extends _classSuper {
|
|
53
|
+
static { _classThis = this; }
|
|
54
|
+
static {
|
|
55
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
56
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
57
|
+
NowikiBaseToken = _classThis = _classDescriptor.value;
|
|
58
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
59
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
60
|
+
}
|
|
61
|
+
/** text content / 纯文本部分 */
|
|
62
|
+
get innerText() {
|
|
63
|
+
return this.firstChild.data;
|
|
64
|
+
}
|
|
65
|
+
/** @param wikitext default: `''` */
|
|
66
|
+
constructor(wikitext = '', config, accum) {
|
|
67
|
+
super(wikitext, config, accum);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return NowikiBaseToken = _classThis;
|
|
71
|
+
})();
|
|
21
72
|
exports.NowikiBaseToken = NowikiBaseToken;
|
|
@@ -81,8 +81,8 @@ let CommentToken = (() => {
|
|
|
81
81
|
if (!s) {
|
|
82
82
|
return [];
|
|
83
83
|
}
|
|
84
|
-
const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('unclosed
|
|
85
|
-
e.suggestions = [
|
|
84
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('unclosed', 'html-comment'), s);
|
|
85
|
+
e.suggestions = [(0, lint_1.fixByClose)(e.endIndex, '-->')];
|
|
86
86
|
return [e];
|
|
87
87
|
}
|
|
88
88
|
/** @private */
|
package/dist/src/nowiki/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const lint_1 = require("../../util/lint");
|
|
|
9
9
|
const index_1 = __importDefault(require("../../index"));
|
|
10
10
|
const base_1 = require("./base");
|
|
11
11
|
const getLintRegex = (0, common_1.getRegex)(name => new RegExp(String.raw `<\s*(?:/\s*)${name === 'nowiki' ? '' : '?'}(${name})\b`, 'giu'));
|
|
12
|
-
const voidExt = new Set(['
|
|
12
|
+
const voidExt = new Set(['languages', 'section', 'templatestyles']);
|
|
13
13
|
/**
|
|
14
14
|
* text-only token inside an extension tag
|
|
15
15
|
*
|
|
@@ -28,8 +28,8 @@ class NowikiToken extends base_1.NowikiBaseToken {
|
|
|
28
28
|
lint(start = this.getAbsoluteIndex()) {
|
|
29
29
|
const { name } = this, rule = 'void-ext', s = index_1.default.lintConfig.getSeverity(rule, name);
|
|
30
30
|
if (s && this.#lint()) {
|
|
31
|
-
const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('nothing
|
|
32
|
-
e.
|
|
31
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('nothing-in', name), s);
|
|
32
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
33
33
|
return [e];
|
|
34
34
|
}
|
|
35
35
|
return super.lint(start, getLintRegex(name));
|
package/dist/src/nowiki/quote.js
CHANGED
|
@@ -56,24 +56,24 @@ class QuoteToken extends base_1.NowikiBaseToken {
|
|
|
56
56
|
if (previousData?.endsWith(`'`)) {
|
|
57
57
|
const severity = severities[(closing.bold || closing.italic) && /[a-z\d]'$/iu.test(previousData) ? 1 : 0];
|
|
58
58
|
if (severity) {
|
|
59
|
-
const e = (0, lint_1.generateForSelf)(this, rect, rules[0], index_1.default.msg('lonely
|
|
60
|
-
errors.push({
|
|
59
|
+
const e = (0, lint_1.generateForSelf)(this, rect, rules[0], index_1.default.msg('lonely', `'`), severity), { startLine: endLine, startCol: endCol } = e, [, { length }] = /(?:^|[^'])('+)$/u.exec(previousData), startIndex = start - length, eNew = {
|
|
61
60
|
...e,
|
|
62
61
|
startIndex,
|
|
63
|
-
endIndex,
|
|
62
|
+
endIndex: start,
|
|
64
63
|
endLine,
|
|
65
64
|
startCol: endCol - length,
|
|
66
65
|
endCol,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
};
|
|
67
|
+
eNew.suggestions = [
|
|
68
|
+
(0, lint_1.fixByEscape)(startIndex, ''', length),
|
|
69
|
+
(0, lint_1.fixByRemove)(eNew),
|
|
70
|
+
];
|
|
71
|
+
errors.push(eNew);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
if (s && bold && this.closest('heading-title')) {
|
|
75
|
-
const e = (0, lint_1.generateForSelf)(this, rect, rules[1], 'bold
|
|
76
|
-
e.suggestions = [
|
|
74
|
+
if (s && bold && this.closest('heading-title,ext')?.type === 'heading-title') {
|
|
75
|
+
const e = (0, lint_1.generateForSelf)(this, rect, rules[1], 'bold-in-header', s);
|
|
76
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
77
77
|
errors.push(e);
|
|
78
78
|
}
|
|
79
79
|
return errors;
|
package/dist/src/onlyinclude.js
CHANGED
|
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.OnlyincludeToken = void 0;
|
|
38
38
|
const padded_1 = require("../mixin/padded");
|
|
39
|
+
const noEscape_1 = require("../mixin/noEscape");
|
|
39
40
|
const index_1 = require("./index");
|
|
40
41
|
/**
|
|
41
42
|
* `<onlyinclude>` during transclusion
|
|
@@ -44,7 +45,7 @@ const index_1 = require("./index");
|
|
|
44
45
|
* @classdesc `{childNodes: (AstText|Token)[]}`
|
|
45
46
|
*/
|
|
46
47
|
let OnlyincludeToken = (() => {
|
|
47
|
-
let _classDecorators = [(0, padded_1.padded)('<onlyinclude>')];
|
|
48
|
+
let _classDecorators = [noEscape_1.noEscape, (0, padded_1.padded)('<onlyinclude>')];
|
|
48
49
|
let _classDescriptor;
|
|
49
50
|
let _classExtraInitializers = [];
|
|
50
51
|
let _classThis;
|
|
@@ -85,7 +85,7 @@ let ParamTagToken = (() => {
|
|
|
85
85
|
if (!s) {
|
|
86
86
|
return [];
|
|
87
87
|
}
|
|
88
|
-
const rect = new rect_1.BoundingRect(this, start), msg = index_1.default.msg('invalid
|
|
88
|
+
const rect = new rect_1.BoundingRect(this, start), msg = index_1.default.msg('invalid-parameter', this.name), errors = [];
|
|
89
89
|
for (const child of this.childNodes) {
|
|
90
90
|
child.setAttribute('aIndex', start);
|
|
91
91
|
const grandChildren = child.childNodes
|
|
@@ -97,7 +97,7 @@ let ParamTagToken = (() => {
|
|
|
97
97
|
const i = grandChildren.findIndex(({ type }) => type !== 'text'), str = grandChildren.slice(0, i === -1 ? undefined : i).map(String).join('');
|
|
98
98
|
if (str && !(i === -1 ? /^[a-z]+(?:\[\])?\s*=/iu : /^[a-z]+(?:\[\])?\s*(?:=|$)/iu).test(str)) {
|
|
99
99
|
const e = (0, lint_1.generateForChild)(child, rect, rule, msg, s);
|
|
100
|
-
e.suggestions = [
|
|
100
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
101
101
|
errors.push(e);
|
|
102
102
|
}
|
|
103
103
|
else {
|
package/dist/src/parameter.js
CHANGED
|
@@ -71,13 +71,13 @@ class ParameterToken extends index_2.Token {
|
|
|
71
71
|
const { firstChild } = this, link = linkRegex.exec(firstChild.text())?.[0];
|
|
72
72
|
try {
|
|
73
73
|
if (link && new URL(link).search) {
|
|
74
|
-
const
|
|
74
|
+
const e = (0, lint_1.generateForChild)(firstChild, { start }, rule, 'unescaped-query', s);
|
|
75
75
|
e.startIndex = e.endIndex;
|
|
76
76
|
e.startLine = e.endLine;
|
|
77
77
|
e.startCol = e.endCol;
|
|
78
78
|
e.endIndex++;
|
|
79
79
|
e.endCol++;
|
|
80
|
-
e.fix =
|
|
80
|
+
e.fix = (0, lint_1.fixByEscape)(e.startIndex, '{{=}}');
|
|
81
81
|
errors.push(e);
|
|
82
82
|
}
|
|
83
83
|
}
|
package/dist/src/redirect.js
CHANGED
|
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.RedirectToken = void 0;
|
|
38
38
|
const hidden_1 = require("../mixin/hidden");
|
|
39
|
+
const noEscape_1 = require("../mixin/noEscape");
|
|
39
40
|
const index_1 = require("./index");
|
|
40
41
|
const syntax_1 = require("./syntax");
|
|
41
42
|
const redirectTarget_1 = require("./link/redirectTarget");
|
|
@@ -46,7 +47,7 @@ const redirectTarget_1 = require("./link/redirectTarget");
|
|
|
46
47
|
* @classdesc `{childNodes: [SyntaxToken, LinkToken]}`
|
|
47
48
|
*/
|
|
48
49
|
let RedirectToken = (() => {
|
|
49
|
-
let _classDecorators = [(0, hidden_1.hiddenToken)(false, false)];
|
|
50
|
+
let _classDecorators = [(0, hidden_1.hiddenToken)(false, false), noEscape_1.noEscape];
|
|
50
51
|
let _classDescriptor;
|
|
51
52
|
let _classExtraInitializers = [];
|
|
52
53
|
let _classThis;
|
package/dist/src/table/base.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Parser from '../../index';
|
|
1
2
|
import { Token } from '../index';
|
|
2
3
|
import { SyntaxToken } from '../syntax';
|
|
3
4
|
import { AttributesToken } from '../attributes';
|
|
@@ -18,5 +19,6 @@ export declare abstract class TableBaseToken extends Token {
|
|
|
18
19
|
* @param attr 表格属性
|
|
19
20
|
*/
|
|
20
21
|
constructor(pattern: RegExp, syntax: string, type: TableTypes, attr?: string, config?: Config, accum?: Token[], acceptable?: WikiParserAcceptable);
|
|
22
|
+
escape(): void;
|
|
21
23
|
}
|
|
22
24
|
export {};
|
package/dist/src/table/base.js
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.TableBaseToken = void 0;
|
|
4
7
|
const attributesParent_1 = require("../../mixin/attributesParent");
|
|
5
|
-
const index_1 = require("
|
|
8
|
+
const index_1 = __importDefault(require("../../index"));
|
|
9
|
+
const index_2 = require("../index");
|
|
6
10
|
const syntax_1 = require("../syntax");
|
|
7
11
|
const attributes_1 = require("../attributes");
|
|
12
|
+
/**
|
|
13
|
+
* 转义表格语法
|
|
14
|
+
* @param syntax 表格语法节点
|
|
15
|
+
*/
|
|
16
|
+
const escapeTable = (syntax) => {
|
|
17
|
+
const wikitext = syntax.childNodes.map(child => child.type === 'text'
|
|
18
|
+
? child.data.replace(/\|\|/gu, '{{!!}}')
|
|
19
|
+
.replace(/\|/gu, '{{!}}')
|
|
20
|
+
: child.toString()).join(''), { childNodes } = index_1.default
|
|
21
|
+
.parse(wikitext, syntax.getAttribute('include'), 2, syntax.getAttribute('config'));
|
|
22
|
+
syntax.safeReplaceChildren(childNodes);
|
|
23
|
+
};
|
|
8
24
|
/**
|
|
9
25
|
* table row that contains the newline at the beginning but not at the end
|
|
10
26
|
*
|
|
11
27
|
* 表格行,含开头的换行,不含结尾的换行
|
|
12
28
|
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token[]]}`
|
|
13
29
|
*/
|
|
14
|
-
class TableBaseToken extends (0, attributesParent_1.attributesParent)(1)(
|
|
30
|
+
class TableBaseToken extends (0, attributesParent_1.attributesParent)(1)(index_2.Token) {
|
|
15
31
|
/**
|
|
16
32
|
* @param pattern 表格语法正则
|
|
17
33
|
* @param syntax 表格语法
|
|
@@ -24,5 +40,17 @@ class TableBaseToken extends (0, attributesParent_1.attributesParent)(1)(index_1
|
|
|
24
40
|
// @ts-expect-error abstract class
|
|
25
41
|
new attributes_1.AttributesToken(attr, 'table-attrs', type, config, accum));
|
|
26
42
|
}
|
|
43
|
+
escape() {
|
|
44
|
+
LSP: { // eslint-disable-line no-unused-labels
|
|
45
|
+
for (const child of this.childNodes) {
|
|
46
|
+
if (child instanceof syntax_1.SyntaxToken) {
|
|
47
|
+
escapeTable(child);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
child.escape();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
27
55
|
}
|
|
28
56
|
exports.TableBaseToken = TableBaseToken;
|
package/dist/src/table/index.js
CHANGED
|
@@ -97,7 +97,7 @@ let TableToken = (() => {
|
|
|
97
97
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
98
98
|
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), rules = ['unclosed-table', 'table-layout'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule));
|
|
99
99
|
if (s[0] && !this.closed) {
|
|
100
|
-
errors.push((0, lint_1.generateForChild)(this.firstChild, rect, rules[0], index_1.default.msg('unclosed
|
|
100
|
+
errors.push((0, lint_1.generateForChild)(this.firstChild, rect, rules[0], index_1.default.msg('unclosed', 'table'), s[0]));
|
|
101
101
|
}
|
|
102
102
|
if (s[1]) {
|
|
103
103
|
const layout = this.getLayout(), { length } = layout;
|
|
@@ -120,7 +120,7 @@ let TableToken = (() => {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
if (j < length) {
|
|
123
|
-
const row = this.getNthRow(j), e = (0, lint_1.generateForChild)(row, rect, rules[1], 'inconsistent
|
|
123
|
+
const row = this.getNthRow(j), e = (0, lint_1.generateForChild)(row, rect, rules[1], 'inconsistent-table', s[1]);
|
|
124
124
|
e.startIndex++;
|
|
125
125
|
e.startLine++;
|
|
126
126
|
e.startCol = 0;
|
|
@@ -138,12 +138,11 @@ let TableToken = (() => {
|
|
|
138
138
|
* @param syntax syntax of the table end / 表格结尾语法
|
|
139
139
|
*/
|
|
140
140
|
close(syntax = '\n|}', halfParsed) {
|
|
141
|
-
const config = this.getAttribute('config'), accum = this.getAttribute('accum')
|
|
141
|
+
const config = this.getAttribute('config'), accum = this.getAttribute('accum');
|
|
142
142
|
debug_1.Shadow.run(() => {
|
|
143
|
-
const token = new syntax_1.SyntaxToken(undefined, 'table-syntax', config, accum);
|
|
143
|
+
const token = new syntax_1.SyntaxToken(halfParsed ? syntax : undefined, 'table-syntax', config, accum);
|
|
144
144
|
super.insertAt(token);
|
|
145
145
|
});
|
|
146
|
-
this.lastChild.safeReplaceChildren(inner);
|
|
147
146
|
}
|
|
148
147
|
// eslint-disable-next-line jsdoc/require-param
|
|
149
148
|
/**
|
package/dist/src/table/td.d.ts
CHANGED
package/dist/src/table/td.js
CHANGED
|
@@ -154,23 +154,13 @@ let TdToken = (() => {
|
|
|
154
154
|
if (data.includes('|')) {
|
|
155
155
|
const double = data.includes('||'), s = severities[double ? 1 : 0];
|
|
156
156
|
if (s) {
|
|
157
|
-
const e = (0, lint_1.generateForChild)(child, rect, rule, '
|
|
157
|
+
const e = (0, lint_1.generateForChild)(child, rect, rule, 'pipe-in-table', s);
|
|
158
158
|
if (double) {
|
|
159
159
|
const syntax = { caption: '|+', td: '|', th: '!' }[this.subtype];
|
|
160
|
-
e.fix = {
|
|
161
|
-
desc: 'newline',
|
|
162
|
-
range: [e.startIndex, e.endIndex],
|
|
163
|
-
text: data.replace(/\|\|/gu, `\n${syntax}`),
|
|
164
|
-
};
|
|
160
|
+
e.fix = (0, lint_1.fixBy)(e, 'newline', data.replace(/\|\|/gu, `\n${syntax}`));
|
|
165
161
|
}
|
|
166
162
|
else {
|
|
167
|
-
e.suggestions = [
|
|
168
|
-
{
|
|
169
|
-
desc: 'escape',
|
|
170
|
-
range: [e.startIndex, e.endIndex],
|
|
171
|
-
text: data.replace(/\|/gu, '|'),
|
|
172
|
-
},
|
|
173
|
-
];
|
|
163
|
+
e.suggestions = [(0, lint_1.fixByPipe)(e.startIndex, data)];
|
|
174
164
|
}
|
|
175
165
|
errors.push(e);
|
|
176
166
|
}
|
|
@@ -191,6 +181,17 @@ let TdToken = (() => {
|
|
|
191
181
|
const value = super.getAttr(key);
|
|
192
182
|
return (key === 'rowspan' || key === 'colspan' ? parseInt(value) || 1 : value);
|
|
193
183
|
}
|
|
184
|
+
escape() {
|
|
185
|
+
LSP: { // eslint-disable-line no-unused-labels
|
|
186
|
+
super.escape();
|
|
187
|
+
if (this.childNodes[1].toString()) {
|
|
188
|
+
this.#innerSyntax ||= '{{!}}';
|
|
189
|
+
}
|
|
190
|
+
if (this.#innerSyntax === '|') {
|
|
191
|
+
this.#innerSyntax = '{{!}}';
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
194
195
|
};
|
|
195
196
|
})();
|
|
196
197
|
exports.TdToken = TdToken;
|
package/dist/src/table/trBase.js
CHANGED
|
@@ -22,7 +22,7 @@ class TrBaseToken extends base_1.TableBaseToken {
|
|
|
22
22
|
}
|
|
23
23
|
const severity = (0, lint_1.isFostered)(inter), rule = 'fostered-content', s = severity && index_1.default.lintConfig.getSeverity(rule, severity === 2 ? undefined : 'transclusion');
|
|
24
24
|
if (s) {
|
|
25
|
-
const error = (0, lint_1.generateForChild)(inter, { start }, rule, 'content
|
|
25
|
+
const error = (0, lint_1.generateForChild)(inter, { start }, rule, 'content-outside-table', s);
|
|
26
26
|
error.startIndex++;
|
|
27
27
|
error.startLine++;
|
|
28
28
|
error.startCol = 0;
|
package/dist/src/tagPair/ext.js
CHANGED
|
@@ -188,12 +188,12 @@ let ExtToken = (() => {
|
|
|
188
188
|
if (this.name !== 'nowiki') {
|
|
189
189
|
const s = this.inHtmlAttrs(), rule = 'parsing-order', severity = s && index_1.default.lintConfig.getSeverity(rule, s === 2 ? 'ext' : 'templateInTable');
|
|
190
190
|
if (severity) {
|
|
191
|
-
errors.push((0, lint_1.generateForSelf)(this, rect, rule, '
|
|
191
|
+
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'ext-in-html', severity));
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
const rule = 'var-anchor', s = index_1.default.lintConfig.getSeverity(rule, 'ref');
|
|
195
195
|
if (s && this.name === 'ref' && this.closest('heading-title')) {
|
|
196
|
-
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'variable
|
|
196
|
+
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'variable-anchor', s));
|
|
197
197
|
}
|
|
198
198
|
return errors;
|
|
199
199
|
}
|
|
@@ -84,13 +84,13 @@ let IncludeToken = (() => {
|
|
|
84
84
|
lint(start = this.getAbsoluteIndex()) {
|
|
85
85
|
const errors = [], { firstChild, closed, name } = this, rect = new rect_1.BoundingRect(this, start), rules = ['no-ignored', 'unclosed-comment'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule, 'include'));
|
|
86
86
|
if (s[0] && firstChild.data.trim()) {
|
|
87
|
-
const e = (0, lint_1.generateForChild)(firstChild, rect, rules[0], 'useless
|
|
88
|
-
e.suggestions = [
|
|
87
|
+
const e = (0, lint_1.generateForChild)(firstChild, rect, rules[0], 'useless-attribute', s[0]);
|
|
88
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
89
89
|
errors.push(e);
|
|
90
90
|
}
|
|
91
91
|
if (s[1] && !closed) {
|
|
92
|
-
const e = (0, lint_1.generateForSelf)(this, rect, rules[1], index_1.default.msg('unclosed
|
|
93
|
-
e.suggestions = [
|
|
92
|
+
const e = (0, lint_1.generateForSelf)(this, rect, rules[1], index_1.default.msg('unclosed', `<${name}>`), s[1]);
|
|
93
|
+
e.suggestions = [(0, lint_1.fixByClose)(e.endIndex, `</${name}>`)];
|
|
94
94
|
errors.push(e);
|
|
95
95
|
}
|
|
96
96
|
return errors;
|
|
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.TagPairToken = void 0;
|
|
38
38
|
const gapped_1 = require("../../mixin/gapped");
|
|
39
|
+
const noEscape_1 = require("../../mixin/noEscape");
|
|
39
40
|
const index_1 = require("../index");
|
|
40
41
|
/**
|
|
41
42
|
* Paired tags
|
|
@@ -43,7 +44,7 @@ const index_1 = require("../index");
|
|
|
43
44
|
* 成对标签
|
|
44
45
|
*/
|
|
45
46
|
let TagPairToken = (() => {
|
|
46
|
-
let _classDecorators = [(0, gapped_1.gapped)()];
|
|
47
|
+
let _classDecorators = [(0, gapped_1.gapped)(), noEscape_1.noEscape];
|
|
47
48
|
let _classDescriptor;
|
|
48
49
|
let _classExtraInitializers = [];
|
|
49
50
|
let _classThis;
|
package/dist/src/transclude.js
CHANGED
|
@@ -44,6 +44,7 @@ const debug_1 = require("../util/debug");
|
|
|
44
44
|
const constants_1 = require("../util/constants");
|
|
45
45
|
const rect_1 = require("../lib/rect");
|
|
46
46
|
const gapped_1 = require("../mixin/gapped");
|
|
47
|
+
const noEscape_1 = require("../mixin/noEscape");
|
|
47
48
|
const index_1 = __importDefault(require("../index"));
|
|
48
49
|
const index_2 = require("./index");
|
|
49
50
|
const parameter_1 = require("./parameter");
|
|
@@ -56,7 +57,7 @@ const syntax_1 = require("./syntax");
|
|
|
56
57
|
* @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken[], ...ParameterToken[]]}`
|
|
57
58
|
*/
|
|
58
59
|
let TranscludeToken = (() => {
|
|
59
|
-
let _classDecorators = [(0, gapped_1.gapped)()];
|
|
60
|
+
let _classDecorators = [noEscape_1.noEscape, (0, gapped_1.gapped)()];
|
|
60
61
|
let _classDescriptor;
|
|
61
62
|
let _classExtraInitializers = [];
|
|
62
63
|
let _classThis;
|
|
@@ -237,10 +238,11 @@ let TranscludeToken = (() => {
|
|
|
237
238
|
}
|
|
238
239
|
/** @private */
|
|
239
240
|
toString(skip) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
+
|
|
241
|
+
const { childNodes, length, firstChild, modifier, type } = this;
|
|
242
|
+
return `{{${modifier}${type === 'magic-word'
|
|
243
|
+
? firstChild.toString(skip)
|
|
244
|
+
+ (length === 1 ? '' : this.#colon)
|
|
245
|
+
+ childNodes.slice(1).map(child => child.toString(skip)).join('|')
|
|
244
246
|
: super.toString(skip, '|')}}}`;
|
|
245
247
|
}
|
|
246
248
|
/** @private */
|
|
@@ -279,40 +281,33 @@ let TranscludeToken = (() => {
|
|
|
279
281
|
rule = 'invalid-invoke';
|
|
280
282
|
s = index_1.default.lintConfig.getSeverity(rule, 'name');
|
|
281
283
|
if (s) {
|
|
282
|
-
errors.push((0, lint_1.generateForChild)(childNodes[1], rect, rule, 'illegal
|
|
284
|
+
errors.push((0, lint_1.generateForChild)(childNodes[1], rect, rule, 'illegal-module', s));
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
287
|
else if (s) {
|
|
286
288
|
const child = childNodes[invoke ? 1 : 0], i = child.childNodes
|
|
287
289
|
.findIndex(c => c.type === 'text' && (0, string_1.decodeHtml)(c.data).includes('#')), textNode = child.childNodes[i];
|
|
288
290
|
if (textNode) {
|
|
289
|
-
const e = (0, lint_1.generateForChild)(child, rect, rule, 'useless
|
|
290
|
-
e.
|
|
291
|
-
desc: 'remove',
|
|
292
|
-
range: [
|
|
293
|
-
e.startIndex + child.getRelativeIndex(i) + textNode.data.indexOf('#'),
|
|
294
|
-
e.endIndex,
|
|
295
|
-
],
|
|
296
|
-
text: '',
|
|
297
|
-
};
|
|
291
|
+
const e = (0, lint_1.generateForChild)(child, rect, rule, 'useless-fragment', s);
|
|
292
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e, child.getRelativeIndex(i) + textNode.data.indexOf('#'))];
|
|
298
293
|
errors.push(e);
|
|
299
294
|
}
|
|
300
295
|
}
|
|
301
296
|
rule = 'invalid-invoke';
|
|
302
297
|
s = index_1.default.lintConfig.getSeverity(rule, 'function');
|
|
303
298
|
if (s && invoke && length === 2) {
|
|
304
|
-
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'missing
|
|
299
|
+
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'missing-function', s));
|
|
305
300
|
return errors;
|
|
306
301
|
}
|
|
307
302
|
rule = 'no-duplicate';
|
|
308
303
|
s = index_1.default.lintConfig.getSeverity(rule, 'parameter');
|
|
309
304
|
if (s) {
|
|
310
305
|
const duplicatedArgs = this.getDuplicatedArgs()
|
|
311
|
-
.filter(([, parameter]) => !parameter[0].querySelector('ext')), msg = '
|
|
306
|
+
.filter(([, parameter]) => !parameter[0].querySelector('ext')), msg = 'duplicate-parameter';
|
|
312
307
|
for (const [, args] of duplicatedArgs) {
|
|
313
308
|
errors.push(...args.map(arg => {
|
|
314
309
|
const e = (0, lint_1.generateForChild)(arg, rect, rule, msg, s);
|
|
315
|
-
e.suggestions = [
|
|
310
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e, -1)];
|
|
316
311
|
return e;
|
|
317
312
|
}));
|
|
318
313
|
}
|
package/dist/util/constants.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BuildMethod = exports.MAX_STAGE = void 0;
|
|
3
|
+
exports.enMsg = exports.BuildMethod = exports.MAX_STAGE = void 0;
|
|
4
4
|
exports.MAX_STAGE = 11;
|
|
5
5
|
var BuildMethod;
|
|
6
6
|
(function (BuildMethod) {
|
|
7
7
|
BuildMethod[BuildMethod["String"] = 0] = "String";
|
|
8
8
|
BuildMethod[BuildMethod["Text"] = 1] = "Text";
|
|
9
9
|
})(BuildMethod || (exports.BuildMethod = BuildMethod = {}));
|
|
10
|
+
exports.enMsg = require('../../i18n/en.json'); // eslint-disable-line n/no-missing-require
|