wikiparser-node 1.25.1 → 1.26.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 +20 -20
- 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/data/ext/math.json +41 -0
- package/dist/base.d.mts +15 -3
- package/dist/base.d.ts +15 -3
- package/dist/bin/config.js +8 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -3
- package/dist/lib/element.js +1 -1
- package/dist/lib/lintConfig.d.ts +18 -7
- package/dist/lib/lintConfig.js +55 -15
- package/dist/lib/lsp.js +16 -8
- package/dist/lib/text.js +35 -33
- package/dist/src/arg.js +8 -6
- package/dist/src/attribute.js +23 -13
- 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 +9 -5
- package/dist/src/imagemap.js +7 -5
- package/dist/src/index.js +50 -41
- package/dist/src/link/base.js +19 -11
- package/dist/src/link/file.js +24 -18
- 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 +4 -2
- 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/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/extensions/dist/base.js +1 -1
- package/extensions/editor.css +2 -2
- package/package.json +5 -5
|
@@ -197,20 +197,24 @@ class ImageParameterToken extends index_2.Token {
|
|
|
197
197
|
/** @private */
|
|
198
198
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
199
199
|
LINT: { // eslint-disable-line no-unused-labels
|
|
200
|
-
const errors = super.lint(start, re), { link, name } = this;
|
|
200
|
+
const errors = super.lint(start, re), { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, { link, name } = this;
|
|
201
201
|
if (name === 'invalid') {
|
|
202
|
-
const rule = 'invalid-gallery', s =
|
|
202
|
+
const rule = 'invalid-gallery', s = lintConfig.getSeverity(rule, 'parameter');
|
|
203
203
|
if (s) {
|
|
204
204
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-image-parameter', s);
|
|
205
|
-
|
|
205
|
+
if (computeEditInfo || fix) {
|
|
206
|
+
e.fix = (0, lint_1.fixByRemove)(e, -1);
|
|
207
|
+
}
|
|
206
208
|
errors.push(e);
|
|
207
209
|
}
|
|
208
210
|
}
|
|
209
211
|
else if (typeof link === 'object' && link.encoded) {
|
|
210
|
-
const rule = 'url-encoding', s =
|
|
212
|
+
const rule = 'url-encoding', s = lintConfig.getSeverity(rule, 'file');
|
|
211
213
|
if (s) {
|
|
212
214
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'unnecessary-encoding', s);
|
|
213
|
-
|
|
215
|
+
if (computeEditInfo || fix) {
|
|
216
|
+
e.fix = (0, lint_1.fixByDecode)(e, this);
|
|
217
|
+
}
|
|
214
218
|
errors.push(e);
|
|
215
219
|
}
|
|
216
220
|
}
|
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
633
|
rule: 'invalid-css',
|
|
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
|
}
|
package/dist/src/link/file.js
CHANGED
|
@@ -185,32 +185,37 @@ let FileToken = (() => {
|
|
|
185
185
|
/** @private */
|
|
186
186
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
187
187
|
LINT: { // eslint-disable-line no-unused-labels
|
|
188
|
-
const errors = super.lint(start, re), args = filterArgs(this.getAllArgs(), argTypes), keys = [...new Set(args.map(({ name }) => name))], frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key)), [fr] = frameKeys, unscaled = fr === 'framed' || fr === 'manualthumb', rect = new rect_1.BoundingRect(this, start), { extension } = this;
|
|
189
|
-
let rule = 'nested-link', s =
|
|
188
|
+
const errors = super.lint(start, re), args = filterArgs(this.getAllArgs(), argTypes), keys = [...new Set(args.map(({ name }) => name))], frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key)), [fr] = frameKeys, unscaled = fr === 'framed' || fr === 'manualthumb', rect = new rect_1.BoundingRect(this, start), { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, { extension } = this;
|
|
189
|
+
let rule = 'nested-link', s = lintConfig.getSeverity(rule, 'file');
|
|
190
190
|
if (s
|
|
191
191
|
&& extensions.has(extension)
|
|
192
192
|
&& this.closest('ext-link-text')
|
|
193
193
|
&& this.getValue('link')?.trim() !== '') {
|
|
194
|
-
const e = (0, lint_1.generateForSelf)(this, rect, rule, 'link-in-extlink', s)
|
|
195
|
-
if (
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
194
|
+
const e = (0, lint_1.generateForSelf)(this, rect, rule, 'link-in-extlink', s);
|
|
195
|
+
if (computeEditInfo || fix) {
|
|
196
|
+
const link = this.getArg('link');
|
|
197
|
+
if (link) {
|
|
198
|
+
const from = start + link.getRelativeIndex();
|
|
199
|
+
e.fix = {
|
|
200
|
+
desc: index_1.default.msg('delink'),
|
|
201
|
+
range: [from, from + link.toString().length],
|
|
202
|
+
text: 'link=',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
e.fix = (0, lint_1.fixByInsert)(e.endIndex - 2, 'delink', '|link=');
|
|
207
|
+
}
|
|
205
208
|
}
|
|
206
209
|
errors.push(e);
|
|
207
210
|
}
|
|
208
211
|
rule = 'invalid-gallery';
|
|
209
|
-
s =
|
|
212
|
+
s = lintConfig.getSeverity(rule, 'parameter');
|
|
210
213
|
if (s && unscaled) {
|
|
211
214
|
for (const arg of args.filter(({ name }) => name === 'width')) {
|
|
212
215
|
const e = (0, lint_1.generateForChild)(arg, rect, rule, 'invalid-image-parameter', s);
|
|
213
|
-
|
|
216
|
+
if (computeEditInfo || fix) {
|
|
217
|
+
e.fix = (0, lint_1.fixByRemove)(e, -1);
|
|
218
|
+
}
|
|
214
219
|
errors.push(e);
|
|
215
220
|
}
|
|
216
221
|
}
|
|
@@ -221,8 +226,7 @@ let FileToken = (() => {
|
|
|
221
226
|
return errors;
|
|
222
227
|
}
|
|
223
228
|
rule = 'no-duplicate';
|
|
224
|
-
const severities = ['unknownImageParameter', 'imageParameter']
|
|
225
|
-
.map(k => index_1.default.lintConfig.getSeverity(rule, k));
|
|
229
|
+
const severities = ['unknownImageParameter', 'imageParameter'].map(k => lintConfig.getSeverity(rule, k));
|
|
226
230
|
/**
|
|
227
231
|
* 图片参数到语法错误的映射
|
|
228
232
|
* @param tokens 图片参数节点
|
|
@@ -237,7 +241,9 @@ let FileToken = (() => {
|
|
|
237
241
|
}
|
|
238
242
|
/** `conflicting-image-parameter`或`duplicate-image-parameter` */
|
|
239
243
|
const e = (0, lint_1.generateForChild)(arg, rect, rule, index_1.default.msg(`${msg}-image-parameter`, p1), s);
|
|
240
|
-
|
|
244
|
+
if (computeEditInfo) {
|
|
245
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e, -1)];
|
|
246
|
+
}
|
|
241
247
|
return e;
|
|
242
248
|
}).filter((e) => e !== false);
|
|
243
249
|
for (const key of keys) {
|
|
@@ -121,10 +121,12 @@ let GalleryImageToken = (() => {
|
|
|
121
121
|
/** @private */
|
|
122
122
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
123
123
|
LINT: { // eslint-disable-line no-unused-labels
|
|
124
|
-
const errors = super.lint(start, re), rule = 'invalid-gallery',
|
|
124
|
+
const errors = super.lint(start, re), rule = 'invalid-gallery', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, 'image');
|
|
125
125
|
if (s && this.#lint()) {
|
|
126
126
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-gallery', s);
|
|
127
|
-
|
|
127
|
+
if (lintConfig.computeEditInfo) {
|
|
128
|
+
e.suggestions = [(0, lint_1.fixByInsert)(start, 'prefix', 'File:')];
|
|
129
|
+
}
|
|
128
130
|
errors.push(e);
|
|
129
131
|
}
|
|
130
132
|
return errors;
|
package/dist/src/link/index.js
CHANGED
|
@@ -47,10 +47,12 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
47
47
|
/** @private */
|
|
48
48
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
49
49
|
LINT: { // eslint-disable-line no-unused-labels
|
|
50
|
-
const errors = super.lint(start, re), rule = 'nested-link',
|
|
50
|
+
const errors = super.lint(start, re), rule = 'nested-link', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule);
|
|
51
51
|
if (s && this.closest('ext-link-text')) {
|
|
52
52
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'link-in-extlink', s);
|
|
53
|
-
|
|
53
|
+
if (lintConfig.computeEditInfo || lintConfig.fix) {
|
|
54
|
+
e.fix = (0, lint_1.fixBy)(e, 'delink', this.innerText);
|
|
55
|
+
}
|
|
54
56
|
errors.push(e);
|
|
55
57
|
}
|
|
56
58
|
return errors;
|
|
@@ -55,12 +55,14 @@ class RedirectTargetToken extends base_1.LinkBaseToken {
|
|
|
55
55
|
/** @private */
|
|
56
56
|
lint(start = this.getAbsoluteIndex()) {
|
|
57
57
|
LINT: { // eslint-disable-line no-unused-labels
|
|
58
|
-
const errors = super.lint(start, false), rule = 'no-ignored',
|
|
58
|
+
const errors = super.lint(start, false), rule = 'no-ignored', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, 'redirect');
|
|
59
59
|
if (s && this.length === 2) {
|
|
60
60
|
const e = (0, lint_1.generateForChild)(this.lastChild, { start }, rule, 'useless-link-text', s);
|
|
61
61
|
e.startIndex--;
|
|
62
62
|
e.startCol--;
|
|
63
|
-
|
|
63
|
+
if (lintConfig.computeEditInfo || lintConfig.fix) {
|
|
64
|
+
e.fix = (0, lint_1.fixByRemove)(e);
|
|
65
|
+
}
|
|
64
66
|
errors.push(e);
|
|
65
67
|
}
|
|
66
68
|
return errors;
|
package/dist/src/magicLink.js
CHANGED
|
@@ -180,25 +180,28 @@ let MagicLinkToken = (() => {
|
|
|
180
180
|
/** @private */
|
|
181
181
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
182
182
|
LINT: { // eslint-disable-line no-unused-labels
|
|
183
|
-
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), { type, childNodes } = this;
|
|
183
|
+
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), { lintConfig } = index_1.default, { type, childNodes } = this;
|
|
184
184
|
if (type === 'magic-link') {
|
|
185
|
-
const rule = 'invalid-isbn', s =
|
|
185
|
+
const rule = 'invalid-isbn', s = lintConfig.getSeverity(rule);
|
|
186
186
|
if (s && this.#lint()) {
|
|
187
187
|
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'invalid-isbn', s));
|
|
188
188
|
}
|
|
189
189
|
return errors;
|
|
190
190
|
}
|
|
191
|
-
const pipe = type === 'ext-link-url', rule = 'unterminated-url', severity =
|
|
191
|
+
const pipe = type === 'ext-link-url', rule = 'unterminated-url', severity = lintConfig.getSeverity(rule, pipe ? 'pipe' : 'punctuation');
|
|
192
192
|
if (severity) {
|
|
193
193
|
const regex = pipe ? /\|/u : /[,;。:!?()]+/u, child = childNodes.find((c) => c.type === 'text' && regex.test(c.data));
|
|
194
194
|
if (child) {
|
|
195
|
-
const { data } = child, e = (0, lint_1.generateForChild)(child, rect, rule, index_1.default.msg('in-url', pipe ? '"|"' : 'full-width-punctuation'), severity)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
(0, lint_1.fixBySpace)(i)
|
|
200
|
-
|
|
201
|
-
|
|
195
|
+
const { data } = child, e = (0, lint_1.generateForChild)(child, rect, rule, index_1.default.msg('in-url', pipe ? '"|"' : 'full-width-punctuation'), severity);
|
|
196
|
+
if (lintConfig.computeEditInfo) {
|
|
197
|
+
const { index, 0: s } = regex.exec(data), i = e.startIndex + index;
|
|
198
|
+
e.suggestions = pipe
|
|
199
|
+
? [(0, lint_1.fixBySpace)(i, 1)]
|
|
200
|
+
: [
|
|
201
|
+
(0, lint_1.fixBySpace)(i),
|
|
202
|
+
{ desc: index_1.default.msg('encode'), range: [i, i + s.length], text: encodeURI(s) },
|
|
203
|
+
];
|
|
204
|
+
}
|
|
202
205
|
errors.push(e);
|
|
203
206
|
}
|
|
204
207
|
}
|
package/dist/src/nested.js
CHANGED
|
@@ -111,7 +111,7 @@ let NestedToken = (() => {
|
|
|
111
111
|
/** @private */
|
|
112
112
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
113
113
|
LINT: { // eslint-disable-line no-unused-labels
|
|
114
|
-
const errors = super.lint(start, re), rule = 'no-ignored',
|
|
114
|
+
const errors = super.lint(start, re), rule = 'no-ignored', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, this.name);
|
|
115
115
|
if (!s) {
|
|
116
116
|
return errors;
|
|
117
117
|
}
|
|
@@ -130,10 +130,12 @@ let NestedToken = (() => {
|
|
|
130
130
|
return str && !regex.test(str);
|
|
131
131
|
}).map(child => {
|
|
132
132
|
const e = (0, lint_1.generateForChild)(child, rect, rule, index_1.default.msg('invalid-content', this.name), s);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
if (lintConfig.computeEditInfo) {
|
|
134
|
+
e.suggestions = [
|
|
135
|
+
(0, lint_1.fixByRemove)(e),
|
|
136
|
+
(0, lint_1.fixByComment)(e, child.toString()),
|
|
137
|
+
];
|
|
138
|
+
}
|
|
137
139
|
return e;
|
|
138
140
|
}),
|
|
139
141
|
];
|
|
@@ -91,12 +91,14 @@ let CommentToken = (() => {
|
|
|
91
91
|
if (this.closed) {
|
|
92
92
|
return [];
|
|
93
93
|
}
|
|
94
|
-
const rule = 'unclosed-comment',
|
|
94
|
+
const rule = 'unclosed-comment', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule);
|
|
95
95
|
if (!s) {
|
|
96
96
|
return [];
|
|
97
97
|
}
|
|
98
98
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('unclosed', 'html-comment'), s);
|
|
99
|
-
|
|
99
|
+
if (lintConfig.computeEditInfo) {
|
|
100
|
+
e.suggestions = [(0, lint_1.fixByClose)(e.endIndex, '-->')];
|
|
101
|
+
}
|
|
100
102
|
return [e];
|
|
101
103
|
}
|
|
102
104
|
}
|
package/dist/src/nowiki/index.js
CHANGED
|
@@ -32,10 +32,12 @@ class NowikiToken extends base_1.NowikiBaseToken {
|
|
|
32
32
|
/** @private */
|
|
33
33
|
lint(start = this.getAbsoluteIndex()) {
|
|
34
34
|
LINT: { // eslint-disable-line no-unused-labels
|
|
35
|
-
const { name } = this, rule = 'void-ext',
|
|
35
|
+
const { name } = this, rule = 'void-ext', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, name);
|
|
36
36
|
if (s && this.#lint()) {
|
|
37
37
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('nothing-in', name), s);
|
|
38
|
-
|
|
38
|
+
if (lintConfig.computeEditInfo) {
|
|
39
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
40
|
+
}
|
|
39
41
|
return [e];
|
|
40
42
|
}
|
|
41
43
|
return super.lint(start, getLintRegex(name));
|
package/dist/src/nowiki/quote.js
CHANGED
|
@@ -114,7 +114,7 @@ let QuoteToken = (() => {
|
|
|
114
114
|
/** @private */
|
|
115
115
|
lint(start = this.getAbsoluteIndex()) {
|
|
116
116
|
LINT: { // eslint-disable-line no-unused-labels
|
|
117
|
-
const { previousSibling, bold, closing } = this, previousData = previousSibling?.type === 'text' ? previousSibling.data : undefined, errors = [], rect = new rect_1.BoundingRect(this, start), rules = ['lonely-apos', 'bold-header'], severities = [undefined, 'word'].map(key =>
|
|
117
|
+
const { previousSibling, bold, closing } = this, previousData = previousSibling?.type === 'text' ? previousSibling.data : undefined, errors = [], rect = new rect_1.BoundingRect(this, start), rules = ['lonely-apos', 'bold-header'], { lintConfig } = index_1.default, { computeEditInfo } = lintConfig, severities = [undefined, 'word'].map(key => lintConfig.getSeverity(rules[0], key)), s = lintConfig.getSeverity(rules[1]);
|
|
118
118
|
if (previousData?.endsWith(`'`)) {
|
|
119
119
|
const severity = severities[(closing.bold || closing.italic) && /[a-z\d]'$/iu.test(previousData) ? 1 : 0];
|
|
120
120
|
if (severity) {
|
|
@@ -126,16 +126,20 @@ let QuoteToken = (() => {
|
|
|
126
126
|
startCol: endCol - length,
|
|
127
127
|
endCol,
|
|
128
128
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
if (computeEditInfo) {
|
|
130
|
+
eNew.suggestions = [
|
|
131
|
+
(0, lint_1.fixByEscape)(startIndex, ''', length),
|
|
132
|
+
(0, lint_1.fixByRemove)(eNew),
|
|
133
|
+
];
|
|
134
|
+
}
|
|
133
135
|
errors.push(eNew);
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
if (s && bold && this.closest('heading-title,ext')?.type === 'heading-title') {
|
|
137
139
|
const e = (0, lint_1.generateForSelf)(this, rect, rules[1], 'bold-in-header', s);
|
|
138
|
-
|
|
140
|
+
if (computeEditInfo) {
|
|
141
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
142
|
+
}
|
|
139
143
|
errors.push(e);
|
|
140
144
|
}
|
|
141
145
|
return errors;
|
|
@@ -97,7 +97,7 @@ let ParamTagToken = (() => {
|
|
|
97
97
|
/** @private */
|
|
98
98
|
lint(start = this.getAbsoluteIndex()) {
|
|
99
99
|
LINT: { // eslint-disable-line no-unused-labels
|
|
100
|
-
const rule = 'no-ignored',
|
|
100
|
+
const rule = 'no-ignored', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, this.name);
|
|
101
101
|
if (!s) {
|
|
102
102
|
return [];
|
|
103
103
|
}
|
|
@@ -113,7 +113,9 @@ let ParamTagToken = (() => {
|
|
|
113
113
|
const i = grandChildren.findIndex(({ type }) => type !== 'text'), str = grandChildren.slice(0, i === -1 ? undefined : i).map(String).join('');
|
|
114
114
|
if (str && !(i === -1 ? /^[a-z]+(?:\[\])?\s*=/iu : /^[a-z]+(?:\[\])?\s*(?:=|$)/iu).test(str)) {
|
|
115
115
|
const e = (0, lint_1.generateForChild)(child, rect, rule, msg, s);
|
|
116
|
-
|
|
116
|
+
if (lintConfig.computeEditInfo) {
|
|
117
|
+
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
118
|
+
}
|
|
117
119
|
errors.push(e);
|
|
118
120
|
}
|
|
119
121
|
else {
|
package/dist/src/parameter.js
CHANGED
|
@@ -178,7 +178,7 @@ let ParameterToken = (() => {
|
|
|
178
178
|
/** @private */
|
|
179
179
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
180
180
|
LINT: { // eslint-disable-line no-unused-labels
|
|
181
|
-
const errors = super.lint(start, re), rule = 'unescaped',
|
|
181
|
+
const errors = super.lint(start, re), rule = 'unescaped', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule);
|
|
182
182
|
if (s) {
|
|
183
183
|
const { firstChild } = this, link = linkRegex.exec(firstChild.text())?.[0];
|
|
184
184
|
try {
|
|
@@ -189,7 +189,9 @@ let ParameterToken = (() => {
|
|
|
189
189
|
e.startCol = e.endCol;
|
|
190
190
|
e.endIndex++;
|
|
191
191
|
e.endCol++;
|
|
192
|
-
|
|
192
|
+
if (lintConfig.computeEditInfo || lintConfig.fix) {
|
|
193
|
+
e.fix = (0, lint_1.fixByEscape)(e.startIndex, '{{=}}');
|
|
194
|
+
}
|
|
193
195
|
errors.push(e);
|
|
194
196
|
}
|
|
195
197
|
}
|
package/dist/src/table/td.js
CHANGED
|
@@ -219,7 +219,7 @@ let TdToken = (() => {
|
|
|
219
219
|
/** @private */
|
|
220
220
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
221
221
|
LINT: { // eslint-disable-line no-unused-labels
|
|
222
|
-
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start + this.getRelativeIndex(this.length - 1)), rule = 'pipe-like', severities = ['td', 'double'].map(key =>
|
|
222
|
+
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start + this.getRelativeIndex(this.length - 1)), rule = 'pipe-like', { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, severities = ['td', 'double'].map(key => lintConfig.getSeverity(rule, key));
|
|
223
223
|
for (const child of this.lastChild.childNodes) {
|
|
224
224
|
if (child.type === 'text') {
|
|
225
225
|
const { data } = child;
|
|
@@ -227,12 +227,14 @@ let TdToken = (() => {
|
|
|
227
227
|
const double = data.includes('||'), s = severities[double ? 1 : 0];
|
|
228
228
|
if (s) {
|
|
229
229
|
const e = (0, lint_1.generateForChild)(child, rect, rule, 'pipe-in-table', s);
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
if (computeEditInfo || fix) {
|
|
231
|
+
if (double) {
|
|
232
|
+
const syntax = { caption: '|+', td: '|', th: '!' }[this.subtype];
|
|
233
|
+
e.fix = (0, lint_1.fixBy)(e, 'newline', data.replace(/\|\|/gu, `\n${syntax}`));
|
|
234
|
+
}
|
|
235
|
+
else if (computeEditInfo) {
|
|
236
|
+
e.suggestions = [(0, lint_1.fixByPipe)(e.startIndex, data)];
|
|
237
|
+
}
|
|
236
238
|
}
|
|
237
239
|
errors.push(e);
|
|
238
240
|
}
|
package/dist/src/tagPair/ext.js
CHANGED
|
@@ -199,14 +199,14 @@ let ExtToken = (() => {
|
|
|
199
199
|
/** @private */
|
|
200
200
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
201
201
|
LINT: { // eslint-disable-line no-unused-labels
|
|
202
|
-
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
|
|
202
|
+
const errors = super.lint(start, re), { lintConfig } = index_1.default, rect = new rect_1.BoundingRect(this, start);
|
|
203
203
|
if (this.name !== 'nowiki') {
|
|
204
|
-
const s = this.inHtmlAttrs(), rule = 'parsing-order', severity = s &&
|
|
204
|
+
const s = this.inHtmlAttrs(), rule = 'parsing-order', severity = s && lintConfig.getSeverity(rule, s === 2 ? 'ext' : 'templateInTable');
|
|
205
205
|
if (severity) {
|
|
206
206
|
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'ext-in-html', severity));
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
const rule = 'var-anchor', s =
|
|
209
|
+
const rule = 'var-anchor', s = lintConfig.getSeverity(rule, 'ref');
|
|
210
210
|
if (s && this.name === 'ref' && this.closest('heading-title')) {
|
|
211
211
|
errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'variable-anchor', s));
|
|
212
212
|
}
|