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.
Files changed (53) hide show
  1. package/README.md +3 -0
  2. package/bundle/bundle-es8.min.js +27 -27
  3. package/bundle/bundle-lsp.min.js +30 -30
  4. package/bundle/bundle.min.js +16 -16
  5. package/dist/base.d.mts +1 -1
  6. package/dist/base.d.ts +1 -1
  7. package/dist/base.js +1 -0
  8. package/dist/base.mjs +1 -0
  9. package/dist/bin/config.js +1 -1
  10. package/dist/index.js +8 -7
  11. package/dist/internal.d.ts +3 -0
  12. package/dist/lib/lintConfig.js +6 -0
  13. package/dist/lib/lsp.js +13 -3
  14. package/dist/lib/node.js +3 -11
  15. package/dist/lib/text.js +14 -14
  16. package/dist/lib/title.js +8 -10
  17. package/dist/src/attribute.d.ts +0 -1
  18. package/dist/src/attribute.js +4 -5
  19. package/dist/src/attributes.d.ts +0 -1
  20. package/dist/src/attributes.js +3 -4
  21. package/dist/src/converterFlags.js +5 -7
  22. package/dist/src/link/base.js +2 -1
  23. package/dist/src/link/categorytree.d.ts +1 -3
  24. package/dist/src/link/categorytree.js +11 -0
  25. package/dist/src/multiLine/imagemap.js +1 -1
  26. package/dist/src/nowiki/index.d.ts +1 -1
  27. package/dist/src/nowiki/index.js +59 -13
  28. package/dist/src/nowiki/list.d.ts +0 -1
  29. package/dist/src/nowiki/list.js +1 -0
  30. package/dist/src/nowiki/noinclude.d.ts +0 -1
  31. package/dist/src/nowiki/noinclude.js +1 -0
  32. package/dist/src/nowiki/quote.d.ts +0 -4
  33. package/dist/src/nowiki/quote.js +4 -0
  34. package/dist/src/parameter.js +5 -7
  35. package/dist/src/table/base.d.ts +0 -1
  36. package/dist/src/table/base.js +7 -8
  37. package/dist/src/table/index.d.ts +0 -1
  38. package/dist/src/table/index.js +1 -0
  39. package/dist/src/table/td.d.ts +0 -1
  40. package/dist/src/table/td.js +1 -0
  41. package/dist/src/tag/html.d.ts +0 -1
  42. package/dist/src/tag/html.js +1 -0
  43. package/dist/src/tag/tvar.d.ts +0 -1
  44. package/dist/src/tag/tvar.js +1 -0
  45. package/dist/src/tagPair/index.d.ts +4 -2
  46. package/dist/src/tagPair/index.js +47 -7
  47. package/dist/src/tagPair/translate.d.ts +1 -1
  48. package/dist/src/tagPair/translate.js +3 -1
  49. package/dist/src/transclude.js +2 -2
  50. package/dist/util/diff.js +6 -17
  51. package/extensions/dist/base.js +1 -1
  52. package/logo.png +0 -0
  53. 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
- 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));
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
- console.warn((0, diff_1.loadChalk)()?.yellow(msg) ?? msg, ...args);
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
- console.debug((0, diff_1.loadChalk)()?.blue(msg) ?? msg, ...args);
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,
@@ -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';
@@ -75,6 +75,12 @@ const defaultLintRuleConfig = {
75
75
  },
76
76
  ],
77
77
  'invalid-isbn': 2,
78
+ 'invalid-json': [
79
+ 2,
80
+ {
81
+ duplicate: 1,
82
+ },
83
+ ],
78
84
  'invalid-url': 1,
