wikilint 2.44.0 → 2.45.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/config/default.json +1 -2
- package/config/enwiki.json +1 -1
- package/config/jawiki.json +1 -1
- package/config/minimum.json +1 -1
- package/config/zhwiki.json +1 -1
- package/data/ext/templatedata.json +13 -5
- package/data/signatures.json +38 -32
- package/dist/base.d.mts +1 -1
- package/dist/base.d.ts +1 -1
- package/dist/bin/config.js +1 -1
- package/dist/index.js +1 -1
- package/dist/internal.d.ts +6 -1
- package/dist/lib/element.js +5 -5
- package/dist/lib/lintConfig.js +7 -0
- package/dist/lib/lsp.d.ts +1 -2
- package/dist/lib/lsp.js +18 -42
- package/dist/lib/node.js +2 -2
- package/dist/lib/text.js +2 -2
- package/dist/map.d.ts +4 -1
- package/dist/mixin/elementLike.js +29 -31
- package/dist/mixin/hidden.js +0 -1
- package/dist/mixin/paramLineParent.d.ts +26 -0
- package/dist/mixin/paramLineParent.js +51 -0
- package/dist/src/arg.js +17 -35
- package/dist/src/atom.d.ts +1 -1
- package/dist/src/atom.js +2 -0
- package/dist/src/attribute.js +10 -5
- package/dist/src/attributes.js +15 -13
- package/dist/src/commented.d.ts +1 -0
- package/dist/src/commented.js +1 -3
- package/dist/src/converterFlags.js +9 -5
- package/dist/src/converterRule.js +2 -2
- package/dist/src/funcTag.d.ts +23 -0
- package/dist/src/funcTag.js +85 -0
- package/dist/src/heading.js +8 -3
- package/dist/src/hidden.d.ts +3 -2
- package/dist/src/hidden.js +29 -5
- package/dist/src/imageParameter.js +16 -4
- package/dist/src/index.js +2 -2
- package/dist/src/link/base.js +14 -2
- package/dist/src/link/categorytree.d.ts +2 -0
- package/dist/src/link/categorytree.js +8 -5
- package/dist/src/link/file.js +18 -12
- package/dist/src/multiLine/charinsert.d.ts +16 -0
- package/dist/src/multiLine/charinsert.js +84 -0
- package/dist/src/multiLine/gallery.js +4 -4
- package/dist/src/multiLine/imagemap.d.ts +1 -1
- package/dist/src/multiLine/imagemap.js +7 -7
- package/dist/src/multiLine/index.d.ts +3 -0
- package/dist/src/multiLine/index.js +79 -18
- package/dist/src/multiLine/inputbox.d.ts +1 -0
- package/dist/src/multiLine/paramTag.d.ts +3 -0
- package/dist/src/multiLine/paramTag.js +60 -13
- package/dist/src/nested.js +7 -7
- package/dist/src/nowiki/quote.js +6 -5
- package/dist/src/paramLine.d.ts +17 -3
- package/dist/src/paramLine.js +123 -31
- package/dist/src/parameter.d.ts +6 -0
- package/dist/src/parameter.js +15 -1
- package/dist/src/singleLine/charinsertLine.d.ts +21 -0
- package/dist/src/singleLine/charinsertLine.js +69 -0
- package/dist/src/{imagemapLink.d.ts → singleLine/imagemapLink.d.ts} +8 -7
- package/dist/src/singleLine/imagemapLink.js +95 -0
- package/dist/src/singleLine/index.d.ts +10 -0
- package/dist/src/singleLine/index.js +16 -0
- package/dist/src/tag/html.js +26 -8
- package/dist/src/tag/index.js +18 -17
- package/dist/src/tagPair/ext.js +23 -2
- package/dist/src/tagPair/index.js +1 -10
- package/dist/src/transclude.js +13 -13
- package/dist/util/sharable.js +22 -0
- package/dist/util/sharable.mjs +22 -0
- package/dist/util/string.js +27 -2
- package/i18n/en.json +4 -0
- package/i18n/zh-hans.json +4 -0
- package/i18n/zh-hant.json +4 -0
- package/package.json +10 -18
- package/dist/src/imagemapLink.js +0 -34
- /package/dist/{util → vendor}/search.js +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Token } from './index';
|
|
2
|
+
import { ParamLineToken } from './paramLine';
|
|
3
|
+
import type { Config } from '../base';
|
|
4
|
+
import type { AttributesToken, ExtToken } from '../internal';
|
|
5
|
+
import type { ParamLineParentBase } from '../mixin/paramLineParent';
|
|
6
|
+
export interface FuncTagToken extends ParamLineParentBase {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* `<seo>`
|
|
10
|
+
* @classdesc `{childNodes: ParamLineToken[]}`
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class FuncTagToken extends Token {
|
|
13
|
+
readonly name: 'seo';
|
|
14
|
+
readonly childNodes: readonly ParamLineToken[];
|
|
15
|
+
abstract get firstChild(): ParamLineToken | undefined;
|
|
16
|
+
abstract get lastChild(): ParamLineToken | undefined;
|
|
17
|
+
abstract get nextSibling(): undefined;
|
|
18
|
+
abstract get previousSibling(): AttributesToken | undefined;
|
|
19
|
+
abstract get parentNode(): ExtToken | undefined;
|
|
20
|
+
get type(): 'ext-inner';
|
|
21
|
+
/** @class */
|
|
22
|
+
constructor(wikitext: string | undefined, config: Config, accum: Token[]);
|
|
23
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.FuncTagToken = void 0;
|
|
38
|
+
const paramLineParent_1 = require("../mixin/paramLineParent");
|
|
39
|
+
const index_1 = require("./index");
|
|
40
|
+
const paramLine_1 = require("./paramLine");
|
|
41
|
+
const gapped_1 = require("../mixin/gapped");
|
|
42
|
+
/**
|
|
43
|
+
* `<seo>`
|
|
44
|
+
* @classdesc `{childNodes: ParamLineToken[]}`
|
|
45
|
+
*/
|
|
46
|
+
let FuncTagToken = (() => {
|
|
47
|
+
let _classDecorators = [(0, gapped_1.gapped)(), paramLineParent_1.paramLineParent];
|
|
48
|
+
let _classDescriptor;
|
|
49
|
+
let _classExtraInitializers = [];
|
|
50
|
+
let _classThis;
|
|
51
|
+
let _classSuper = index_1.Token;
|
|
52
|
+
var FuncTagToken = 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
|
+
FuncTagToken = _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
|
+
get type() {
|
|
62
|
+
return 'ext-inner';
|
|
63
|
+
}
|
|
64
|
+
/** @class */
|
|
65
|
+
constructor(wikitext, config, accum) {
|
|
66
|
+
super(undefined, config, accum, {});
|
|
67
|
+
if (wikitext) {
|
|
68
|
+
for (const parameter of wikitext.split('|')) {
|
|
69
|
+
// @ts-expect-error abstract class
|
|
70
|
+
this.insertAt(new paramLine_1.ParamLineToken('seo', parameter, config, accum));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** @private */
|
|
75
|
+
toString(skip) {
|
|
76
|
+
return super.toString(skip, '|');
|
|
77
|
+
}
|
|
78
|
+
/** @private */
|
|
79
|
+
text() {
|
|
80
|
+
return this.childNodes.map(child => child.text()).filter(Boolean).join('|');
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return FuncTagToken = _classThis;
|
|
84
|
+
})();
|
|
85
|
+
exports.FuncTagToken = FuncTagToken;
|
package/dist/src/heading.js
CHANGED
|
@@ -100,7 +100,7 @@ let HeadingToken = (() => {
|
|
|
100
100
|
/** @private */
|
|
101
101
|
text() {
|
|
102
102
|
const equals = this.#getEquals();
|
|
103
|
-
return equals + this.firstChild.text() + equals;
|
|
103
|
+
return equals + this.firstChild.text().trim() + equals;
|
|
104
104
|
}
|
|
105
105
|
/** @private */
|
|
106
106
|
getAttribute(key) {
|
|
@@ -110,10 +110,15 @@ let HeadingToken = (() => {
|
|
|
110
110
|
getGaps() {
|
|
111
111
|
return this.level;
|
|
112
112
|
}
|
|
113
|
+
/** 是否包含未成对的`=` */
|
|
114
|
+
#lint() {
|
|
115
|
+
const innerStr = this.firstChild.toString(), unbalancedStart = innerStr.startsWith('=');
|
|
116
|
+
return unbalancedStart ? 1 : innerStr.endsWith('=');
|
|
117
|
+
}
|
|
113
118
|
/** @private */
|
|
114
119
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
115
120
|
LINT: {
|
|
116
|
-
const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(),
|
|
121
|
+
const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), unbalanced = this.#lint(), rect = new rect_1.BoundingRect(this, start), s = this.inHtmlAttrs(), rules = ['h1', 'unbalanced-header', 'format-leakage'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, severities = rules.map(rule => lintConfig.getSeverity(rule, 'apostrophe'));
|
|
117
122
|
if (severities[0] && this.level === 1) {
|
|
118
123
|
const e = (0, lint_1.generateForChild)(firstChild, rect, rules[0], '<h1>', severities[0]);
|
|
119
124
|
if (computeEditInfo && !unbalanced) {
|
|
@@ -126,7 +131,7 @@ let HeadingToken = (() => {
|
|
|
126
131
|
if (!computeEditInfo || innerStr === '=') {
|
|
127
132
|
//
|
|
128
133
|
}
|
|
129
|
-
else if (
|
|
134
|
+
else if (unbalanced === 1) {
|
|
130
135
|
const extra = (0, common_1.numLeadingSpaces)(innerStr, /[^=]|$/u), newLevel = level + extra;
|
|
131
136
|
e.suggestions = [{ desc: `h${level}`, range: [e.startIndex, e.startIndex + extra], text: '' }];
|
|
132
137
|
if (newLevel < 7) {
|
package/dist/src/hidden.d.ts
CHANGED
package/dist/src/hidden.js
CHANGED
|
@@ -33,22 +33,27 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
33
33
|
}
|
|
34
34
|
return useValue ? value : void 0;
|
|
35
35
|
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
36
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
40
|
exports.HiddenToken = void 0;
|
|
41
|
+
const lint_1 = require("../util/lint");
|
|
38
42
|
const hidden_1 = require("../mixin/hidden");
|
|
39
43
|
const noEscape_1 = require("../mixin/noEscape");
|
|
40
|
-
const index_1 = require("
|
|
44
|
+
const index_1 = __importDefault(require("../index"));
|
|
45
|
+
const index_2 = require("./index");
|
|
41
46
|
/**
|
|
42
|
-
* invisible token
|
|
47
|
+
* invisible token in triple braces
|
|
43
48
|
*
|
|
44
|
-
*
|
|
49
|
+
* 三重括号内不可见的节点
|
|
45
50
|
*/
|
|
46
51
|
let HiddenToken = (() => {
|
|
47
|
-
let _classDecorators = [(0, hidden_1.hiddenToken)(), noEscape_1.noEscape];
|
|
52
|
+
let _classDecorators = [(0, hidden_1.hiddenToken)(false), noEscape_1.noEscape];
|
|
48
53
|
let _classDescriptor;
|
|
49
54
|
let _classExtraInitializers = [];
|
|
50
55
|
let _classThis;
|
|
51
|
-
let _classSuper =
|
|
56
|
+
let _classSuper = index_2.Token;
|
|
52
57
|
var HiddenToken = class extends _classSuper {
|
|
53
58
|
static { _classThis = this; }
|
|
54
59
|
static {
|
|
@@ -61,6 +66,25 @@ let HiddenToken = (() => {
|
|
|
61
66
|
get type() {
|
|
62
67
|
return 'hidden';
|
|
63
68
|
}
|
|
69
|
+
/** @private */
|
|
70
|
+
lint(start = this.getAbsoluteIndex()) {
|
|
71
|
+
LINT: {
|
|
72
|
+
const rule = 'no-ignored', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, 'arg');
|
|
73
|
+
if (s) {
|
|
74
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invisible-triple-braces', s);
|
|
75
|
+
e.startIndex--;
|
|
76
|
+
e.startCol--;
|
|
77
|
+
if (lintConfig.computeEditInfo) {
|
|
78
|
+
e.suggestions = [
|
|
79
|
+
(0, lint_1.fixByRemove)(e),
|
|
80
|
+
(0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
return [e];
|
|
84
|
+
}
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
64
88
|
};
|
|
65
89
|
return HiddenToken = _classThis;
|
|
66
90
|
})();
|
|
@@ -62,6 +62,7 @@ const getUrl = (link) => {
|
|
|
62
62
|
}
|
|
63
63
|
return new URL(link).href;
|
|
64
64
|
};
|
|
65
|
+
const pdfExtensions = new Set(['djvu', 'djv', 'pdf']);
|
|
65
66
|
function validate(key, val, config, extOrType, halfParsed, accum) {
|
|
66
67
|
val = (0, string_1.removeComment)(val).trim();
|
|
67
68
|
let value = val.replace(key === 'link' ? /\0\d+[tq]\x7F/gu : /\0\d+t\x7F/gu, '').trim();
|
|
@@ -91,7 +92,7 @@ function validate(key, val, config, extOrType, halfParsed, accum) {
|
|
|
91
92
|
case 'manualthumb':
|
|
92
93
|
return true;
|
|
93
94
|
case 'page':
|
|
94
|
-
return (extOrType
|
|
95
|
+
return pdfExtensions.has(extOrType) && Number(value) > 0;
|
|
95
96
|
default:
|
|
96
97
|
return Boolean(value) && !isNaN(value);
|
|
97
98
|
}
|
|
@@ -201,7 +202,15 @@ let ImageParameterToken = (() => {
|
|
|
201
202
|
}
|
|
202
203
|
/** @private */
|
|
203
204
|
text() {
|
|
204
|
-
|
|
205
|
+
const { name } = this;
|
|
206
|
+
if (name === 'invalid') {
|
|
207
|
+
return '';
|
|
208
|
+
}
|
|
209
|
+
let str = super.text();
|
|
210
|
+
if (name !== 'caption') {
|
|
211
|
+
str = str.trim();
|
|
212
|
+
}
|
|
213
|
+
return this.#syntax ? this.#syntax.replace('$1', str).trim() : str;
|
|
205
214
|
}
|
|
206
215
|
/** @private */
|
|
207
216
|
isPlain() {
|
|
@@ -290,9 +299,12 @@ let ImageParameterToken = (() => {
|
|
|
290
299
|
LINT: {
|
|
291
300
|
const { name, childNodes } = this;
|
|
292
301
|
if (name === 'link') {
|
|
293
|
-
return (0, string_1.text)(childNodes.map(child => child.is('ext') && child.name === 'nowiki' ? child.innerText ?? '' : child));
|
|
302
|
+
return (0, string_1.text)(childNodes.map(child => child.is('ext') && child.name === 'nowiki' ? child.innerText ?? '' : child)).trim();
|
|
303
|
+
}
|
|
304
|
+
else if (name === 'invalid') {
|
|
305
|
+
return '';
|
|
294
306
|
}
|
|
295
|
-
return name === '
|
|
307
|
+
return name === 'caption' ? super.text() : this.#isVoid() || super.text().trim();
|
|
296
308
|
}
|
|
297
309
|
}
|
|
298
310
|
};
|
package/dist/src/index.js
CHANGED
|
@@ -372,12 +372,12 @@ class Token extends element_1.AstElement {
|
|
|
372
372
|
}
|
|
373
373
|
/** @private */
|
|
374
374
|
inTableAttrs() {
|
|
375
|
-
return this.isInside('table-attrs')
|
|
375
|
+
LINT: return this.isInside('table-attrs')
|
|
376
376
|
&& (this.closest('table-attrs,arg,parameter')?.is('table-attrs') ? 2 : 1);
|
|
377
377
|
}
|
|
378
378
|
/** @private */
|
|
379
379
|
inHtmlAttrs() {
|
|
380
|
-
return this.isInside('html-attrs') ? 2 : this.inTableAttrs();
|
|
380
|
+
LINT: return this.isInside('html-attrs') ? 2 : this.inTableAttrs();
|
|
381
381
|
}
|
|
382
382
|
/** @private */
|
|
383
383
|
lint(start = this.getAbsoluteIndex(), re) {
|
package/dist/src/link/base.js
CHANGED
|
@@ -41,6 +41,7 @@ exports.LinkBaseToken = void 0;
|
|
|
41
41
|
const lint_1 = require("../../util/lint");
|
|
42
42
|
const constants_1 = require("../../util/constants");
|
|
43
43
|
const debug_1 = require("../../util/debug");
|
|
44
|
+
const string_1 = require("../../util/string");
|
|
44
45
|
const rect_1 = require("../../lib/rect");
|
|
45
46
|
const padded_1 = require("../../mixin/padded");
|
|
46
47
|
const noEscape_1 = require("../../mixin/noEscape");
|
|
@@ -74,7 +75,7 @@ let LinkBaseToken = (() => {
|
|
|
74
75
|
#title;
|
|
75
76
|
/** full link / 完整链接 */
|
|
76
77
|
get link() {
|
|
77
|
-
|
|
78
|
+
return this.#title;
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* @param link 链接标题
|
|
@@ -130,7 +131,18 @@ let LinkBaseToken = (() => {
|
|
|
130
131
|
}
|
|
131
132
|
/** @private */
|
|
132
133
|
text() {
|
|
133
|
-
const
|
|
134
|
+
const { length, firstChild, childNodes, type, } = this, target = firstChild.text();
|
|
135
|
+
let str;
|
|
136
|
+
if (length === 1) {
|
|
137
|
+
str =
|
|
138
|
+
type === 'link' ?
|
|
139
|
+
(0, string_1.trimStart)(target) :
|
|
140
|
+
target.trim();
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
str = `${target.trim()}|${(0, string_1.text)(childNodes.slice(1)
|
|
144
|
+
.filter(({ type: t, name }) => t !== 'image-parameter' || name !== 'invalid'), '|')}`;
|
|
145
|
+
}
|
|
134
146
|
if (this.#bracket) {
|
|
135
147
|
return `[[${str}]]`;
|
|
136
148
|
}
|
|
@@ -7,6 +7,8 @@ import type { Token, AtomToken, AttributesToken, ExtToken } from '../../internal
|
|
|
7
7
|
* @classdesc `{childNodes: [AtomToken]}`
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class CategorytreeToken extends LinkBaseToken {
|
|
10
|
+
#private;
|
|
11
|
+
readonly name: 'categorytree';
|
|
10
12
|
readonly childNodes: readonly [AtomToken];
|
|
11
13
|
abstract get lastChild(): AtomToken;
|
|
12
14
|
abstract get nextSibling(): undefined;
|
|
@@ -80,15 +80,18 @@ 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
|
-
if (s) {
|
|
84
|
-
|
|
85
|
-
if (!link.valid || link.ns !== 14) {
|
|
86
|
-
return [(0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-category', s)];
|
|
87
|
-
}
|
|
83
|
+
if (s && this.#lint()) {
|
|
84
|
+
return [(0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-category', s)];
|
|
88
85
|
}
|
|
89
86
|
return super.lint(start, false);
|
|
90
87
|
}
|
|
91
88
|
}
|
|
89
|
+
/** 无效的分类名 */
|
|
90
|
+
#lint() {
|
|
91
|
+
const { link } = this;
|
|
92
|
+
return !link.valid
|
|
93
|
+
|| link.ns !== 14;
|
|
94
|
+
}
|
|
92
95
|
};
|
|
93
96
|
return CategorytreeToken = _classThis;
|
|
94
97
|
})();
|
package/dist/src/link/file.js
CHANGED
|
@@ -86,7 +86,7 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
86
86
|
if (s
|
|
87
87
|
&& constants_1.extensions.has(extension)
|
|
88
88
|
&& this.isInside('ext-link-text')
|
|
89
|
-
&& this.getValue('link')
|
|
89
|
+
&& this.getValue('link') !== '') {
|
|
90
90
|
const e = (0, lint_1.generateForSelf)(this, rect, rule, 'link-in-extlink', s);
|
|
91
91
|
if (computeEditInfo || fix) {
|
|
92
92
|
const link = this.getArg('link');
|
|
@@ -146,18 +146,24 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
146
146
|
* @param p1 替换$1
|
|
147
147
|
* @param severity 错误等级
|
|
148
148
|
*/
|
|
149
|
-
const generate = (tokens, msg, p1, severity = true) =>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
149
|
+
const generate = (tokens, msg, p1, severity = true) => {
|
|
150
|
+
const duplication = Array.from({ length: tokens.length });
|
|
151
|
+
for (let i = tokens.length - 1; i >= 0; i--) {
|
|
152
|
+
const arg = tokens[i];
|
|
153
|
+
s = severities[Number(typeof severity === 'function' ? severity(arg) : severity)];
|
|
154
|
+
if (!s) {
|
|
155
|
+
duplication[i] = false;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
/** `conflicting-image-parameter`或`duplicate-image-parameter` */
|
|
159
|
+
const e = (0, lint_1.generateForChild)(arg, rect, rule, index_1.default.msg(`${msg}-image-parameter`, p1), s);
|
|
160
|
+
if (computeEditInfo) {
|
|
161
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e, -1)];
|
|
162
|
+
}
|
|
163
|
+
duplication[i] = e;
|
|
158
164
|
}
|
|
159
|
-
return e;
|
|
160
|
-
}
|
|
165
|
+
return duplication.filter((e) => e !== false);
|
|
166
|
+
};
|
|
161
167
|
for (const key of keys) {
|
|
162
168
|
if (key === 'invalid' || key === 'width' && unscaled) {
|
|
163
169
|
continue;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MultiLineToken } from './index';
|
|
2
|
+
import { CharinsertLineToken } from '../singleLine/charinsertLine';
|
|
3
|
+
import type { Config, LintError } from '../../base';
|
|
4
|
+
import type { Token } from '../../internal';
|
|
5
|
+
/**
|
|
6
|
+
* `<charinsert>`
|
|
7
|
+
* @classdesc `{childNodes: CharinsertLineToken[]}`
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class CharinsertToken extends MultiLineToken {
|
|
10
|
+
readonly name: 'charinsert';
|
|
11
|
+
readonly childNodes: readonly CharinsertLineToken[];
|
|
12
|
+
abstract get firstChild(): CharinsertLineToken | undefined;
|
|
13
|
+
abstract get lastChild(): CharinsertLineToken | undefined;
|
|
14
|
+
/** @class */
|
|
15
|
+
constructor(wikitext: string | undefined, config: Config, accum?: Token[]);
|
|
16
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CharinsertToken = void 0;
|
|
7
|
+
const common_1 = require("@bhsd/common");
|
|
8
|
+
const lint_1 = require("../../util/lint");
|
|
9
|
+
const rect_1 = require("../../lib/rect");
|
|
10
|
+
const index_1 = __importDefault(require("../../index"));
|
|
11
|
+
const index_2 = require("./index");
|
|
12
|
+
const charinsertLine_1 = require("../singleLine/charinsertLine");
|
|
13
|
+
/* NOT FOR BROWSER ONLY */
|
|
14
|
+
const string_1 = require("../../util/string");
|
|
15
|
+
/* NOT FOR BROWSER ONLY END */
|
|
16
|
+
/**
|
|
17
|
+
* `<charinsert>`
|
|
18
|
+
* @classdesc `{childNodes: CharinsertLineToken[]}`
|
|
19
|
+
*/
|
|
20
|
+
class CharinsertToken extends index_2.MultiLineToken {
|
|
21
|
+
/** @class */
|
|
22
|
+
constructor(wikitext, config, accum = []) {
|
|
23
|
+
super(undefined, config, accum, {});
|
|
24
|
+
if (wikitext) {
|
|
25
|
+
this.safeAppend(wikitext.split('\n')
|
|
26
|
+
// @ts-expect-error abstract class
|
|
27
|
+
.map((line) => new charinsertLine_1.CharinsertLineToken(line, config, accum)));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** @private */
|
|
31
|
+
lint(start = this.getAbsoluteIndex()) {
|
|
32
|
+
LINT: {
|
|
33
|
+
const { name, childNodes } = this, rule = 'no-ignored', { lintConfig } = index_1.default, { computeEditInfo } = lintConfig, s = lintConfig.getSeverity(rule, name);
|
|
34
|
+
if (!s) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
const rect = new rect_1.BoundingRect(this, start), msg = index_1.default.msg('invalid-space', name), trailing = [];
|
|
38
|
+
let errors = super.lint(start), begin = false;
|
|
39
|
+
for (const child of childNodes) {
|
|
40
|
+
const str = String(child), trimmed = str.trim();
|
|
41
|
+
if (trimmed) {
|
|
42
|
+
if (begin) {
|
|
43
|
+
const n = (0, common_1.numLeadingSpaces)(str);
|
|
44
|
+
if (n) {
|
|
45
|
+
const e = (0, lint_1.generateForChild)(child, rect, rule, msg, s);
|
|
46
|
+
e.endIndex = e.startIndex + n;
|
|
47
|
+
e.endCol = e.startCol + n;
|
|
48
|
+
if (computeEditInfo) {
|
|
49
|
+
e.fix = (0, lint_1.fixByRemove)(e);
|
|
50
|
+
}
|
|
51
|
+
errors.push(e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
begin = true;
|
|
56
|
+
}
|
|
57
|
+
if (trailing.length > 0) {
|
|
58
|
+
errors = [...errors, ...trailing];
|
|
59
|
+
trailing.length = 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (begin) {
|
|
63
|
+
const [, { length }] = /(?:^|\S)(\s*)$/u.exec(str);
|
|
64
|
+
if (length) {
|
|
65
|
+
const e = (0, lint_1.generateForChild)(child, rect, rule, msg, s);
|
|
66
|
+
e.startIndex = e.endIndex - length;
|
|
67
|
+
e.startCol = e.endCol - length;
|
|
68
|
+
if (computeEditInfo) {
|
|
69
|
+
e.fix = (0, lint_1.fixByRemove)(e);
|
|
70
|
+
}
|
|
71
|
+
trailing.push(e);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return errors;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/* NOT FOR BROWSER ONLY */
|
|
79
|
+
/** @private */
|
|
80
|
+
text() {
|
|
81
|
+
return (0, string_1.text)(this.childNodes, '\n').trim();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.CharinsertToken = CharinsertToken;
|
|
@@ -48,9 +48,9 @@ class GalleryToken extends index_2.MultiLineToken {
|
|
|
48
48
|
/** @private */
|
|
49
49
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
50
50
|
LINT: {
|
|
51
|
-
const { top, left } = this.getRootNode().posFromIndex(start), errors = [], rule = 'no-ignored', { lintConfig } = index_1.default, s = ['Image', 'NoImage', 'Comment'].map(k => lintConfig.getSeverity(rule, `gallery${k}`));
|
|
52
|
-
for (let i = 0; i <
|
|
53
|
-
const child =
|
|
51
|
+
const { length: l, childNodes, name } = this, { top, left } = this.getRootNode().posFromIndex(start), errors = [], message = index_1.default.msg('invalid-content', name), rule = 'no-ignored', { lintConfig } = index_1.default, s = ['Image', 'NoImage', 'Comment'].map(k => lintConfig.getSeverity(rule, `gallery${k}`));
|
|
52
|
+
for (let i = 0; i < l; i++) {
|
|
53
|
+
const child = childNodes[i], str = child.toString(), { length } = str, trimmed = str.trim(), { type } = child, startLine = top + i, startCol = i ? 0 : left;
|
|
54
54
|
child.setAttribute('aIndex', start);
|
|
55
55
|
if (type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
|
|
56
56
|
let [severity] = s;
|
|
@@ -63,7 +63,7 @@ class GalleryToken extends index_2.MultiLineToken {
|
|
|
63
63
|
if (severity) {
|
|
64
64
|
const endIndex = start + length, e = {
|
|
65
65
|
rule,
|
|
66
|
-
message
|
|
66
|
+
message,
|
|
67
67
|
severity,
|
|
68
68
|
startIndex: start,
|
|
69
69
|
endIndex,
|
|
@@ -2,7 +2,7 @@ import Parser from '../../index';
|
|
|
2
2
|
import { MultiLineToken } from './index';
|
|
3
3
|
import { CommentLineToken } from '../nowiki/commentLine';
|
|
4
4
|
import { GalleryImageToken } from '../link/galleryImage';
|
|
5
|
-
import { ImagemapLinkToken } from '../imagemapLink';
|
|
5
|
+
import { ImagemapLinkToken } from '../singleLine/imagemapLink';
|
|
6
6
|
import type { LintError } from '../../base';
|
|
7
7
|
import type { AstText, Token } from '../../internal';
|
|
8
8
|
/**
|
|
@@ -11,7 +11,7 @@ const index_1 = __importDefault(require("../../index"));
|
|
|
11
11
|
const index_2 = require("./index");
|
|
12
12
|
const commentLine_1 = require("../nowiki/commentLine");
|
|
13
13
|
const galleryImage_1 = require("../link/galleryImage");
|
|
14
|
-
const imagemapLink_1 = require("../imagemapLink");
|
|
14
|
+
const imagemapLink_1 = require("../singleLine/imagemapLink");
|
|
15
15
|
/**
|
|
16
16
|
* `<imagemap>`
|
|
17
17
|
* @classdesc `{childNodes: [...CommentLineToken[], GalleryImageToken, ...(CommentLineToken|ImagemapLinkToken|AstText)[]]}`
|
|
@@ -52,8 +52,8 @@ class ImagemapToken extends index_2.MultiLineToken {
|
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
54
54
|
else if (line.includes('[')) {
|
|
55
|
-
const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[\[([^|]+)(?:\|([^\]]*))?\]\]
|
|
56
|
-
.exec(
|
|
55
|
+
const i = line.indexOf('['), substr = line.slice(i), trimmedSubstr = substr.trim(), mtIn = /^\[\[([^|]+)(?:\|([^\]]*))?\]\]\w*$/u
|
|
56
|
+
.exec(trimmedSubstr);
|
|
57
57
|
if (mtIn) {
|
|
58
58
|
if (this.normalizeTitle(mtIn[1], 0, { halfParsed: true, temporary: true, selfLink: true, page: '' }).valid) {
|
|
59
59
|
// @ts-expect-error abstract class
|
|
@@ -64,8 +64,8 @@ class ImagemapToken extends index_2.MultiLineToken {
|
|
|
64
64
|
else if (substr.startsWith('[//')
|
|
65
65
|
|| protocols.has(substr.slice(1, substr.indexOf(':') + 1))
|
|
66
66
|
|| protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
|
|
67
|
-
const mtEx = /^\[([^\]\s]+)(?:(\s+(?!\s))([^\]]*))?\]
|
|
68
|
-
.exec(
|
|
67
|
+
const mtEx = /^\[([^\]\s]+)(?:(\s+(?!\s))([^\]]*))?\]\w*$/u
|
|
68
|
+
.exec(trimmedSubstr);
|
|
69
69
|
if (mtEx) {
|
|
70
70
|
// @ts-expect-error abstract class
|
|
71
71
|
super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
|
|
@@ -80,7 +80,7 @@ class ImagemapToken extends index_2.MultiLineToken {
|
|
|
80
80
|
/** @private */
|
|
81
81
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
82
82
|
LINT: {
|
|
83
|
-
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), { childNodes, image } = this, rule = 'invalid-imagemap', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, image ? 'link' : 'image');
|
|
83
|
+
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), { childNodes, image } = this, rule = 'invalid-imagemap', { lintConfig } = index_1.default, { computeEditInfo } = lintConfig, s = lintConfig.getSeverity(rule, image ? 'link' : 'image');
|
|
84
84
|
if (s) {
|
|
85
85
|
if (image) {
|
|
86
86
|
Array.prototype.push.apply(errors, childNodes.filter(child => {
|
|
@@ -89,7 +89,7 @@ class ImagemapToken extends index_2.MultiLineToken {
|
|
|
89
89
|
&& str && !str.startsWith('#');
|
|
90
90
|
}).map(child => {
|
|
91
91
|
const e = (0, lint_1.generateForChild)(child, rect, rule, 'invalid-imagemap-link', s);
|
|
92
|
-
if (
|
|
92
|
+
if (computeEditInfo) {
|
|
93
93
|
e.suggestions = [
|
|
94
94
|
(0, lint_1.fixByRemove)(e, -1),
|
|
95
95
|
(0, lint_1.fixBy)(e, 'comment', '# '),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Parser from '../../index';
|
|
1
2
|
import { Token } from '../index';
|
|
2
3
|
import type { AttributesToken, ExtToken } from '../../internal';
|
|
3
4
|
/**
|
|
@@ -11,4 +12,6 @@ export declare abstract class MultiLineToken extends Token {
|
|
|
11
12
|
abstract get previousSibling(): AttributesToken | undefined;
|
|
12
13
|
abstract get parentNode(): ExtToken | undefined;
|
|
13
14
|
get type(): 'ext-inner';
|
|
15
|
+
/** @class */
|
|
16
|
+
constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: WikiParserAcceptable);
|
|
14
17
|
}
|