wikiparser-node 1.25.1 → 1.27.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/bundle/bundle-es8.min.js +25 -25
- package/bundle/bundle-lsp.min.js +30 -30
- package/bundle/bundle.min.js +23 -23
- package/config/default.json +3 -0
- package/config/enwiki.json +3 -0
- package/config/jawiki.json +3 -0
- package/config/minimum.json +1 -0
- package/config/moegirl.json +0 -20
- package/config/zhwiki.json +3 -0
- package/coverage/badge.svg +1 -1
- package/data/.schema.json +2 -1
- package/data/ext/math.json +41 -0
- package/data/signatures.json +82 -16
- package/dist/base.d.mts +16 -4
- package/dist/base.d.ts +16 -4
- package/dist/bin/config.js +8 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -3
- package/dist/lib/document.js +6 -0
- package/dist/lib/element.js +1 -1
- package/dist/lib/lintConfig.d.ts +18 -7
- package/dist/lib/lintConfig.js +68 -21
- package/dist/lib/lsp.js +16 -8
- package/dist/lib/text.js +36 -34
- package/dist/src/arg.js +8 -6
- package/dist/src/attribute.js +37 -27
- package/dist/src/attributes.js +23 -15
- package/dist/src/converterFlags.js +9 -7
- package/dist/src/gallery.js +7 -5
- package/dist/src/heading.js +35 -25
- package/dist/src/html.js +38 -29
- package/dist/src/imageParameter.js +14 -7
- package/dist/src/imagemap.js +7 -5
- package/dist/src/index.js +51 -42
- package/dist/src/link/base.js +19 -11
- package/dist/src/link/file.js +32 -19
- package/dist/src/link/galleryImage.js +4 -2
- package/dist/src/link/index.js +4 -2
- package/dist/src/link/redirectTarget.js +4 -2
- package/dist/src/magicLink.js +13 -10
- package/dist/src/nested.js +7 -5
- package/dist/src/nowiki/comment.js +5 -3
- package/dist/src/nowiki/index.js +4 -2
- package/dist/src/nowiki/quote.js +10 -6
- package/dist/src/paramTag/index.js +4 -2
- package/dist/src/parameter.js +4 -2
- package/dist/src/table/index.js +1 -1
- package/dist/src/table/td.js +9 -7
- package/dist/src/tagPair/ext.js +3 -3
- package/dist/src/tagPair/include.js +7 -3
- package/dist/src/transclude.js +13 -7
- package/dist/util/html.js +2 -1
- package/extensions/dist/base.js +1 -1
- package/extensions/editor.css +2 -2
- package/i18n/en.json +14 -13
- package/i18n/zh-hans.json +19 -18
- package/i18n/zh-hant.json +31 -30
- package/package.json +5 -5
|
@@ -151,22 +151,24 @@ let ConverterFlagsToken = (() => {
|
|
|
151
151
|
/** @private */
|
|
152
152
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
153
153
|
LINT: { // eslint-disable-line no-unused-labels
|
|
154
|
-
const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags(), validFlags = new Set(this.#flags.filter(flag => definedFlags.has(flag))), emptyFlagCount = this.#flags.filter(flag => !flag).length, knownFlagCount = this.#flags.length - unknownFlags.size - emptyFlagCount, errors = super.lint(start, re);
|
|
154
|
+
const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags(), validFlags = new Set(this.#flags.filter(flag => definedFlags.has(flag))), emptyFlagCount = this.#flags.filter(flag => !flag).length, knownFlagCount = this.#flags.length - unknownFlags.size - emptyFlagCount, { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, errors = super.lint(start, re);
|
|
155
155
|
if (variantFlags.size === knownFlagCount || validFlags.size === knownFlagCount) {
|
|
156
156
|
return errors;
|
|
157
157
|
}
|
|
158
|
-
const rule = 'no-ignored', s =
|
|
158
|
+
const rule = 'no-ignored', s = lintConfig.getSeverity(rule, 'conversionFlag');
|
|
159
159
|
if (s) {
|
|
160
160
|
const rect = new rect_1.BoundingRect(this, start);
|
|
161
161
|
for (let i = 0; i < this.length; i++) {
|
|
162
162
|
const child = this.childNodes[i], flag = child.text().trim();
|
|
163
163
|
if (this.isInvalidFlag(flag, variantFlags, unknownFlags, validFlags)) {
|
|
164
164
|
const e = (0, lint_1.generateForChild)(child, rect, rule, 'invalid-conversion-flag', s);
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
if (computeEditInfo || fix) {
|
|
166
|
+
if (variantFlags.size === 0 && definedFlags.has(flag.toUpperCase())) {
|
|
167
|
+
e.fix = (0, lint_1.fixByUpper)(e, flag);
|
|
168
|
+
}
|
|
169
|
+
else if (computeEditInfo) {
|
|
170
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e, i && -1)];
|
|
171
|
+
}
|
|
170
172
|
}
|
|
171
173
|
errors.push(e);
|
|
172
174
|
}
|
package/dist/src/gallery.js
CHANGED
|
@@ -142,7 +142,7 @@ let GalleryToken = (() => {
|
|
|
142
142
|
/** @private */
|
|
143
143
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
144
144
|
LINT: { // eslint-disable-line no-unused-labels
|
|
145
|
-
const { top, left } = this.getRootNode().posFromIndex(start), errors = [], rule = 'no-ignored', s = ['Image', 'NoImage', 'Comment'].map(k =>
|
|
145
|
+
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}`));
|
|
146
146
|
for (let i = 0; i < this.length; i++) {
|
|
147
147
|
const child = this.childNodes[i], str = child.toString(), { length } = str, trimmed = str.trim(), { type } = child, startLine = top + i, startCol = i ? 0 : left;
|
|
148
148
|
child.setAttribute('aIndex', start);
|
|
@@ -166,10 +166,12 @@ let GalleryToken = (() => {
|
|
|
166
166
|
startCol,
|
|
167
167
|
endCol: startCol + length,
|
|
168
168
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
if (lintConfig.computeEditInfo) {
|
|
170
|
+
e.suggestions = [
|
|
171
|
+
(0, lint_1.fixByRemove)(e),
|
|
172
|
+
(0, lint_1.fixByComment)(e, str),
|
|
173
|
+
];
|
|
174
|
+
}
|
|
173
175
|
errors.push(e);
|
|
174
176
|
}
|
|
175
177
|
}
|
package/dist/src/heading.js
CHANGED
|
@@ -157,17 +157,17 @@ let HeadingToken = (() => {
|
|
|
157
157
|
/** @private */
|
|
158
158
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
159
159
|
LINT: { // eslint-disable-line no-unused-labels
|
|
160
|
-
const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), unbalancedStart = innerStr.startsWith('='), unbalanced = unbalancedStart || innerStr.endsWith('='), rect = new rect_1.BoundingRect(this, start), s = this.inHtmlAttrs(), rules = ['h1', 'unbalanced-header', 'format-leakage'], severities = rules.map(rule =>
|
|
160
|
+
const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), unbalancedStart = innerStr.startsWith('='), unbalanced = unbalancedStart || innerStr.endsWith('='), 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'));
|
|
161
161
|
if (severities[0] && this.level === 1) {
|
|
162
162
|
const e = (0, lint_1.generateForChild)(firstChild, rect, rules[0], '<h1>', severities[0]);
|
|
163
|
-
if (!unbalanced) {
|
|
163
|
+
if (computeEditInfo && !unbalanced) {
|
|
164
164
|
e.suggestions = [(0, lint_1.fixBy)(e, 'h2', `=${innerStr}=`)];
|
|
165
165
|
}
|
|
166
166
|
errors.push(e);
|
|
167
167
|
}
|
|
168
168
|
if (severities[1] && unbalanced) {
|
|
169
169
|
const msg = index_1.default.msg('unbalanced-in-section-header', '"="'), e = (0, lint_1.generateForChild)(firstChild, rect, rules[1], msg, severities[1]);
|
|
170
|
-
if (innerStr === '=') {
|
|
170
|
+
if (!computeEditInfo || innerStr === '=') {
|
|
171
171
|
//
|
|
172
172
|
}
|
|
173
173
|
else if (unbalancedStart) {
|
|
@@ -187,7 +187,7 @@ let HeadingToken = (() => {
|
|
|
187
187
|
errors.push(e);
|
|
188
188
|
}
|
|
189
189
|
if (s) {
|
|
190
|
-
const rule = 'parsing-order', severity =
|
|
190
|
+
const rule = 'parsing-order', severity = lintConfig.getSeverity(rule, s === 2 ? 'heading' : 'templateInTable');
|
|
191
191
|
if (severity) {
|
|
192
192
|
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'header-in-html', severity));
|
|
193
193
|
}
|
|
@@ -199,31 +199,41 @@ let HeadingToken = (() => {
|
|
|
199
199
|
...rect, // eslint-disable-line @typescript-eslint/no-misused-spread
|
|
200
200
|
start: start + level,
|
|
201
201
|
left: rect.left + level,
|
|
202
|
-
}, rules[2], index_1.default.msg('unbalanced-in-section-header', 'bold-apostrophes'), severities[2])
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
202
|
+
}, rules[2], index_1.default.msg('unbalanced-in-section-header', 'bold-apostrophes'), severities[2]);
|
|
203
|
+
if (computeEditInfo || fix) {
|
|
204
|
+
const end = start + level + innerStr.length, remove = (0, lint_1.fixByRemove)(e);
|
|
205
|
+
if (rootStr.slice(e.endIndex, end).trim()) {
|
|
206
|
+
if (computeEditInfo) {
|
|
207
|
+
e.suggestions = [
|
|
208
|
+
remove,
|
|
209
|
+
(0, lint_1.fixByClose)(end, `'''`),
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (boldQuotes.length === 1 && italicQuotes.length === 0) {
|
|
214
|
+
e.fix = remove;
|
|
215
|
+
}
|
|
216
|
+
else if (computeEditInfo) {
|
|
217
|
+
e.suggestions = [remove];
|
|
218
|
+
}
|
|
214
219
|
}
|
|
215
220
|
errors.push(e);
|
|
216
221
|
}
|
|
217
222
|
if (italicQuotes.length % 2) {
|
|
218
|
-
const e = (0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, rules[2], index_1.default.msg('unbalanced-in-section-header', 'italic-apostrophes'), severities[2])
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
223
|
+
const e = (0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, rules[2], index_1.default.msg('unbalanced-in-section-header', 'italic-apostrophes'), severities[2]);
|
|
224
|
+
if (computeEditInfo || fix) {
|
|
225
|
+
const end = start + level + innerStr.length;
|
|
226
|
+
if (rootStr.slice(e.endIndex, end).trim()) {
|
|
227
|
+
if (computeEditInfo) {
|
|
228
|
+
e.suggestions = [(0, lint_1.fixByClose)(end, `''`)];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else if (italicQuotes.length === 1 && boldQuotes.length === 0) {
|
|
232
|
+
e.fix = (0, lint_1.fixByRemove)(e);
|
|
233
|
+
}
|
|
234
|
+
else if (computeEditInfo) {
|
|
235
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
236
|
+
}
|
|
227
237
|
}
|
|
228
238
|
errors.push(e);
|
|
229
239
|
}
|
package/dist/src/html.js
CHANGED
|
@@ -193,56 +193,65 @@ let HtmlToken = (() => {
|
|
|
193
193
|
/** @private */
|
|
194
194
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
195
195
|
LINT: { // eslint-disable-line no-unused-labels
|
|
196
|
-
const errors = super.lint(start, re), { name, parentNode, closing, selfClosing } = this, rect = new rect_1.BoundingRect(this, start), severity = this.inTableAttrs();
|
|
197
|
-
let rule = 'h1', s =
|
|
196
|
+
const errors = super.lint(start, re), { name, parentNode, closing, selfClosing } = this, rect = new rect_1.BoundingRect(this, start), { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, severity = this.inTableAttrs();
|
|
197
|
+
let rule = 'h1', s = lintConfig.getSeverity(rule, 'html');
|
|
198
198
|
if (s && name === 'h1' && !closing) {
|
|
199
199
|
const e = (0, lint_1.generateForSelf)(this, rect, rule, '<h1>', s);
|
|
200
|
-
|
|
200
|
+
if (computeEditInfo) {
|
|
201
|
+
e.suggestions = [{ desc: 'h2', range: [start + 2, start + 3], text: '2' }];
|
|
202
|
+
}
|
|
201
203
|
errors.push(e);
|
|
202
204
|
}
|
|
203
205
|
rule = 'parsing-order';
|
|
204
|
-
s = severity &&
|
|
206
|
+
s = severity && lintConfig.getSeverity(rule, severity === 2 ? 'html' : 'templateInTable');
|
|
205
207
|
if (s) {
|
|
206
208
|
const e = (0, lint_1.generateForSelf)(this, rect, rule, 'html-in-table', s);
|
|
207
|
-
if (severity === 2) {
|
|
209
|
+
if (computeEditInfo && severity === 2) {
|
|
208
210
|
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
209
211
|
}
|
|
210
212
|
errors.push(e);
|
|
211
213
|
}
|
|
212
214
|
rule = 'obsolete-tag';
|
|
213
|
-
s =
|
|
215
|
+
s = lintConfig.getSeverity(rule, name);
|
|
214
216
|
if (s && obsoleteTags.has(name)) {
|
|
215
217
|
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'obsolete-tag', s));
|
|
216
218
|
}
|
|
217
219
|
rule = 'bold-header';
|
|
218
|
-
s =
|
|
220
|
+
s = lintConfig.getSeverity(rule, name);
|
|
219
221
|
if (s && (name === 'b' || name === 'strong')
|
|
220
222
|
&& this.closest('heading-title,ext')?.type === 'heading-title') {
|
|
221
223
|
const e = (0, lint_1.generateForSelf)(this, rect, rule, 'bold-in-header', s);
|
|
222
|
-
|
|
224
|
+
if (computeEditInfo) {
|
|
225
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
226
|
+
}
|
|
223
227
|
errors.push(e);
|
|
224
228
|
}
|
|
225
229
|
const { html: [, flexibleTags, voidTags] } = this.getAttribute('config'), isVoid = voidTags.includes(name), isFlexible = flexibleTags.includes(name), isNormal = !isVoid && !isFlexible;
|
|
226
230
|
rule = 'unmatched-tag';
|
|
227
231
|
if (closing && (selfClosing || isVoid) || selfClosing && isNormal) {
|
|
228
|
-
s =
|
|
232
|
+
s = lintConfig.getSeverity(rule, closing ? 'both' : 'selfClosing');
|
|
229
233
|
if (s) {
|
|
230
|
-
const e = (0, lint_1.generateForSelf)(this, rect, rule, closing ? 'closing-and-self-closing' : 'invalid-self-closing', s)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
noSelfClosing
|
|
244
|
-
|
|
245
|
-
|
|
234
|
+
const e = (0, lint_1.generateForSelf)(this, rect, rule, closing ? 'closing-and-self-closing' : 'invalid-self-closing', s);
|
|
235
|
+
if (computeEditInfo || fix) {
|
|
236
|
+
const open = (0, lint_1.fixByOpen)(start), noSelfClosing = {
|
|
237
|
+
desc: index_1.default.msg('no-self-closing'),
|
|
238
|
+
range: [e.endIndex - 2, e.endIndex - 1],
|
|
239
|
+
text: '',
|
|
240
|
+
};
|
|
241
|
+
if (isFlexible) {
|
|
242
|
+
if (computeEditInfo) {
|
|
243
|
+
e.suggestions = [open, noSelfClosing];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else if (closing) {
|
|
247
|
+
e.fix = isVoid ? open : noSelfClosing;
|
|
248
|
+
}
|
|
249
|
+
else if (computeEditInfo) {
|
|
250
|
+
e.suggestions = [
|
|
251
|
+
noSelfClosing,
|
|
252
|
+
(0, lint_1.fixByClose)(e.endIndex, `></${name}>`, -2),
|
|
253
|
+
];
|
|
254
|
+
}
|
|
246
255
|
}
|
|
247
256
|
errors.push(e);
|
|
248
257
|
}
|
|
@@ -250,14 +259,14 @@ let HtmlToken = (() => {
|
|
|
250
259
|
else if (!this.findMatchingTag()) {
|
|
251
260
|
const error = (0, lint_1.generateForSelf)(this, rect, rule, closing ? 'unmatched-closing' : 'unclosed-tag'), ancestor = this.closest('magic-word');
|
|
252
261
|
if (ancestor && magicWords.has(ancestor.name)) {
|
|
253
|
-
s =
|
|
262
|
+
s = lintConfig.getSeverity(rule, 'conditional');
|
|
254
263
|
}
|
|
255
264
|
else if (closing) {
|
|
256
|
-
s =
|
|
265
|
+
s = lintConfig.getSeverity(rule, 'closing');
|
|
257
266
|
error.suggestions = [(0, lint_1.fixByRemove)(error)];
|
|
258
267
|
}
|
|
259
268
|
else {
|
|
260
|
-
s =
|
|
269
|
+
s = lintConfig.getSeverity(rule, 'opening');
|
|
261
270
|
const childNodes = parentNode?.childNodes;
|
|
262
271
|
if (formattingTags.has(name)) {
|
|
263
272
|
if (childNodes?.slice(0, childNodes.indexOf(this)).some(tag => tag.type === 'html' && tag.name === name && !tag.findMatchingTag())) {
|
|
@@ -265,7 +274,7 @@ let HtmlToken = (() => {
|
|
|
265
274
|
}
|
|
266
275
|
if (this.closest('heading-title')) {
|
|
267
276
|
error.rule = 'format-leakage';
|
|
268
|
-
s =
|
|
277
|
+
s = lintConfig.getSeverity('format-leakage', name);
|
|
269
278
|
}
|
|
270
279
|
}
|
|
271
280
|
}
|
|
@@ -7,11 +7,11 @@ exports.ImageParameterToken = exports.galleryParams = void 0;
|
|
|
7
7
|
const common_1 = require("@bhsd/common");
|
|
8
8
|
const string_1 = require("../util/string");
|
|
9
9
|
const lint_1 = require("../util/lint");
|
|
10
|
+
const constants_1 = require("../util/constants");
|
|
10
11
|
const index_1 = __importDefault(require("../index"));
|
|
11
12
|
const index_2 = require("./index");
|
|
12
13
|
/* NOT FOR BROWSER */
|
|
13
14
|
const debug_1 = require("../util/debug");
|
|
14
|
-
const constants_1 = require("../util/constants");
|
|
15
15
|
/* NOT FOR BROWSER END */
|
|
16
16
|
/^(?:ftp:\/\/|\/\/|\0\d+m\x7F)/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
|
|
17
17
|
const getUrlLikeRegex = (0, common_1.getRegex)(protocol => new RegExp(String.raw `^(?:${protocol}|//|\0\d+m\x7F)`, 'iu'));
|
|
@@ -151,6 +151,9 @@ class ImageParameterToken extends index_2.Token {
|
|
|
151
151
|
this.#syntax = mt[1] + param[0] + mt[3];
|
|
152
152
|
}
|
|
153
153
|
this.setAttribute('name', param[1]);
|
|
154
|
+
if (param[1] === 'alt') {
|
|
155
|
+
this.setAttribute('stage', constants_1.MAX_STAGE - 1);
|
|
156
|
+
}
|
|
154
157
|
return;
|
|
155
158
|
}
|
|
156
159
|
super(str, config.excludes.includes('list')
|
|
@@ -181,7 +184,7 @@ class ImageParameterToken extends index_2.Token {
|
|
|
181
184
|
}
|
|
182
185
|
/** @private */
|
|
183
186
|
isPlain() {
|
|
184
|
-
return this.name === 'caption';
|
|
187
|
+
return this.name === 'caption' || this.name === 'alt';
|
|
185
188
|
}
|
|
186
189
|
/** @private */
|
|
187
190
|
getAttribute(key) {
|
|
@@ -197,20 +200,24 @@ class ImageParameterToken extends index_2.Token {
|
|
|
197
200
|
/** @private */
|
|
198
201
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
199
202
|
LINT: { // eslint-disable-line no-unused-labels
|
|
200
|
-
const errors = super.lint(start, re), { link, name } = this;
|
|
203
|
+
const errors = super.lint(start, re), { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, { link, name } = this;
|
|
201
204
|
if (name === 'invalid') {
|
|
202
|
-
const rule = 'invalid-gallery', s =
|
|
205
|
+
const rule = 'invalid-gallery', s = lintConfig.getSeverity(rule, 'parameter');
|
|
203
206
|
if (s) {
|
|
204
207
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-image-parameter', s);
|
|
205
|
-
|
|
208
|
+
if (computeEditInfo || fix) {
|
|
209
|
+
e.fix = (0, lint_1.fixByRemove)(e, -1);
|
|
210
|
+
}
|
|
206
211
|
errors.push(e);
|
|
207
212
|
}
|
|
208
213
|
}
|
|
209
214
|
else if (typeof link === 'object' && link.encoded) {
|
|
210
|
-
const rule = 'url-encoding', s =
|
|
215
|
+
const rule = 'url-encoding', s = lintConfig.getSeverity(rule, 'file');
|
|
211
216
|
if (s) {
|
|
212
217
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'unnecessary-encoding', s);
|
|
213
|
-
|
|
218
|
+
if (computeEditInfo || fix) {
|
|
219
|
+
e.fix = (0, lint_1.fixByDecode)(e, this);
|
|
220
|
+
}
|
|
214
221
|
errors.push(e);
|
|
215
222
|
}
|
|
216
223
|
}
|
package/dist/src/imagemap.js
CHANGED
|
@@ -149,7 +149,7 @@ let ImagemapToken = (() => {
|
|
|
149
149
|
/** @private */
|
|
150
150
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
151
151
|
LINT: { // eslint-disable-line no-unused-labels
|
|
152
|
-
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), { childNodes, image } = this, rule = 'invalid-imagemap',
|
|
152
|
+
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');
|
|
153
153
|
if (s) {
|
|
154
154
|
if (image) {
|
|
155
155
|
errors.push(...childNodes.filter(child => {
|
|
@@ -157,10 +157,12 @@ let ImagemapToken = (() => {
|
|
|
157
157
|
return child.is('noinclude') && str && !str.startsWith('#');
|
|
158
158
|
}).map(child => {
|
|
159
159
|
const e = (0, lint_1.generateForChild)(child, rect, rule, 'invalid-imagemap-link', s);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
if (lintConfig.computeEditInfo) {
|
|
161
|
+
e.suggestions = [
|
|
162
|
+
(0, lint_1.fixByRemove)(e, -1),
|
|
163
|
+
(0, lint_1.fixBy)(e, 'comment', '# '),
|
|
164
|
+
];
|
|
165
|
+
}
|
|
164
166
|
return e;
|
|
165
167
|
}));
|
|
166
168
|
}
|
package/dist/src/index.js
CHANGED
|
@@ -525,9 +525,10 @@ let Token = (() => {
|
|
|
525
525
|
/** @private */
|
|
526
526
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
527
527
|
LINT: { // eslint-disable-line no-unused-labels
|
|
528
|
+
const { lintConfig } = index_1.default, { computeEditInfo, fix: needFix, ignoreDisables, configurationComment } = lintConfig;
|
|
528
529
|
let errors = super.lint(start, re);
|
|
529
530
|
if (this.type === 'root') {
|
|
530
|
-
const record = new Map(), r = 'no-duplicate', s = ['category', 'id'].map(key =>
|
|
531
|
+
const record = new Map(), r = 'no-duplicate', s = ['category', 'id'].map(key => lintConfig.getSeverity(r, key)), wikitext = this.toString(), selector = lintSelectors.filter((_, i) => s[i]).join();
|
|
531
532
|
if (selector) {
|
|
532
533
|
for (const cat of this.querySelectorAll(selector)) {
|
|
533
534
|
let key;
|
|
@@ -555,7 +556,7 @@ let Token = (() => {
|
|
|
555
556
|
const isCat = !key.startsWith('#'), msg = `duplicate-${isCat ? 'category' : 'id'}`, severity = s[isCat ? 0 : 1];
|
|
556
557
|
errors.push(...[...value].map(cat => {
|
|
557
558
|
const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, r, msg, severity);
|
|
558
|
-
if (isCat) {
|
|
559
|
+
if (computeEditInfo && isCat) {
|
|
559
560
|
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
560
561
|
}
|
|
561
562
|
return e;
|
|
@@ -563,42 +564,44 @@ let Token = (() => {
|
|
|
563
564
|
}
|
|
564
565
|
}
|
|
565
566
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
567
|
+
if (!ignoreDisables) {
|
|
568
|
+
const regex = new RegExp(String.raw `<!--\s*${configurationComment}-(disable(?:(?:-next)?-line)?|enable)(\s[\sa-z,-]*)?-->`, 'gu'), ignores = [];
|
|
569
|
+
let mt = regex.exec(wikitext);
|
|
570
|
+
while (mt) {
|
|
571
|
+
const { 1: type, index } = mt, detail = mt[2]?.trim();
|
|
572
|
+
ignores.push({
|
|
573
|
+
line: this.posFromIndex(index).top + (type === 'disable-line' ? 0 : 1),
|
|
574
|
+
from: type === 'disable' ? regex.lastIndex : undefined,
|
|
575
|
+
to: type === 'enable' ? regex.lastIndex : undefined,
|
|
576
|
+
rules: detail ? new Set(detail.split(',').map(rule => rule.trim())) : undefined,
|
|
577
|
+
});
|
|
578
|
+
mt = regex.exec(wikitext);
|
|
579
|
+
}
|
|
580
|
+
errors = errors.filter(({ rule, startLine, startIndex }) => {
|
|
581
|
+
const nearest = { pos: 0 };
|
|
582
|
+
for (const { line, from, to, rules } of ignores) {
|
|
583
|
+
if (line > startLine + 1) {
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
else if (rules && !rules.has(rule)) {
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
else if (line === startLine && from === undefined && to === undefined) {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
else if (from <= startIndex && from > nearest.pos) {
|
|
593
|
+
nearest.pos = from;
|
|
594
|
+
nearest.type = 'from';
|
|
595
|
+
}
|
|
596
|
+
else if (to <= startIndex && to > nearest.pos) {
|
|
597
|
+
nearest.pos = to;
|
|
598
|
+
nearest.type = 'to';
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return nearest.type !== 'from';
|
|
575
602
|
});
|
|
576
|
-
mt = regex.exec(wikitext);
|
|
577
603
|
}
|
|
578
|
-
|
|
579
|
-
const nearest = { pos: 0 };
|
|
580
|
-
for (const { line, from, to, rules } of ignores) {
|
|
581
|
-
if (line > startLine + 1) {
|
|
582
|
-
break;
|
|
583
|
-
}
|
|
584
|
-
else if (rules && !rules.has(rule)) {
|
|
585
|
-
continue;
|
|
586
|
-
}
|
|
587
|
-
else if (line === startLine && from === undefined && to === undefined) {
|
|
588
|
-
return false;
|
|
589
|
-
}
|
|
590
|
-
else if (from <= startIndex && from > nearest.pos) {
|
|
591
|
-
nearest.pos = from;
|
|
592
|
-
nearest.type = 'from';
|
|
593
|
-
}
|
|
594
|
-
else if (to <= startIndex && to > nearest.pos) {
|
|
595
|
-
nearest.pos = to;
|
|
596
|
-
nearest.type = 'to';
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
return nearest.type !== 'from';
|
|
600
|
-
});
|
|
601
|
-
if (errors.some(({ fix }) => fix)) {
|
|
604
|
+
if (needFix && errors.some(({ fix }) => fix)) {
|
|
602
605
|
// 倒序修复,跳过嵌套的修复
|
|
603
606
|
const fixable = errors.map(({ fix }) => fix).filter(Boolean).sort(({ range: [aFrom, aTo] }, { range: [bFrom, bTo] }) => aTo === bTo ? bFrom - aFrom : bTo - aTo);
|
|
604
607
|
let i = Infinity, output = wikitext;
|
|
@@ -610,20 +613,26 @@ let Token = (() => {
|
|
|
610
613
|
}
|
|
611
614
|
Object.assign(errors, { output });
|
|
612
615
|
}
|
|
616
|
+
if (!computeEditInfo) {
|
|
617
|
+
for (const e of errors) {
|
|
618
|
+
delete e.fix;
|
|
619
|
+
delete e.suggestions;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
613
622
|
/* NOT FOR BROWSER ONLY */
|
|
614
623
|
}
|
|
615
|
-
else if (
|
|
616
|
-
const rule = 'invalid-css', s =
|
|
617
|
-
if (s) {
|
|
624
|
+
else if ((0, lsp_1.isAttr)(this, true)) {
|
|
625
|
+
const rule = 'invalid-css', s = lintConfig.getSeverity(rule), sWarn = lintConfig.getSeverity(rule, 'warn');
|
|
626
|
+
if (s || sWarn) {
|
|
618
627
|
const root = this.getRootNode(), textDoc = new document_1.EmbeddedCSSDocument(root, this);
|
|
619
628
|
errors.push(...document_1.cssLSP.doValidation(textDoc, textDoc.styleSheet)
|
|
620
629
|
.filter(({ code, severity }) => code !== 'css-ruleorselectorexpected' && code !== 'emptyRules'
|
|
621
|
-
&& (
|
|
630
|
+
&& (severity === 1 ? s : sWarn))
|
|
622
631
|
.map(({ range: { start: { line, character }, end }, message, severity, code }) => ({
|
|
623
632
|
code: code,
|
|
624
|
-
rule
|
|
633
|
+
rule,
|
|
625
634
|
message,
|
|
626
|
-
severity: severity === 1 ? s : sWarn,
|
|
635
|
+
severity: (severity === 1 ? s : sWarn),
|
|
627
636
|
startLine: line,
|
|
628
637
|
startCol: character,
|
|
629
638
|
startIndex: root.indexFromPos(line, character),
|
package/dist/src/link/base.js
CHANGED
|
@@ -215,34 +215,42 @@ let LinkBaseToken = (() => {
|
|
|
215
215
|
/** @private */
|
|
216
216
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
217
217
|
LINT: { // eslint-disable-line no-unused-labels
|
|
218
|
-
const errors = super.lint(start, re), { childNodes: [target, linkText], type } = this, { encoded, fragment } = this.#title, rect = new rect_1.BoundingRect(this, start);
|
|
219
|
-
let rule = 'unknown-page', s =
|
|
218
|
+
const errors = super.lint(start, re), { childNodes: [target, linkText], type } = this, { encoded, fragment } = this.#title, { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, rect = new rect_1.BoundingRect(this, start);
|
|
219
|
+
let rule = 'unknown-page', s = lintConfig.getSeverity(rule);
|
|
220
220
|
if (s && target.childNodes.some(({ type: t }) => t === 'template')) {
|
|
221
221
|
errors.push((0, lint_1.generateForChild)(target, rect, rule, 'template-in-link', s));
|
|
222
222
|
}
|
|
223
223
|
rule = 'url-encoding';
|
|
224
|
-
s =
|
|
224
|
+
s = lintConfig.getSeverity(rule);
|
|
225
225
|
if (s && encoded) {
|
|
226
226
|
const e = (0, lint_1.generateForChild)(target, rect, rule, 'unnecessary-encoding', s);
|
|
227
|
-
|
|
227
|
+
if (computeEditInfo || fix) {
|
|
228
|
+
e.fix = (0, lint_1.fixByDecode)(e, target);
|
|
229
|
+
}
|
|
228
230
|
errors.push(e);
|
|
229
231
|
}
|
|
230
232
|
rule = 'pipe-like';
|
|
231
|
-
s =
|
|
233
|
+
s = lintConfig.getSeverity(rule, 'link');
|
|
232
234
|
if (s && (type === 'link' || type === 'category')) {
|
|
233
235
|
const j = linkText?.childNodes.findIndex(c => c.type === 'text' && c.data.includes('|')), textNode = linkText?.childNodes[j];
|
|
234
236
|
if (textNode) {
|
|
235
|
-
const e = (0, lint_1.generateForChild)(linkText, rect, rule, 'pipe-in-link', s)
|
|
236
|
-
|
|
237
|
+
const e = (0, lint_1.generateForChild)(linkText, rect, rule, 'pipe-in-link', s);
|
|
238
|
+
if (computeEditInfo) {
|
|
239
|
+
const i = e.startIndex + linkText.getRelativeIndex(j);
|
|
240
|
+
e.suggestions = [(0, lint_1.fixByPipe)(i, textNode.data)];
|
|
241
|
+
}
|
|
237
242
|
errors.push(e);
|
|
238
243
|
}
|
|
239
244
|
}
|
|
240
245
|
rule = 'no-ignored';
|
|
241
|
-
s =
|
|
246
|
+
s = lintConfig.getSeverity(rule, 'fragment');
|
|
242
247
|
if (s && fragment !== undefined && !isLink(type)) {
|
|
243
|
-
const e = (0, lint_1.generateForChild)(target, rect, rule, 'useless-fragment', s)
|
|
244
|
-
if (
|
|
245
|
-
|
|
248
|
+
const e = (0, lint_1.generateForChild)(target, rect, rule, 'useless-fragment', s);
|
|
249
|
+
if (computeEditInfo || fix) {
|
|
250
|
+
const j = target.childNodes.findIndex(c => c.type === 'text' && c.data.includes('#')), textNode = target.childNodes[j];
|
|
251
|
+
if (textNode) {
|
|
252
|
+
e.fix = (0, lint_1.fixByRemove)(e, target.getRelativeIndex(j) + textNode.data.indexOf('#'));
|
|
253
|
+
}
|
|
246
254
|
}
|
|
247
255
|
errors.push(e);
|
|
248
256
|
}
|