wikiparser-node 1.33.0 → 1.34.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 -0
- package/bundle/bundle-es8.min.js +27 -27
- package/bundle/bundle-lsp.min.js +30 -30
- package/bundle/bundle.min.js +16 -16
- package/dist/base.d.mts +1 -1
- package/dist/base.d.ts +1 -1
- package/dist/base.js +1 -0
- package/dist/base.mjs +1 -0
- package/dist/bin/config.js +1 -1
- package/dist/index.js +8 -7
- package/dist/internal.d.ts +3 -0
- package/dist/lib/lintConfig.js +6 -0
- package/dist/lib/lsp.js +13 -3
- package/dist/lib/node.js +3 -11
- package/dist/lib/text.js +14 -14
- package/dist/lib/title.js +8 -10
- package/dist/src/attribute.d.ts +0 -1
- package/dist/src/attribute.js +4 -5
- package/dist/src/attributes.d.ts +0 -1
- package/dist/src/attributes.js +3 -4
- package/dist/src/converterFlags.js +5 -7
- package/dist/src/link/base.js +2 -1
- package/dist/src/link/categorytree.d.ts +1 -3
- package/dist/src/link/categorytree.js +11 -0
- package/dist/src/multiLine/imagemap.js +1 -1
- package/dist/src/nowiki/index.d.ts +1 -1
- package/dist/src/nowiki/index.js +59 -13
- package/dist/src/nowiki/list.d.ts +0 -1
- package/dist/src/nowiki/list.js +1 -0
- package/dist/src/nowiki/noinclude.d.ts +0 -1
- package/dist/src/nowiki/noinclude.js +1 -0
- package/dist/src/nowiki/quote.d.ts +0 -4
- package/dist/src/nowiki/quote.js +4 -0
- package/dist/src/parameter.js +5 -7
- package/dist/src/table/base.d.ts +0 -1
- package/dist/src/table/base.js +7 -8
- package/dist/src/table/index.d.ts +0 -1
- package/dist/src/table/index.js +1 -0
- package/dist/src/table/td.d.ts +0 -1
- package/dist/src/table/td.js +1 -0
- package/dist/src/tag/html.d.ts +0 -1
- package/dist/src/tag/html.js +1 -0
- package/dist/src/tag/tvar.d.ts +0 -1
- package/dist/src/tag/tvar.js +1 -0
- package/dist/src/tagPair/index.d.ts +4 -2
- package/dist/src/tagPair/index.js +47 -7
- package/dist/src/tagPair/translate.d.ts +1 -1
- package/dist/src/tagPair/translate.js +3 -1
- package/dist/src/transclude.js +2 -2
- package/dist/util/diff.js +6 -17
- package/extensions/dist/base.js +1 -1
- package/logo.png +0 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const string_1 = require("./util/string");
|
|
|
10
10
|
const lintConfig_1 = require("./lib/lintConfig");
|
|
11
11
|
const title_1 = require("./lib/title");
|
|
12
12
|
/* NOT FOR BROWSER */
|
|
13
|
+
const util_1 = __importDefault(require("util"));
|
|
13
14
|
const redirectMap_1 = require("./lib/redirectMap");
|
|
14
15
|
/* NOT FOR BROWSER END */
|
|
15
16
|
/* NOT FOR BROWSER ONLY */
|
|
@@ -216,11 +217,9 @@ const Parser = {
|
|
|
216
217
|
maxStage ??= constants_1.MAX_STAGE;
|
|
217
218
|
config ??= this.getConfig();
|
|
218
219
|
let types;
|
|
219
|
-
LINT: {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
maxStage = Math.max(...types.map(t => base_1.stages[t] || constants_1.MAX_STAGE));
|
|
223
|
-
}
|
|
220
|
+
LINT: if (typeof maxStage !== 'number') {
|
|
221
|
+
types = Array.isArray(maxStage) ? maxStage : [maxStage];
|
|
222
|
+
maxStage = Math.max(...types.map(t => base_1.stages[t] || constants_1.MAX_STAGE));
|
|
224
223
|
}
|
|
225
224
|
const { Token } = require('./src/index');
|
|
226
225
|
const root = debug_1.Shadow.run(() => {
|
|
@@ -376,14 +375,16 @@ const Parser = {
|
|
|
376
375
|
warn(msg, ...args) {
|
|
377
376
|
/* istanbul ignore if */
|
|
378
377
|
if (this.warning) {
|
|
379
|
-
|
|
378
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
379
|
+
console.warn(util_1.default.styleText?.('yellow', msg) ?? msg, ...args);
|
|
380
380
|
}
|
|
381
381
|
},
|
|
382
382
|
/** @implements */
|
|
383
383
|
debug(msg, ...args) {
|
|
384
384
|
/* istanbul ignore if */
|
|
385
385
|
if (this.debugging) {
|
|
386
|
-
|
|
386
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
387
|
+
console.debug(util_1.default.styleText?.('blue', msg) ?? msg, ...args);
|
|
387
388
|
}
|
|
388
389
|
},
|
|
389
390
|
error: diff_1.error,
|
package/dist/internal.d.ts
CHANGED
|
@@ -45,6 +45,9 @@ export type { GalleryToken } from './src/multiLine/gallery';
|
|
|
45
45
|
export type { ImagemapLinkToken } from './src/imagemapLink';
|
|
46
46
|
export type { ImagemapToken } from './src/multiLine/imagemap';
|
|
47
47
|
export type { CommentedToken } from './src/commented';
|
|
48
|
+
export type { CategorytreeToken } from './src/link/categorytree';
|
|
49
|
+
export type { ParamLineToken } from './src/paramLine';
|
|
50
|
+
export type { CommentLineToken } from './src/nowiki/commentLine';
|
|
48
51
|
export type { TranslateToken } from './src/tagPair/translate';
|
|
49
52
|
export type { TvarToken } from './src/tag/tvar';
|
|
50
53
|
export type { ListRangeToken } from './src/nowiki/listBase';
|
package/dist/lib/lintConfig.js
CHANGED
package/dist/lib/lsp.js
CHANGED
|
@@ -829,8 +829,21 @@ class LanguageService {
|
|
|
829
829
|
async provideDiagnostics(text, warning = true) {
|
|
830
830
|
const root = await this.#queue(text), { lintConfig } = index_1.default, needFix = lintConfig.fix;
|
|
831
831
|
lintConfig.fix = false;
|
|
832
|
+
/* NOT FOR BROWSER ONLY */
|
|
833
|
+
const stylelint = await (0, document_1.loadStylelint)(), jsonLSP = (0, document_1.loadJsonLSP)();
|
|
834
|
+
let s;
|
|
835
|
+
NPM: if (jsonLSP) {
|
|
836
|
+
s = lintConfig.rules['invalid-json'];
|
|
837
|
+
lintConfig.rules['invalid-json'] = 0;
|
|
838
|
+
}
|
|
839
|
+
/* NOT FOR BROWSER ONLY END */
|
|
832
840
|
const errors = root.lint();
|
|
833
841
|
lintConfig.fix = needFix;
|
|
842
|
+
/* NOT FOR BROWSER ONLY */
|
|
843
|
+
NPM: if (jsonLSP) {
|
|
844
|
+
lintConfig.rules['invalid-json'] = s;
|
|
845
|
+
}
|
|
846
|
+
/* NOT FOR BROWSER ONLY END */
|
|
834
847
|
const diagnostics = (warning ? errors : errors.filter(({ severity }) => severity === 'error')).map(({ startLine, startCol, endLine, endCol, severity, rule, message, fix, suggestions,
|
|
835
848
|
/* NOT FOR BROWSER ONLY */
|
|
836
849
|
code, }) => ({
|
|
@@ -852,9 +865,6 @@ class LanguageService {
|
|
|
852
865
|
...suggestions ? suggestions.map(suggestion => getQuickFix(root, suggestion)) : [],
|
|
853
866
|
],
|
|
854
867
|
})),
|
|
855
|
-
/* NOT FOR BROWSER ONLY */
|
|
856
|
-
stylelint = await (0, document_1.loadStylelint)(), jsonLSP = (0, document_1.loadJsonLSP)(),
|
|
857
|
-
/* NOT FOR BROWSER ONLY END */
|
|
858
868
|
/* eslint-disable @stylistic/operator-linebreak */
|
|
859
869
|
cssDiagnostics = stylelint ?
|
|
860
870
|
await (async () => {
|
package/dist/lib/node.js
CHANGED
|
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.AstNode = void 0;
|
|
41
41
|
/* eslint-disable @typescript-eslint/no-base-to-string */
|
|
42
|
+
const common_1 = require("@bhsd/common");
|
|
42
43
|
const search_1 = __importDefault(require("../util/search"));
|
|
43
44
|
const lint_1 = require("../util/lint");
|
|
44
45
|
const debug_1 = require("../util/debug");
|
|
@@ -269,7 +270,7 @@ let AstNode = (() => {
|
|
|
269
270
|
* @param left column number / 列号
|
|
270
271
|
*/
|
|
271
272
|
indexFromPos(top, left) {
|
|
272
|
-
|
|
273
|
+
LINT: {
|
|
273
274
|
if (top < 0 || left < 0) {
|
|
274
275
|
return undefined;
|
|
275
276
|
}
|
|
@@ -381,16 +382,7 @@ let AstNode = (() => {
|
|
|
381
382
|
* @since v1.16.3
|
|
382
383
|
*/
|
|
383
384
|
getLines() {
|
|
384
|
-
LINT:
|
|
385
|
-
const results = [];
|
|
386
|
-
let start = 0;
|
|
387
|
-
for (const line of String(this).split('\n')) {
|
|
388
|
-
const end = start + line.length;
|
|
389
|
-
results.push([line, start, end]);
|
|
390
|
-
start = end + 1;
|
|
391
|
-
}
|
|
392
|
-
return results;
|
|
393
|
-
}
|
|
385
|
+
LINT: return (0, common_1.splitLines)(String(this));
|
|
394
386
|
}
|
|
395
387
|
/* PRINT ONLY */
|
|
396
388
|
/** @private */
|
package/dist/lib/text.js
CHANGED
|
@@ -230,9 +230,15 @@ let AstText = (() => {
|
|
|
230
230
|
...lintConfig.getSeverity('tag-like', 'disallowed') ? disallowedTags : [],
|
|
231
231
|
]);
|
|
232
232
|
for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
|
|
233
|
-
const [, tag, prefix] = mt;
|
|
234
233
|
let { index, 0: error } = mt;
|
|
235
|
-
|
|
234
|
+
const [, tag, prefix] = mt, lbrackInExtLinkText = error === '[' && type === 'ext-link-text';
|
|
235
|
+
if (error.startsWith('<') && !tags.has(tag.toLowerCase())
|
|
236
|
+
|| lbrackInExtLinkText && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
237
|
+
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
238
|
+
&& nextSibling.innerText?.includes(']'))) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
else if (prefix && prefix !== ']') {
|
|
236
242
|
const { length } = prefix;
|
|
237
243
|
index += length;
|
|
238
244
|
error = error.slice(length);
|
|
@@ -242,20 +248,14 @@ let AstText = (() => {
|
|
|
242
248
|
error = error.slice(1);
|
|
243
249
|
}
|
|
244
250
|
error = error.toLowerCase();
|
|
245
|
-
const [char] = error, magicLink =
|
|
251
|
+
const [char] = error, magicLink = error === 'rfc' || error === 'pmid' || error === 'isbn', lbrace = char === '{', rbrace = char === '}', lbrack = char === '[', rbrack = char === ']';
|
|
246
252
|
let { length } = error;
|
|
247
|
-
if (
|
|
248
|
-
|| lbrack && type === 'ext-link-text' && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
249
|
-
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
250
|
-
&& nextSibling.innerText?.includes(']'))) {
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
else if (rbrack && (index || length > 1)) {
|
|
253
|
+
if (rbrack && (index || length > 1)) {
|
|
254
254
|
errorRegex.lastIndex--;
|
|
255
255
|
}
|
|
256
256
|
// Rule & Severity
|
|
257
257
|
let startIndex = start + index, endIndex = startIndex + length, rule, severity, endLine, endCol;
|
|
258
|
-
const nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], leftBracket = lbrace || lbrack, lConverter =
|
|
258
|
+
const nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], leftBracket = lbrace || lbrack, lConverter = error === '{' && previousChar === '-' && variants.length > 0, rConverter = error === '}' && nextChar === '-' && variants.length > 0, brokenExtLink = lbrack && nextType === 'free-ext-link' && !data.slice(index + 1).trim()
|
|
259
259
|
|| rbrack && previousType === 'free-ext-link'
|
|
260
260
|
&& !data.slice(0, index).includes(']');
|
|
261
261
|
if (magicLink) {
|
|
@@ -306,7 +306,7 @@ let AstText = (() => {
|
|
|
306
306
|
severity = lintConfig.getSeverity(rule, 'double');
|
|
307
307
|
}
|
|
308
308
|
else {
|
|
309
|
-
if (!
|
|
309
|
+
if (!lbrackInExtLinkText) {
|
|
310
310
|
const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
|
|
311
311
|
if (lbrace && regex.exec(remains)?.[0] === '}'
|
|
312
312
|
|| rbrace && regex.exec(remains)?.[0] === '{') {
|
|
@@ -388,11 +388,11 @@ let AstText = (() => {
|
|
|
388
388
|
else if (char === 'h' && type !== 'link-text' && wordRegex.test(previousChar || '')) {
|
|
389
389
|
e.suggestions = [(0, lint_1.fixBySpace)(startIndex)];
|
|
390
390
|
}
|
|
391
|
-
else if (
|
|
391
|
+
else if (lbrackInExtLinkText) {
|
|
392
392
|
const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
|
|
393
393
|
e.suggestions = [(0, lint_1.fixByEscape)(i, ']')];
|
|
394
394
|
}
|
|
395
|
-
else if (
|
|
395
|
+
else if (error === ']' && brokenExtLink) {
|
|
396
396
|
const i = start - previousSibling.toString().length;
|
|
397
397
|
e.suggestions = [(0, lint_1.fixByInsert)(i, 'left-bracket', '[')];
|
|
398
398
|
}
|
package/dist/lib/title.js
CHANGED
|
@@ -187,16 +187,14 @@ class Title {
|
|
|
187
187
|
this.#path += `${this.#path.endsWith('/') ? '' : '/'}$1`;
|
|
188
188
|
}
|
|
189
189
|
/* PRINT ONLY */
|
|
190
|
-
LSP: {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
199
|
-
}
|
|
190
|
+
LSP: if (!temporary) {
|
|
191
|
+
Object.defineProperties(this, {
|
|
192
|
+
encoded: { enumerable: false, writable: false },
|
|
193
|
+
/* NOT FOR BROWSER */
|
|
194
|
+
valid: { writable: false },
|
|
195
|
+
conversionTable: { enumerable: false },
|
|
196
|
+
redirects: { enumerable: false },
|
|
197
|
+
});
|
|
200
198
|
}
|
|
201
199
|
}
|
|
202
200
|
/**
|
package/dist/src/attribute.d.ts
CHANGED
package/dist/src/attribute.js
CHANGED
|
@@ -364,12 +364,11 @@ let AttributeToken = (() => {
|
|
|
364
364
|
getValue() {
|
|
365
365
|
return this.#equal ? this.lastChild.text().trim() : this.type === 'ext-attr' || '';
|
|
366
366
|
}
|
|
367
|
+
/** @private */
|
|
367
368
|
escape() {
|
|
368
|
-
LSP: {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
this.lastChild.escape();
|
|
372
|
-
}
|
|
369
|
+
LSP: if (this.type !== 'ext-attr') {
|
|
370
|
+
this.#equal = '{{=}}';
|
|
371
|
+
this.lastChild.escape();
|
|
373
372
|
}
|
|
374
373
|
}
|
|
375
374
|
/* PRINT ONLY */
|
package/dist/src/attributes.d.ts
CHANGED
package/dist/src/attributes.js
CHANGED
|
@@ -314,11 +314,10 @@ let AttributesToken = (() => {
|
|
|
314
314
|
return errors;
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
+
/** @private */
|
|
317
318
|
escape() {
|
|
318
|
-
LSP: {
|
|
319
|
-
|
|
320
|
-
super.escape();
|
|
321
|
-
}
|
|
319
|
+
LSP: if (this.type !== 'ext-attrs') {
|
|
320
|
+
super.escape();
|
|
322
321
|
}
|
|
323
322
|
}
|
|
324
323
|
/* PRINT ONLY */
|
|
@@ -140,13 +140,11 @@ let ConverterFlagsToken = (() => {
|
|
|
140
140
|
/** @private */
|
|
141
141
|
isInvalidFlag(flag, variant, unknown, valid) {
|
|
142
142
|
/* PRINT ONLY */
|
|
143
|
-
PRINT: {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
valid = new Set(this.#flags.filter(f => definedFlags.has(f)));
|
|
149
|
-
}
|
|
143
|
+
PRINT: if (typeof flag === 'object') {
|
|
144
|
+
flag = flag.text().trim();
|
|
145
|
+
variant = this.getVariantFlags();
|
|
146
|
+
unknown = this.getUnknownFlags();
|
|
147
|
+
valid = new Set(this.#flags.filter(f => definedFlags.has(f)));
|
|
150
148
|
}
|
|
151
149
|
/* PRINT ONLY END */
|
|
152
150
|
return Boolean(flag) && !variant.has(flag) && !unknown.has(flag) && (variant.size > 0 || !valid.has(flag));
|
package/dist/src/link/base.js
CHANGED
|
@@ -154,7 +154,8 @@ let LinkBaseToken = (() => {
|
|
|
154
154
|
/* NOT FOR BROWSER */
|
|
155
155
|
const /** @implements */ linkListener = (e, data) => {
|
|
156
156
|
const { prevTarget } = e, { type } = this;
|
|
157
|
-
if (prevTarget?.is('link-target')
|
|
157
|
+
if (prevTarget?.is('link-target')
|
|
158
|
+
&& !(this.is('ext-inner') && this.parentNode?.selfClosing)) {
|
|
158
159
|
const name = prevTarget.text(), titleObj = this.getTitle(), { interwiki, ns, valid } = titleObj;
|
|
159
160
|
if (!valid) {
|
|
160
161
|
(0, debug_1.undo)(e, data);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LinkBaseToken } from './base';
|
|
2
2
|
import type { Config, LintError } from '../../base';
|
|
3
3
|
import type { Title } from '../../lib/title';
|
|
4
|
-
import type { Token, AtomToken, AttributesToken, ExtToken } from '../../internal';
|
|
4
|
+
import type { Token, AtomToken, AttributesToken, ExtToken, AstNodes } from '../../internal';
|
|
5
5
|
/**
|
|
6
6
|
* `<categorytree>`
|
|
7
7
|
* @classdesc `{childNodes: [AtomToken]}`
|
|
@@ -22,6 +22,4 @@ export declare abstract class CategorytreeToken extends LinkBaseToken {
|
|
|
22
22
|
get type(): 'ext-inner';
|
|
23
23
|
/** @param link 链接标题 */
|
|
24
24
|
constructor(link: string, linkText?: undefined, config?: Config, accum?: Token[]);
|
|
25
|
-
getTitle(): Title;
|
|
26
|
-
lint(start?: number): LintError[];
|
|
27
25
|
}
|
|
@@ -83,6 +83,7 @@ let CategorytreeToken = (() => {
|
|
|
83
83
|
// @ts-expect-error abstract getter override
|
|
84
84
|
this.firstChild.setAttribute('acceptable', { AstText: 0 });
|
|
85
85
|
}
|
|
86
|
+
/** @private */
|
|
86
87
|
getTitle() {
|
|
87
88
|
const target = this.firstChild.toString().trim(), opt = { halfParsed: true }, title = this.normalizeTitle(target, 14, opt);
|
|
88
89
|
return title.valid && title.ns === 14
|
|
@@ -90,6 +91,7 @@ let CategorytreeToken = (() => {
|
|
|
90
91
|
? title
|
|
91
92
|
: this.normalizeTitle(`Category:${target}`, 0, opt);
|
|
92
93
|
}
|
|
94
|
+
/** @private */
|
|
93
95
|
lint(start = this.getAbsoluteIndex()) {
|
|
94
96
|
LINT: {
|
|
95
97
|
const rule = 'no-ignored', s = index_1.default.lintConfig.getSeverity(rule, 'categorytree');
|
|
@@ -108,6 +110,15 @@ let CategorytreeToken = (() => {
|
|
|
108
110
|
toHtmlInternal() {
|
|
109
111
|
return '';
|
|
110
112
|
}
|
|
113
|
+
/** @private */
|
|
114
|
+
safeReplaceChildren(elements) {
|
|
115
|
+
if (elements.length === 0) {
|
|
116
|
+
this.firstChild.replaceChildren();
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
super.safeReplaceChildren(elements);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
111
122
|
};
|
|
112
123
|
return CategorytreeToken = _classThis;
|
|
113
124
|
})();
|
|
@@ -129,7 +129,7 @@ class ImagemapToken extends index_2.MultiLineToken {
|
|
|
129
129
|
}
|
|
130
130
|
/** @private */
|
|
131
131
|
removeAt(i) {
|
|
132
|
-
if (this.childNodes[i]?.is('imagemap-image')) {
|
|
132
|
+
if (!this.parentNode?.selfClosing && this.childNodes[i]?.is('imagemap-image')) {
|
|
133
133
|
throw new Error('Do not remove the image in <imagemap>!');
|
|
134
134
|
}
|
|
135
135
|
return super.removeAt(i);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NowikiBaseToken } from './base';
|
|
2
2
|
import type { LintError } from '../../base';
|
|
3
|
-
import type { AttributesToken, ExtToken } from '../../internal';
|
|
3
|
+
import type { AttributesToken, ExtToken, AstNodes } from '../../internal';
|
|
4
4
|
/**
|
|
5
5
|
* text-only token inside an extension tag
|
|
6
6
|
*
|
package/dist/src/nowiki/index.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.NowikiToken = void 0;
|
|
7
7
|
const common_1 = require("@bhsd/common");
|
|
8
8
|
const lint_1 = require("../../util/lint");
|
|
9
|
+
const rect_1 = require("../../lib/rect");
|
|
9
10
|
const index_1 = __importDefault(require("../../index"));
|
|
10
11
|
const base_1 = require("./base");
|
|
11
12
|
/* NOT FOR BROWSER ONLY */
|
|
@@ -44,9 +45,9 @@ class NowikiToken extends base_1.NowikiBaseToken {
|
|
|
44
45
|
/** @private */
|
|
45
46
|
lint(start = this.getAbsoluteIndex()) {
|
|
46
47
|
LINT: {
|
|
47
|
-
const { name,
|
|
48
|
+
const { name, innerText,
|
|
48
49
|
/* NOT FOR BROWSER ONLY */
|
|
49
|
-
|
|
50
|
+
previousSibling, } = this, { lintConfig } = index_1.default;
|
|
50
51
|
let rule = 'void-ext', s = lintConfig.getSeverity(rule, name);
|
|
51
52
|
if (s && this.#lint()) {
|
|
52
53
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('nothing-in', name), s);
|
|
@@ -55,9 +56,42 @@ class NowikiToken extends base_1.NowikiBaseToken {
|
|
|
55
56
|
}
|
|
56
57
|
return [e];
|
|
57
58
|
}
|
|
58
|
-
const errors = super.lint(start, getLintRegex(name));
|
|
59
|
-
/* NOT FOR BROWSER ONLY */
|
|
60
59
|
NPM: {
|
|
60
|
+
rule = 'invalid-json';
|
|
61
|
+
const sSyntax = lintConfig.getSeverity(rule);
|
|
62
|
+
/* NOT FOR BROWSER ONLY */
|
|
63
|
+
const sDuplicate = lintConfig.getSeverity(rule, 'duplicate');
|
|
64
|
+
/* NOT FOR BROWSER ONLY END */
|
|
65
|
+
if (name === 'templatedata' && (sSyntax
|
|
66
|
+
|| sDuplicate)) {
|
|
67
|
+
// browser版本使用`lintJSONNative()`
|
|
68
|
+
return (0, common_1.lintJSON)(innerText).map(({ message, position, line, column,
|
|
69
|
+
/* NOT FOR BROWSER ONLY */
|
|
70
|
+
severity, }) => {
|
|
71
|
+
s =
|
|
72
|
+
/* eslint-disable @stylistic/operator-linebreak */
|
|
73
|
+
severity === 'warning' ?
|
|
74
|
+
sDuplicate :
|
|
75
|
+
/* eslint-enable @stylistic/operator-linebreak */
|
|
76
|
+
sSyntax;
|
|
77
|
+
if (!s) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const rect = new rect_1.BoundingRect(this, start), startIndex = start + position, startLine = rect.top + line - 1, startCol = (line > 1 ? 0 : rect.left) + column - 1;
|
|
81
|
+
return {
|
|
82
|
+
rule,
|
|
83
|
+
message,
|
|
84
|
+
severity: s,
|
|
85
|
+
startIndex,
|
|
86
|
+
endIndex: startIndex,
|
|
87
|
+
startLine,
|
|
88
|
+
endLine: startLine,
|
|
89
|
+
startCol,
|
|
90
|
+
endCol: startCol,
|
|
91
|
+
};
|
|
92
|
+
}).filter((e) => e !== false);
|
|
93
|
+
}
|
|
94
|
+
/* NOT FOR BROWSER ONLY */
|
|
61
95
|
rule = 'invalid-math';
|
|
62
96
|
s = lintConfig.getSeverity(rule);
|
|
63
97
|
if (s && constants_1.mathTags.has(name)) {
|
|
@@ -86,20 +120,21 @@ class NowikiToken extends base_1.NowikiBaseToken {
|
|
|
86
120
|
const result = texvcjs.check(tex, {
|
|
87
121
|
usemhchem: isChem || Boolean(previousSibling?.hasAttr('chem')),
|
|
88
122
|
});
|
|
89
|
-
if (result.status
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
123
|
+
if (result.status === '+') {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'chem-required', s);
|
|
127
|
+
if (result.status !== 'C') {
|
|
128
|
+
const { message, location } = result.error, [endIndex, endLine, endCol] = updateLocation(e, location.end, n);
|
|
129
|
+
[e.startIndex, e.startLine, e.startCol] = updateLocation(e, location.start, n);
|
|
130
|
+
Object.assign(e, { endIndex, endLine, endCol, message });
|
|
97
131
|
}
|
|
132
|
+
return [e];
|
|
98
133
|
}
|
|
99
134
|
}
|
|
100
135
|
}
|
|
101
136
|
/* NOT FOR BROWSER ONLY END */
|
|
102
|
-
return
|
|
137
|
+
return super.lint(start, getLintRegex(name));
|
|
103
138
|
}
|
|
104
139
|
}
|
|
105
140
|
/* PRINT ONLY */
|
|
@@ -107,6 +142,17 @@ class NowikiToken extends base_1.NowikiBaseToken {
|
|
|
107
142
|
getAttribute(key) {
|
|
108
143
|
return key === 'invalid' ? this.#lint() : super.getAttribute(key);
|
|
109
144
|
}
|
|
145
|
+
/* PRINT ONLY END */
|
|
146
|
+
/* NOT FOR BROWSER */
|
|
147
|
+
/** @private */
|
|
148
|
+
safeReplaceChildren(elements) {
|
|
149
|
+
if (elements.length === 0) {
|
|
150
|
+
this.setText('');
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
super.safeReplaceChildren(elements);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
110
156
|
}
|
|
111
157
|
exports.NowikiToken = NowikiToken;
|
|
112
158
|
constants_1.classes['NowikiToken'] = __filename;
|
package/dist/src/nowiki/list.js
CHANGED
|
@@ -11,7 +11,6 @@ export declare abstract class NoincludeToken extends NowikiBaseToken {
|
|
|
11
11
|
get type(): 'noinclude';
|
|
12
12
|
/** @param fixed 是否不可更改 */
|
|
13
13
|
constructor(wikitext: string, config?: Config, accum?: Token[], fixed?: boolean);
|
|
14
|
-
lint(start?: number): LintError[];
|
|
15
14
|
cloneNode(): this;
|
|
16
15
|
setText(str: string): string;
|
|
17
16
|
}
|
|
@@ -83,6 +83,7 @@ let NoincludeToken = (() => {
|
|
|
83
83
|
toString(skip) {
|
|
84
84
|
return skip ? '' : super.toString();
|
|
85
85
|
}
|
|
86
|
+
/** @private */
|
|
86
87
|
lint(start = this.getAbsoluteIndex()) {
|
|
87
88
|
LINT: {
|
|
88
89
|
const { lintConfig } = index_1.default, rule = 'no-ignored', s = lintConfig.getSeverity(rule, 'include');
|
|
@@ -14,8 +14,6 @@ export interface QuoteToken extends SyntaxBase {
|
|
|
14
14
|
export declare abstract class QuoteToken extends NowikiBaseToken {
|
|
15
15
|
#private;
|
|
16
16
|
get type(): 'quote';
|
|
17
|
-
get bold(): boolean;
|
|
18
|
-
get italic(): boolean;
|
|
19
17
|
/**
|
|
20
18
|
* whether to be closing quotes
|
|
21
19
|
*
|
|
@@ -23,11 +21,9 @@ export declare abstract class QuoteToken extends NowikiBaseToken {
|
|
|
23
21
|
* @since v1.16.5
|
|
24
22
|
*/
|
|
25
23
|
get closing(): Partial<Font>;
|
|
26
|
-
get font(): Font;
|
|
27
24
|
/** @param closing 是否闭合 */
|
|
28
25
|
constructor(wikitext: string, closing: Font, config?: Config, accum?: Token[]);
|
|
29
26
|
cloneNode(): this;
|
|
30
|
-
setAttribute<T extends string>(key: T, value: TokenAttribute<T>): void;
|
|
31
27
|
/**
|
|
32
28
|
* Find the matching apostrophes
|
|
33
29
|
*
|
package/dist/src/nowiki/quote.js
CHANGED
|
@@ -79,9 +79,11 @@ let QuoteToken = (() => {
|
|
|
79
79
|
get type() {
|
|
80
80
|
return 'quote';
|
|
81
81
|
}
|
|
82
|
+
/** @private */
|
|
82
83
|
get bold() {
|
|
83
84
|
return this.innerText.length !== 2;
|
|
84
85
|
}
|
|
86
|
+
/** @private */
|
|
85
87
|
get italic() {
|
|
86
88
|
return this.innerText.length !== 3;
|
|
87
89
|
}
|
|
@@ -98,6 +100,7 @@ let QuoteToken = (() => {
|
|
|
98
100
|
};
|
|
99
101
|
}
|
|
100
102
|
/* NOT FOR BROWSER */
|
|
103
|
+
/** @private */
|
|
101
104
|
get font() {
|
|
102
105
|
return { bold: this.bold, italic: this.italic };
|
|
103
106
|
}
|
|
@@ -162,6 +165,7 @@ let QuoteToken = (() => {
|
|
|
162
165
|
// @ts-expect-error abstract class
|
|
163
166
|
() => new QuoteToken(this.innerText, this.#closing, this.getAttribute('config')));
|
|
164
167
|
}
|
|
168
|
+
/** @private */
|
|
165
169
|
setAttribute(key, value) {
|
|
166
170
|
if (key === 'bold') {
|
|
167
171
|
this.#match.bold = value;
|
package/dist/src/parameter.js
CHANGED
|
@@ -82,13 +82,11 @@ let ParameterToken = (() => {
|
|
|
82
82
|
/* PRINT ONLY */
|
|
83
83
|
/** whether to be a duplicated parameter / 是否是重复参数 */
|
|
84
84
|
get duplicated() {
|
|
85
|
-
LSP: {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
85
|
+
LSP: try {
|
|
86
|
+
return Boolean(this.parentNode?.getDuplicatedArgs().some(([key]) => key === this.name));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return false;
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
/* PRINT ONLY END */
|
package/dist/src/table/base.d.ts
CHANGED
|
@@ -27,7 +27,6 @@ export declare abstract class TableBaseToken extends Token {
|
|
|
27
27
|
* @param attr 表格属性
|
|
28
28
|
*/
|
|
29
29
|
constructor(pattern: RegExp, syntax: string | undefined, type: TableTypes, attr?: string, config?: Config, accum?: Token[], acceptable?: WikiParserAcceptable);
|
|
30
|
-
escape(): void;
|
|
31
30
|
cloneNode(): this;
|
|
32
31
|
}
|
|
33
32
|
export {};
|
package/dist/src/table/base.js
CHANGED
|
@@ -94,15 +94,14 @@ let TableBaseToken = (() => {
|
|
|
94
94
|
/* NOT FOR BROWSER */
|
|
95
95
|
this.protectChildren([0, 1]);
|
|
96
96
|
}
|
|
97
|
+
/** @private */
|
|
97
98
|
escape() {
|
|
98
|
-
LSP: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
child.escape();
|
|
105
|
-
}
|
|
99
|
+
LSP: for (const child of this.childNodes) {
|
|
100
|
+
if (child instanceof syntax_1.SyntaxToken) {
|
|
101
|
+
escapeTable(child);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
child.escape();
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
}
|