wikilint 2.8.0 → 2.9.1

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 (113) hide show
  1. package/dist/base.d.ts +4 -2
  2. package/dist/base.js +1 -0
  3. package/dist/index.d.ts +3 -7
  4. package/dist/index.js +8 -2
  5. package/dist/lib/element.d.ts +0 -13
  6. package/dist/lib/element.js +4 -11
  7. package/dist/lib/node.d.ts +1 -1
  8. package/dist/lib/node.js +1 -1
  9. package/dist/lib/rect.d.ts +18 -0
  10. package/dist/lib/rect.js +32 -0
  11. package/dist/lib/text.d.ts +0 -6
  12. package/dist/lib/text.js +6 -17
  13. package/dist/mixin/attributesParent.js +2 -1
  14. package/dist/mixin/hidden.d.ts +2 -0
  15. package/dist/mixin/hidden.js +9 -4
  16. package/dist/parser/braces.js +16 -4
  17. package/dist/parser/commentAndExt.js +1 -8
  18. package/dist/parser/converter.js +2 -3
  19. package/dist/parser/externalLinks.js +2 -9
  20. package/dist/parser/hrAndDoubleUnderscore.js +1 -1
  21. package/dist/parser/html.js +1 -1
  22. package/dist/parser/links.js +1 -1
  23. package/dist/parser/magicLinks.js +28 -17
  24. package/dist/parser/redirect.js +1 -1
  25. package/dist/parser/table.js +1 -1
  26. package/dist/src/arg.d.ts +0 -4
  27. package/dist/src/arg.js +6 -5
  28. package/dist/src/atom.d.ts +2 -2
  29. package/dist/src/atom.js +3 -4
  30. package/dist/src/attribute.d.ts +0 -4
  31. package/dist/src/attribute.js +6 -18
  32. package/dist/src/attributes.d.ts +0 -2
  33. package/dist/src/attributes.js +5 -10
  34. package/dist/src/converter.d.ts +0 -2
  35. package/dist/src/converter.js +2 -2
  36. package/dist/src/converterFlags.d.ts +0 -4
  37. package/dist/src/converterFlags.js +4 -3
  38. package/dist/src/converterRule.d.ts +0 -2
  39. package/dist/src/converterRule.js +2 -2
  40. package/dist/src/extLink.d.ts +0 -4
  41. package/dist/src/extLink.js +3 -3
  42. package/dist/src/gallery.d.ts +0 -4
  43. package/dist/src/gallery.js +3 -3
  44. package/dist/src/heading.d.ts +0 -4
  45. package/dist/src/heading.js +5 -10
  46. package/dist/src/hidden.d.ts +1 -1
  47. package/dist/src/hidden.js +53 -3
  48. package/dist/src/html.d.ts +2 -7
  49. package/dist/src/html.js +16 -36
  50. package/dist/src/imageParameter.d.ts +0 -4
  51. package/dist/src/imageParameter.js +5 -5
  52. package/dist/src/imagemap.d.ts +0 -4
  53. package/dist/src/imagemap.js +6 -5
  54. package/dist/src/index.d.ts +0 -11
  55. package/dist/src/index.js +34 -32
  56. package/dist/src/link/base.d.ts +0 -4
  57. package/dist/src/link/base.js +4 -8
  58. package/dist/src/link/file.d.ts +0 -2
  59. package/dist/src/link/file.js +7 -7
  60. package/dist/src/link/galleryImage.d.ts +0 -2
  61. package/dist/src/link/galleryImage.js +2 -3
  62. package/dist/src/link/index.d.ts +0 -2
  63. package/dist/src/link/index.js +1 -1
  64. package/dist/src/link/redirectTarget.d.ts +0 -4
  65. package/dist/src/link/redirectTarget.js +4 -4
  66. package/dist/src/magicLink.d.ts +7 -5
  67. package/dist/src/magicLink.js +37 -7
  68. package/dist/src/nested.d.ts +0 -2
  69. package/dist/src/nested.js +5 -5
  70. package/dist/src/nowiki/base.d.ts +2 -2
  71. package/dist/src/nowiki/base.js +3 -4
  72. package/dist/src/nowiki/comment.d.ts +3 -6
  73. package/dist/src/nowiki/comment.js +78 -28
  74. package/dist/src/nowiki/doubleUnderscore.d.ts +3 -3
  75. package/dist/src/nowiki/doubleUnderscore.js +68 -19
  76. package/dist/src/nowiki/index.d.ts +0 -2
  77. package/dist/src/nowiki/index.js +2 -2
  78. package/dist/src/nowiki/noinclude.d.ts +1 -1
  79. package/dist/src/nowiki/noinclude.js +53 -3
  80. package/dist/src/nowiki/quote.d.ts +0 -2
  81. package/dist/src/nowiki/quote.js +19 -25
  82. package/dist/src/paramTag/index.d.ts +0 -4
  83. package/dist/src/paramTag/index.js +5 -5
  84. package/dist/src/parameter.d.ts +0 -2
  85. package/dist/src/parameter.js +4 -3
  86. package/dist/src/pre.d.ts +0 -2
  87. package/dist/src/pre.js +1 -1
  88. package/dist/src/redirect.d.ts +4 -5
  89. package/dist/src/redirect.js +83 -33
  90. package/dist/src/syntax.d.ts +2 -4
  91. package/dist/src/syntax.js +4 -5
  92. package/dist/src/table/index.d.ts +2 -5
  93. package/dist/src/table/index.js +7 -6
  94. package/dist/src/table/td.d.ts +0 -4
  95. package/dist/src/table/td.js +13 -7
  96. package/dist/src/table/tr.d.ts +2 -2
  97. package/dist/src/table/tr.js +1 -2
  98. package/dist/src/table/trBase.d.ts +0 -2
  99. package/dist/src/table/trBase.js +2 -2
  100. package/dist/src/tagPair/ext.d.ts +0 -2
  101. package/dist/src/tagPair/ext.js +6 -8
  102. package/dist/src/tagPair/include.d.ts +6 -6
  103. package/dist/src/tagPair/include.js +76 -26
  104. package/dist/src/tagPair/index.d.ts +2 -4
  105. package/dist/src/tagPair/index.js +6 -7
  106. package/dist/src/transclude.d.ts +0 -4
  107. package/dist/src/transclude.js +10 -14
  108. package/dist/util/debug.js +10 -1
  109. package/dist/util/lint.js +4 -3
  110. package/dist/util/string.js +5 -5
  111. package/i18n/zh-hans.json +1 -0
  112. package/i18n/zh-hant.json +1 -0
  113. package/package.json +12 -12