79
85
  'lonely-apos': [
80
86
  1,
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
- LSP: {
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
- if (prefix && prefix !== ']') {
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 = char === 'r' || char === 'p' || char === 'i', lbrace = char === '{', rbrace = char === '}', lbrack = char === '[', rbrack = char === ']';
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 (char === '<' && !tags.has(tag.toLowerCase())
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 = lbrace && previousChar === '-' && variants.length > 0, rConverter = rbrace && nextChar === '-' && variants.length > 0, brokenExtLink = lbrack && nextType === 'free-ext-link' && !data.slice(index + 1).trim()
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 (!lbrack || type !== 'ext-link-text') {
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 (lbrack && type === 'ext-link-text') {
391
+ else if (lbrackInExtLinkText) {
392
392
  const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
393
393
  e.suggestions = [(0, lint_1.fixByEscape)(i, '&#93;')];
394
394
  }
395
- else if (rbrack && brokenExtLink) {
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
- if (!temporary) {
192
- Object.defineProperties(this, {
193
- encoded: { enumerable: false, writable: false },
194
- /* NOT FOR BROWSER */
195
- valid: { writable: false },
196
- conversionTable: { enumerable: false },
197
- redirects: { enumerable: false },
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
  /**
@@ -53,7 +53,6 @@ export declare abstract class AttributeToken extends Token {
53
53
  * 获取属性值
54
54
  */
55
55
  getValue(): string | true;
56
- escape(): void;
57
56
  cloneNode(): this;
58
57
  /**
59
58
  * Close the quote
@@ -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
- if (this.type !== 'ext-attr') {
370
- this.#equal = '{{=}}';
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 */
@@ -79,7 +79,6 @@ export declare abstract class AttributesToken extends Token {
79
79
  * @param key attribute name / 属性键
80
80
  */
81
81
  getAttr(key: string): string | true | undefined;
82
- escape(): void;
83
82
  /**
84
83
  * Sanitize invalid attributes
85
84
  *
@@ -314,11 +314,10 @@ let AttributesToken = (() => {
314
314
  return errors;
315
315
  }
316
316
  }
317
+ /** @private */
317
318
  escape() {
318
- LSP: {
319
- if (this.type !== 'ext-attrs') {
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
- if (typeof flag === 'object') {
145
- flag = flag.text().trim();
146
- variant = this.getVariantFlags();
147
- unknown = this.getUnknownFlags();
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));
@@ -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
  *
@@ -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
- innerText, previousSibling, } = this, { lintConfig } = index_1.default;
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
- const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'chem-required', s);
91
- if (result.status !== 'C') {
92
- const { message, location } = result.error, [endIndex, endLine, endCol] = updateLocation(e, location.end, n);
93
- [e.startIndex, e.startLine, e.startCol] = updateLocation(e, location.start, n);
94
- Object.assign(e, { endIndex, endLine, endCol, message });
95
- }
96
- errors.push(e);
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 errors;
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;
@@ -10,5 +10,4 @@ export interface ListToken extends SyntaxBase {
10
10
  */
11
11
  export declare abstract class ListToken extends ListBaseToken {
12
12
  get type(): 'list';
13
- lint(start?: number): LintError[];
14
13
  }
@@ -70,6 +70,7 @@ let ListToken = (() => {
70
70
  get type() {
71
71
  return 'list';
72
72
  }
73
+ /** @private */
73
74
  lint(start = this.getAbsoluteIndex()) {
74
75
  LINT: {
75
76
  const rule = 'syntax-like', s = index_1.default.lintConfig.getSeverity(rule, 'redirect'), { innerText } = this;
@@ -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
  *
@@ -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;
@@ -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
- try {
87
- return Boolean(this.parentNode?.getDuplicatedArgs().some(([key]) => key === this.name));
88
- }
89
- catch {
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 */
@@ -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 {};
@@ -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
- for (const child of this.childNodes) {
100
- if (child instanceof syntax_1.SyntaxToken) {
101
- escapeTable(child);
102
- }
103
- else {
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
  }
@@ -88,7 +88,6 @@ export declare abstract class TableToken extends TrBaseToken {
88
88
  * @throws `SyntaxError` 表格的闭合部分非法
89
89
  */
90
90
  insertAt<T extends Token>(token: T, i?: number): T;
91
- getRowCount(): number;
92
91
  /**
93
92
  * Get the next row
94
93
  *