package/dist/src/arg.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArgToken = void 0;
4
4
  const string_1 = require("../util/string");
5
5
  const lint_1 = require("../util/lint");
6
+ const rect_1 = require("../lib/rect");
6
7
  const index_1 = require("../index");
7
8
  const index_2 = require("./index");
8
9
  const atom_1 = require("./atom");
@@ -26,7 +27,7 @@ class ArgToken extends index_2.Token {
26
27
  super.insertAt(token);
27
28
  }
28
29
  else if (i > 1) {
29
- const token = new hidden_1.HiddenToken(parts[i], config, accum, {});
30
+ const token = new hidden_1.HiddenToken(parts[i], config, accum);
30
31
  super.insertAt(token);
31
32
  }
32
33
  else {
@@ -41,7 +42,7 @@ class ArgToken extends index_2.Token {
41
42
  toString() {
42
43
  return `{{{${super.toString('|')}}}}`;
43
44
  }
44
- /** @override */
45
+ /** @private */
45
46
  text() {
46
47
  return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
47
48
  }
@@ -53,7 +54,7 @@ class ArgToken extends index_2.Token {
53
54
  getGaps() {
54
55
  return 1;
55
56
  }
56
- /** @override */
57
+ /** @private */
57
58
  lint(start = this.getAbsoluteIndex(), re) {
58
59
  const { childNodes: [argName, argDefault, ...rest] } = this;
59
60
  if (!this.getAttribute('include')) {
@@ -68,10 +69,10 @@ class ArgToken extends index_2.Token {
68
69
  }
69
70
  const errors = argName.lint(start + 3, re);
70
71
  if (argDefault) {
71
- errors.push(...argDefault.lint(start + 4 + String(argName).length, re));
72
+ errors.push(...argDefault.lint(start + 4 + argName.toString().length, re));
72
73
  }
73
74
  if (rest.length > 0) {
74
- const rect = { start, ...this.getRootNode().posFromIndex(start) };
75
+ const rect = new rect_1.BoundingRect(this, start);
75
76
  errors.push(...rest.map(child => {
76
77
  const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', 'invisible content inside triple braces');
77
78
  e.startIndex--;
@@ -1,10 +1,10 @@
1
- import Parser from '../index';
2
1
  import { Token } from './index';
2
+ import type { Config } from '../base';
3
3
  declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
4
4
  /** 不会被继续解析的plain Token */
5
5
  export declare class AtomToken extends Token {
6
6
  type: AtomTypes;
7
7
  /** @class */
8
- constructor(wikitext: string | undefined, type: AtomTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
8
+ constructor(wikitext: string | undefined, type: AtomTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
9
9
  }
10
10
  export {};
package/dist/src/atom.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AtomToken = void 0;
4
- const index_1 = require("../index");
5
- const index_2 = require("./index");
4
+ const index_1 = require("./index");
6
5
  /** 不会被继续解析的plain Token */
7
- class AtomToken extends index_2.Token {
6
+ class AtomToken extends index_1.Token {
8
7
  /** @class */
9
- constructor(wikitext, type, config = index_1.default.getConfig(), accum = [], acceptable) {
8
+ constructor(wikitext, type, config, accum, acceptable) {
10
9
  super(wikitext, config, accum, acceptable);
11
10
  this.type = type;
12
11
  }
@@ -31,10 +31,6 @@ export declare abstract class AttributeToken extends Token {
31
31
  * @param quotes 引号
32
32
  */
33
33
  constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
34
- /** @override */
35
- text(): string;
36
- /** @override */
37
- lint(start?: number, re?: RegExp): LintError[];
38
34
  /** 获取属性值 */
39
35
  getValue(): string | true;
40
36
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AttributeToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
+ const rect_1 = require("../lib/rect");
5
6
  const string_1 = require("../util/string");
6
7
  const constants_1 = require("../util/constants");
7
8
  const index_1 = require("../index");
@@ -144,13 +145,7 @@ const commonHtmlAttrs = new Set([
144
145
  ]),
145
146
  tabs: new Set(['plain', 'class', 'container', 'id', 'title', 'style']),
146
147
  combobox: new Set(['placeholder', 'value', 'id', 'class', 'text', 'dropdown', 'style']),
147
- }, insecureStyle = new RegExp('expression'
148
- + '|'
149
- + '(?:accelerator|-o-link(?:-source)?|-o-replace)\\s*:'
150
- + '|'
151
- + '(?:url|image(?:-set)?)\\s*\\('
152
- + '|'
153
- + 'attr\\s*\\([^)]+[\\s,]url', 'u'), obsoleteAttrs = {
148
+ }, insecureStyle = /expression|(?:accelerator|-o-link(?:-source)?|-o-replace)\s*:|(?:url|image(?:-set)?)\s*\(|attr\s*\([^)]+[\s,]url/u, obsoleteAttrs = {
154
149
  table: obsoleteTableAttrs,
155
150
  td: new Set([...obsoleteTdAttrs, 'scope']),
156
151
  th: obsoleteTdAttrs,
@@ -244,9 +239,9 @@ class AttributeToken extends index_2.Token {
244
239
  /** @private */
245
240
  toString() {
246
241
  const [quoteStart = '', quoteEnd = ''] = this.#quotes;
247
- return this.#equal ? super.toString(this.#equal + quoteStart) + quoteEnd : String(this.firstChild);
242
+ return this.#equal ? super.toString(this.#equal + quoteStart) + quoteEnd : this.firstChild.toString();
248
243
  }
249
- /** @override */
244
+ /** @private */
250
245
  text() {
251
246
  return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
252
247
  }
@@ -254,13 +249,10 @@ class AttributeToken extends index_2.Token {
254
249
  getGaps() {
255
250
  return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
256
251
  }
257
- /** @override */
252
+ /** @private */
258
253
  lint(start = this.getAbsoluteIndex(), re) {
259
- const errors = super.lint(start, re), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
260
- let rect;
254
+ const errors = super.lint(start, re), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue(), rect = new rect_1.BoundingRect(this, start);
261
255
  if (!balanced) {
262
- const root = this.getRootNode();
263
- rect = { start, ...root.posFromIndex(start) };
264
256
  const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed-quote', index_1.default.msg('unclosed $1', 'quotes'), 'warning');
265
257
  e.startIndex--;
266
258
  e.startCol--;
@@ -287,19 +279,15 @@ class AttributeToken extends index_2.Token {
287
279
  && !htmlAttrs[tag]?.has(name)
288
280
  && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
289
281
  && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
290
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
291
282
  errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal-attr', 'illegal attribute name'));
292
283
  }
293
284
  else if (obsoleteAttrs[tag]?.has(name)) {
294
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
295
285
  errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete-attr', 'obsolete attribute', 'warning'));
296
286
  }
297
287
  else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
298
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
299
288
  errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure-style', 'insecure style'));
300
289
  }
301
290
  else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
302
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
303
291
  const e = (0, lint_1.generateForChild)(lastChild, rect, 'illegal-attr', 'nonzero tabindex');
304
292
  e.suggestions = [
305
293
  {
@@ -38,7 +38,5 @@ export declare abstract class AttributesToken extends Token {
38
38
  * @param key 属性键
39
39
  */
40
40
  getAttr(key: string): string | true | undefined;
41
- /** @override */
42
- lint(start?: number, re?: RegExp): LintError[];
43
41
  }
44
42
  export {};
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AttributesToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
+ const rect_1 = require("../lib/rect");
5
6
  const string_1 = require("../util/string");
6
7
  const index_1 = require("../index");
7
8
  const index_2 = require("./index");
8
9
  const atom_1 = require("./atom");
9
10
  const attribute_1 = require("./attribute");
11
+ const regex = /([^\s/](?:(?!\0\d+~\x7F)[^\s/=])*)(?:((?:\s(?:\s|\0\d+c\x7F)*)?(?:=|\0\d+~\x7F)(?:\s|\0\d+c\x7F)*)(?:(["'])(.*?)(\3|$)|(\S*)))?/gsu;
10
12
  /**
11
13
  * 将属性类型转换为单属性类型
12
14
  * @param type 属性类型
@@ -32,10 +34,7 @@ class AttributesToken extends index_2.Token {
32
34
  this.type = type;
33
35
  this.setAttribute('name', name);
34
36
  if (attr) {
35
- const regex = new RegExp('([^\\s/](?:(?!\0\\d+~\x7F)[^\\s/=])*)' // 属性名
36
- + `(?:${'((?:\\s|\0\\d+c\x7F)*(?:=|\0\\d+~\x7F)(?:\\s|\0\\d+c\x7F)*)' // `=`和前后的空白字符
37
- + `(?:(["'])(.*?)(\\3|$)|(\\S*))` // 属性值
38
- })?`, 'gsu');
37
+ regex.lastIndex = 0;
39
38
  let out = '', mt = regex.exec(attr), lastIndex = 0;
40
39
  const insertDirty = /** 插入无效属性 */ () => {
41
40
  if (out) {
@@ -92,12 +91,10 @@ class AttributesToken extends index_2.Token {
92
91
  getAttr(key) {
93
92
  return this.getAttrToken(key)?.getValue();
94
93
  }
95
- /** @override */
94
+ /** @private */
96
95
  lint(start = this.getAbsoluteIndex(), re) {
97
- const errors = super.lint(start, re), { parentNode, length, childNodes } = this, attrs = new Map(), duplicated = new Set();
98
- let rect;
96
+ const errors = super.lint(start, re), { parentNode, length, childNodes } = this, attrs = new Map(), duplicated = new Set(), rect = new rect_1.BoundingRect(this, start);
99
97
  if (parentNode?.type === 'html' && parentNode.closing && this.text().trim()) {
100
- rect = { start, ...this.getRootNode().posFromIndex(start) };
101
98
  const e = (0, lint_1.generateForSelf)(this, rect, 'no-ignored', 'attributes of a closing tag');
102
99
  e.fix = { range: [start, e.endIndex], text: '' };
103
100
  errors.push(e);
@@ -105,7 +102,6 @@ class AttributesToken extends index_2.Token {
105
102
  for (let i = 0; i < length; i++) {
106
103
  const attr = childNodes[i];
107
104
  if (attr instanceof atom_1.AtomToken && attr.text().trim()) {
108
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
109
105
  const e = (0, lint_1.generateForChild)(attr, rect, 'no-ignored', 'containing invalid attribute');
110
106
  e.suggestions = [
111
107
  {
@@ -128,7 +124,6 @@ class AttributesToken extends index_2.Token {
128
124
  }
129
125
  }
130
126
  if (duplicated.size > 0) {
131
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
132
127
  for (const key of duplicated) {
133
128
  errors.push(...attrs.get(key).map(attr => (0, lint_1.generateForChild)(attr, rect, 'no-duplicate', index_1.default.msg('duplicated $1 attribute', key))));
134
129
  }
@@ -16,6 +16,4 @@ export declare abstract class ConverterToken extends Token {
16
16
  * @param rules 转换规则
17
17
  */
18
18
  constructor(flags: readonly string[], rules: readonly [string, ...string[]], config?: Parser.Config, accum?: Token[]);
19
- /** @override */
20
- text(): string;
21
19
  }
@@ -36,9 +36,9 @@ class ConverterToken extends index_2.Token {
36
36
  /** @private */
37
37
  toString() {
38
38
  const { childNodes: [flags, ...rules] } = this;
39
- return `-{${String(flags)}${flags.length > 0 ? '|' : ''}${rules.map(String).join(';')}}-`;
39
+ return `-{${flags.toString()}${flags.length > 0 ? '|' : ''}${rules.map(String).join(';')}}-`;
40
40
  }
41
- /** @override */
41
+ /** @private */
42
42
  text() {
43
43
  const { childNodes: [flags, ...rules] } = this;
44
44
  return `-{${flags.text()}|${(0, string_1.text)(rules, ';')}}-`;
@@ -18,12 +18,8 @@ export declare abstract class ConverterFlagsToken extends Token {
18
18
  abstract get nextSibling(): ConverterRuleToken | undefined;
19
19
  /** @param flags 转换类型标记 */
20
20
  constructor(flags: readonly string[], config?: Parser.Config, accum?: Token[]);
21
- /** @override */
22
- text(): string;
23
21
  /** 获取未知的转换类型标记 */
24
22
  getUnknownFlags(): Set<string>;
25
23
  /** 获取指定语言变体的转换标记 */
26
24
  getVariantFlags(): Set<string>;
27
- /** @override */
28
- lint(start?: number, re?: RegExp): LintError[];
29
25
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConverterFlagsToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
+ const rect_1 = require("../lib/rect");
5
6
  const index_1 = require("../index");
6
7
  const index_2 = require("./index");
7
8
  const atom_1 = require("./atom");
@@ -26,7 +27,7 @@ class ConverterFlagsToken extends index_2.Token {
26
27
  toString() {
27
28
  return super.toString(';');
28
29
  }
29
- /** @override */
30
+ /** @private */
30
31
  text() {
31
32
  return super.text(';');
32
33
  }
@@ -43,13 +44,13 @@ class ConverterFlagsToken extends index_2.Token {
43
44
  const variants = new Set(this.getAttribute('config').variants);
44
45
  return new Set(this.#flags.filter(flag => variants.has(flag)));
45
46
  }
46
- /** @override */
47
+ /** @private */
47
48
  lint(start = this.getAbsoluteIndex(), re) {
48
49
  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);
49
50
  if (variantFlags.size === knownFlagCount || validFlags.size === knownFlagCount) {
50
51
  return errors;
51
52
  }
52
- const rect = { start, ...this.getRootNode().posFromIndex(start) }, { childNodes, length } = this;
53
+ const rect = new rect_1.BoundingRect(this, start), { childNodes, length } = this;
53
54
  for (let i = 0; i < length; i++) {
54
55
  const child = childNodes[i], flag = child.text().trim();
55
56
  if (flag
@@ -19,6 +19,4 @@ export declare abstract class ConverterRuleToken extends Token {
19
19
  * @param hasColon 是否带有":"
20
20
  */
21
21
  constructor(rule: string, hasColon?: boolean, config?: Parser.Config, accum?: Token[]);
22
- /** @override */
23
- text(): string;
24
22
  }
@@ -33,11 +33,11 @@ class ConverterRuleToken extends index_2.Token {
33
33
  const { childNodes } = this;
34
34
  if (childNodes.length === 3) {
35
35
  const [from, variant, to] = childNodes;
36
- return `${String(from)}=>${String(variant)}:${String(to)}`;
36
+ return `${from.toString()}=>${variant.toString()}:${to.toString()}`;
37
37
  }
38
38
  return super.toString(':');
39
39
  }
40
- /** @override */
40
+ /** @private */
41
41
  text() {
42
42
  const { childNodes } = this;
43
43
  if (childNodes.length === 3) {
@@ -18,8 +18,4 @@ export declare abstract class ExtLinkToken extends Token {
18
18
  * @param text 链接文字
19
19
  */
20
20
  constructor(url?: string, space?: string, text?: string, config?: Parser.Config, accum?: Token[]);
21
- /** @override */
22
- text(): string;
23
- /** @override */
24
- lint(start?: number, re?: RegExp): LintError[];
25
21
  }
@@ -23,7 +23,7 @@ class ExtLinkToken extends index_2.Token {
23
23
  const link = url && /\0\d+f\x7F/u.test(url)
24
24
  ? accum[Number(url.slice(1, -2))]
25
25
  // @ts-expect-error abstract class
26
- : new magicLink_1.MagicLinkToken(url, true, config, accum);
26
+ : new magicLink_1.MagicLinkToken(url, 'ext-link-url', config, accum);
27
27
  this.insertAt(link);
28
28
  this.#space = space;
29
29
  if (text) {
@@ -40,7 +40,7 @@ class ExtLinkToken extends index_2.Token {
40
40
  }
41
41
  return `[${super.toString(this.#space)}]`;
42
42
  }
43
- /** @override */
43
+ /** @private */
44
44
  text() {
45
45
  return `[${super.text(' ')}]`;
46
46
  }
@@ -52,7 +52,7 @@ class ExtLinkToken extends index_2.Token {
52
52
  getGaps() {
53
53
  return this.#space.length;
54
54
  }
55
- /** @override */
55
+ /** @private */
56
56
  lint(start = this.getAbsoluteIndex(), re) {
57
57
  const errors = super.lint(start, re);
58
58
  if (this.length === 1 && this.closest('heading-title')) {
@@ -20,8 +20,4 @@ export declare abstract class GalleryToken extends Token {
20
20
  abstract get parentNode(): ExtToken | undefined;
21
21
  /** @param inner 标签内部wikitext */
22
22
  constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
23
- /** @override */
24
- text(): string;
25
- /** @override */
26
- lint(start?: number, re?: RegExp): LintError[];
27
23
  }
@@ -43,7 +43,7 @@ class GalleryToken extends index_2.Token {
43
43
  toString() {
44
44
  return super.toString('\n');
45
45
  }
46
- /** @override */
46
+ /** @private */
47
47
  text() {
48
48
  return super.text('\n').replace(/\n\s*\n/gu, '\n');
49
49
  }
@@ -51,11 +51,11 @@ class GalleryToken extends index_2.Token {
51
51
  getGaps() {
52
52
  return 1;
53
53
  }
54
- /** @override */
54
+ /** @private */
55
55
  lint(start = this.getAbsoluteIndex(), re) {
56
56
  const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
57
57
  for (let i = 0; i < this.length; i++) {
58
- const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
58
+ const child = this.childNodes[i], str = child.toString(), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
59
59
  if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
60
60
  errors.push({
61
61
  rule: 'no-ignored',
@@ -19,8 +19,4 @@ export declare abstract class HeadingToken extends Token {
19
19
  * @param input 标题文字
20
20
  */
21
21
  constructor(level: number, input: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
22
- /** @override */
23
- text(): string;
24
- /** @override */
25
- lint(start?: number, re?: RegExp): LintError[];
26
22
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HeadingToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
+ const rect_1 = require("../lib/rect");
5
6
  const index_1 = require("../index");
6
7
  const index_2 = require("./index");
7
8
  const syntax_1 = require("./syntax");
@@ -36,9 +37,9 @@ class HeadingToken extends index_2.Token {
36
37
  /** @private */
37
38
  toString() {
38
39
  const equals = this.#equals;
39
- return equals + String(this.firstChild) + equals + String(this.lastChild);
40
+ return equals + this.firstChild.toString() + equals + this.lastChild.toString();
40
41
  }
41
- /** @override */
42
+ /** @private */
42
43
  text() {
43
44
  const equals = this.#equals;
44
45
  return equals + this.firstChild.text() + equals;
@@ -51,28 +52,22 @@ class HeadingToken extends index_2.Token {
51
52
  getGaps() {
52
53
  return this.level;
53
54
  }
54
- /** @override */
55
+ /** @private */
55
56
  lint(start = this.getAbsoluteIndex(), re) {
56
- const errors = super.lint(start, re), { firstChild, level } = this, innerStr = String(firstChild), quotes = firstChild.childNodes.filter((node) => node.type === 'quote'), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic);
57
- let rect;
57
+ const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), quotes = firstChild.childNodes.filter((node) => node.type === 'quote'), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic), rect = new rect_1.BoundingRect(this, start);
58
58
  if (this.level === 1) {
59
- rect = { start, ...this.getRootNode().posFromIndex(start) };
60
59
  errors.push((0, lint_1.generateForChild)(firstChild, rect, 'h1', '<h1>'));
61
60
  }
62
61
  if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
63
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
64
62
  errors.push((0, lint_1.generateForChild)(firstChild, rect, 'unbalanced-header', index_1.default.msg('unbalanced $1 in a section header', '"="')));
65
63
  }
66
64
  if (this.closest('html-attrs, table-attrs')) {
67
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
68
65
  errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in a HTML tag'));
69
66
  }
70
67
  if (boldQuotes.length % 2) {
71
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
72
68
  errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')));
73
69
  }
74
70
  if (italicQuotes.length % 2) {
75
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
76
71
  errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes')));
77
72
  }
78
73
  return errors;
@@ -1,5 +1,5 @@
1
1
  import { Token } from './index';
2
+ /** 不可见的节点 */
2
3
  export declare class HiddenToken extends Token {
3
4
  readonly type = "hidden";
4
5
  }
5
- export {};
@@ -1,10 +1,60 @@
1
1
  "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.HiddenToken = void 0;
4
38
  const hidden_1 = require("../mixin/hidden");
5
39
  const index_1 = require("./index");
6
40
  /** 不可见的节点 */
7
- class HiddenToken extends (0, hidden_1.hiddenToken)(index_1.Token) {
8
- type = 'hidden';
9
- }
41
+ let HiddenToken = (() => {
42
+ let _classDecorators = [(0, hidden_1.hiddenToken)(true)];
43
+ let _classDescriptor;
44
+ let _classExtraInitializers = [];
45
+ let _classThis;
46
+ let _classSuper = index_1.Token;
47
+ var HiddenToken = class extends _classSuper {
48
+ static { _classThis = this; }
49
+ static {
50
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
51
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
52
+ HiddenToken = _classThis = _classDescriptor.value;
53
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
54
+ __runInitializers(_classThis, _classExtraInitializers);
55
+ }
56
+ type = 'hidden';
57
+ };
58
+ return HiddenToken = _classThis;
59
+ })();
10
60
  exports.HiddenToken = HiddenToken;
@@ -1,6 +1,5 @@
1
- import Parser from '../index';
2
1
  import { Token } from './index';
3
- import type { LintError } from '../base';
2
+ import type { Config, LintError } from '../base';
4
3
  import type { AttributesToken } from '../internal';
5
4
  /**
6
5
  * HTML标签
@@ -23,11 +22,7 @@ export declare abstract class HtmlToken extends Token {
23
22
  * @param closing 是否闭合
24
23
  * @param selfClosing 是否自封闭
25
24
  */
26
- constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: Parser.Config, accum?: Token[]);
27
- /** @override */
28
- text(): string;
29
- /** @override */
30
- lint(start?: number, re?: RegExp): LintError[];
25
+ constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: Config, accum?: Token[]);
31
26
  /**
32
27
  * 搜索匹配的标签
33
28
  * @throws `SyntaxError` 同时闭合和自封闭的标签