wikiparser-node 1.9.0 → 1.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 (111) hide show
  1. package/README.en.md +2 -2
  2. package/dist/addon/table.js +9 -8
  3. package/dist/addon/token.js +8 -5
  4. package/dist/addon/transclude.js +12 -10
  5. package/dist/base.d.ts +2 -0
  6. package/dist/index.d.ts +2 -4
  7. package/dist/index.js +5 -2
  8. package/dist/lib/element.d.ts +0 -5
  9. package/dist/lib/element.js +46 -39
  10. package/dist/lib/node.d.ts +1 -1
  11. package/dist/lib/node.js +9 -9
  12. package/dist/lib/rect.d.ts +18 -0
  13. package/dist/lib/rect.js +34 -0
  14. package/dist/lib/text.js +8 -13
  15. package/dist/mixin/attributesParent.js +2 -1
  16. package/dist/mixin/fixed.js +5 -3
  17. package/dist/mixin/flagsParent.js +2 -1
  18. package/dist/mixin/hidden.d.ts +2 -0
  19. package/dist/mixin/hidden.js +9 -4
  20. package/dist/mixin/magicLinkParent.js +2 -1
  21. package/dist/mixin/singleLine.js +3 -2
  22. package/dist/mixin/sol.js +3 -2
  23. package/dist/mixin/syntax.js +3 -6
  24. package/dist/parser/braces.js +13 -6
  25. package/dist/parser/commentAndExt.js +3 -13
  26. package/dist/parser/converter.js +4 -5
  27. package/dist/parser/externalLinks.js +2 -9
  28. package/dist/parser/hrAndDoubleUnderscore.js +3 -1
  29. package/dist/parser/html.js +1 -1
  30. package/dist/parser/links.js +3 -1
  31. package/dist/parser/magicLinks.js +7 -13
  32. package/dist/parser/redirect.js +1 -1
  33. package/dist/parser/selector.js +8 -8
  34. package/dist/src/arg.d.ts +0 -2
  35. package/dist/src/arg.js +6 -7
  36. package/dist/src/atom.d.ts +2 -2
  37. package/dist/src/atom.js +4 -5
  38. package/dist/src/attribute.d.ts +0 -2
  39. package/dist/src/attribute.js +7 -19
  40. package/dist/src/attributes.d.ts +0 -2
  41. package/dist/src/attributes.js +11 -17
  42. package/dist/src/converter.d.ts +0 -2
  43. package/dist/src/converter.js +1 -1
  44. package/dist/src/converterFlags.d.ts +0 -2
  45. package/dist/src/converterFlags.js +3 -2
  46. package/dist/src/converterRule.d.ts +0 -2
  47. package/dist/src/converterRule.js +10 -9
  48. package/dist/src/extLink.d.ts +0 -2
  49. package/dist/src/extLink.js +1 -1
  50. package/dist/src/gallery.d.ts +0 -2
  51. package/dist/src/gallery.js +3 -3
  52. package/dist/src/heading.d.ts +0 -2
  53. package/dist/src/heading.js +4 -9
  54. package/dist/src/hidden.d.ts +4 -1
  55. package/dist/src/hidden.js +69 -13
  56. package/dist/src/html.d.ts +2 -5
  57. package/dist/src/html.js +19 -38
  58. package/dist/src/imageParameter.d.ts +0 -2
  59. package/dist/src/imageParameter.js +11 -7
  60. package/dist/src/imagemap.d.ts +0 -2
  61. package/dist/src/imagemap.js +7 -6
  62. package/dist/src/index.d.ts +1 -13
  63. package/dist/src/index.js +58 -58
  64. package/dist/src/link/base.d.ts +0 -2
  65. package/dist/src/link/base.js +5 -9
  66. package/dist/src/link/file.js +11 -9
  67. package/dist/src/link/galleryImage.js +2 -2
  68. package/dist/src/link/index.d.ts +0 -2
  69. package/dist/src/link/index.js +5 -5
  70. package/dist/src/link/redirectTarget.d.ts +0 -12
  71. package/dist/src/link/redirectTarget.js +4 -10
  72. package/dist/src/magicLink.d.ts +1 -0
  73. package/dist/src/magicLink.js +29 -19
  74. package/dist/src/nested.js +3 -3
  75. package/dist/src/nowiki/base.d.ts +2 -2
  76. package/dist/src/nowiki/base.js +3 -4
  77. package/dist/src/nowiki/comment.d.ts +3 -9
  78. package/dist/src/nowiki/comment.js +106 -59
  79. package/dist/src/nowiki/doubleUnderscore.d.ts +3 -3
  80. package/dist/src/nowiki/doubleUnderscore.js +3 -4
  81. package/dist/src/nowiki/index.js +3 -1
  82. package/dist/src/nowiki/noinclude.d.ts +1 -1
  83. package/dist/src/nowiki/noinclude.js +63 -13
  84. package/dist/src/nowiki/quote.js +18 -24
  85. package/dist/src/onlyinclude.js +1 -1
  86. package/dist/src/paramTag/index.d.ts +0 -2
  87. package/dist/src/paramTag/index.js +3 -3
  88. package/dist/src/parameter.js +10 -9
  89. package/dist/src/redirect.d.ts +4 -1
  90. package/dist/src/redirect.js +5 -3
  91. package/dist/src/syntax.d.ts +2 -2
  92. package/dist/src/syntax.js +4 -5
  93. package/dist/src/table/index.d.ts +2 -3
  94. package/dist/src/table/index.js +9 -8
  95. package/dist/src/table/td.d.ts +0 -4
  96. package/dist/src/table/td.js +17 -7
  97. package/dist/src/table/tr.d.ts +2 -4
  98. package/dist/src/table/tr.js +2 -3
  99. package/dist/src/table/trBase.d.ts +0 -2
  100. package/dist/src/table/trBase.js +2 -2
  101. package/dist/src/tagPair/ext.js +5 -7
  102. package/dist/src/tagPair/include.d.ts +7 -5
  103. package/dist/src/tagPair/include.js +106 -56
  104. package/dist/src/tagPair/index.d.ts +2 -4
  105. package/dist/src/tagPair/index.js +4 -4
  106. package/dist/src/transclude.d.ts +0 -2
  107. package/dist/src/transclude.js +15 -17
  108. package/dist/util/debug.js +10 -1
  109. package/dist/util/lint.js +3 -2
  110. package/dist/util/string.js +5 -5
  111. package/package.json +12 -12
@@ -1,6 +1,7 @@
1
- import Parser from '../../index';
2
1
  import { NowikiBaseToken } from './base';
2
+ import type { Config } from '../../base';
3
3
  import type { Token } from '../index';
4
+ /** 状态开关 */
4
5
  export declare abstract class DoubleUnderscoreToken extends NowikiBaseToken {
5
6
  #private;
6
7
  readonly type = "double-underscore";
@@ -9,8 +10,7 @@ export declare abstract class DoubleUnderscoreToken extends NowikiBaseToken {
9
10
  * @param word 状态开关名
10
11
  * @param sensitive 是否固定大小写
11
12
  */
12
- constructor(word: string, sensitive: boolean, config?: Parser.Config, accum?: Token[]);
13
+ constructor(word: string, sensitive: boolean, config?: Config, accum?: Token[]);
13
14
  /** @override */
14
15
  cloneNode(): this;
15
16
  }
16
- export {};
@@ -39,15 +39,14 @@ const debug_1 = require("../../util/debug");
39
39
  const constants_1 = require("../../util/constants");
40
40
  const hidden_1 = require("../../mixin/hidden");
41
41
  const syntax_1 = require("../../mixin/syntax");
42
- const index_1 = require("../../index");
43
42
  const base_1 = require("./base");
44
43
  /** 状态开关 */
45
44
  let DoubleUnderscoreToken = (() => {
46
- let _classDecorators = [(0, syntax_1.syntax)()];
45
+ let _classDecorators = [(0, syntax_1.syntax)(), (0, hidden_1.hiddenToken)(true)];
47
46
  let _classDescriptor;
48
47
  let _classExtraInitializers = [];
49
48
  let _classThis;
50
- let _classSuper = (0, hidden_1.hiddenToken)(base_1.NowikiBaseToken);
49
+ let _classSuper = base_1.NowikiBaseToken;
51
50
  var DoubleUnderscoreToken = class extends _classSuper {
52
51
  static { _classThis = this; }
53
52
  static {
@@ -64,7 +63,7 @@ let DoubleUnderscoreToken = (() => {
64
63
  * @param word 状态开关名
65
64
  * @param sensitive 是否固定大小写
66
65
  */
67
- constructor(word, sensitive, config = index_1.default.getConfig(), accum = []) {
66
+ constructor(word, sensitive, config, accum) {
68
67
  super(word, config, accum);
69
68
  /* NOT FOR BROWSER */
70
69
  this.#sensitive = sensitive;
@@ -20,7 +20,9 @@ class NowikiToken extends base_1.NowikiBaseToken {
20
20
  };
21
21
  return [e];
22
22
  }
23
- return super.lint(start, new RegExp(`<\\s*(?:\\/\\s*)${name === 'nowiki' ? '' : '?'}(${name})\\b`, 'giu'));
23
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
24
+ /<\s*(?:\/\s*)?(nowiki)\b/giu;
25
+ return super.lint(start, new RegExp(String.raw `<\s*(?:/\s*)${name === 'nowiki' ? '' : '?'}(${name})\b`, 'giu'));
24
26
  }
25
27
  }
26
28
  exports.NowikiToken = NowikiToken;
@@ -1,4 +1,5 @@
1
1
  import { NowikiBaseToken } from './base';
2
+ /** `<noinclude>`和`</noinclude>`,不可进行任何更改 */
2
3
  export declare abstract class NoincludeToken extends NowikiBaseToken {
3
4
  readonly type = "noinclude";
4
5
  /**
@@ -7,4 +8,3 @@ export declare abstract class NoincludeToken extends NowikiBaseToken {
7
8
  */
8
9
  setText(str: string): string;
9
10
  }
10
- export {};
@@ -1,23 +1,73 @@
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.NoincludeToken = void 0;
4
38
  const constants_1 = require("../../util/constants");
5
39
  const hidden_1 = require("../../mixin/hidden");
6
40
  const base_1 = require("./base");
7
41
  /** `<noinclude>`和`</noinclude>`,不可进行任何更改 */
8
- class NoincludeToken extends (0, hidden_1.hiddenToken)(base_1.NowikiBaseToken) {
9
- type = 'noinclude';
10
- /* NOT FOR BROWSER */
11
- /**
12
- * @override
13
- * @param str 新文本
14
- */
15
- setText(str) {
16
- if (/^<\/?(?:(?:no|only)include|includeonly)(?:\s[^>]*)?\/?>$/iu.test(this.innerText)) {
17
- this.constructorError('不可更改文字内容');
42
+ let NoincludeToken = (() => {
43
+ let _classDecorators = [(0, hidden_1.hiddenToken)(true)];
44
+ let _classDescriptor;
45
+ let _classExtraInitializers = [];
46
+ let _classThis;
47
+ let _classSuper = base_1.NowikiBaseToken;
48
+ var NoincludeToken = class extends _classSuper {
49
+ static { _classThis = this; }
50
+ static {
51
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
52
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
53
+ NoincludeToken = _classThis = _classDescriptor.value;
54
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
55
+ __runInitializers(_classThis, _classExtraInitializers);
18
56
  }
19
- return super.setText(str);
20
- }
21
- }
57
+ type = 'noinclude';
58
+ /* NOT FOR BROWSER */
59
+ /**
60
+ * @override
61
+ * @param str 新文本
62
+ */
63
+ setText(str) {
64
+ if (/^<\/?(?:(?:no|only)include|includeonly)(?:\s[^>]*)?\/?>$/iu.test(this.innerText)) {
65
+ this.constructorError('cannot change the text content');
66
+ }
67
+ return super.setText(str);
68
+ }
69
+ };
70
+ return NoincludeToken = _classThis;
71
+ })();
22
72
  exports.NoincludeToken = NoincludeToken;
23
73
  constants_1.classes['NoincludeToken'] = __filename;
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.QuoteToken = void 0;
38
38
  const lint_1 = require("../../util/lint");
39
+ const rect_1 = require("../../lib/rect");
39
40
  const constants_1 = require("../../util/constants");
40
41
  const syntax_1 = require("../../mixin/syntax");
41
42
  const index_1 = require("../../index");
@@ -73,10 +74,21 @@ let QuoteToken = (() => {
73
74
  /* NOT FOR BROWSER END */
74
75
  /** @private */
75
76
  lint(start = this.getAbsoluteIndex()) {
76
- const { previousSibling, nextSibling, bold } = this, message = index_1.default.msg('lonely "$1"', `'`), errors = [];
77
+ const { previousSibling, nextSibling, bold } = this, message = index_1.default.msg('lonely "$1"', `'`), errors = [], rect = new rect_1.BoundingRect(this, start);
77
78
  let refError;
79
+ /**
80
+ * 获取建议
81
+ * @param startIndex 起点
82
+ * @param endIndex 终点
83
+ * @param length 长度
84
+ */
85
+ const getSuggestion = (startIndex, endIndex, length) => ({
86
+ desc: 'escape',
87
+ range: [startIndex, endIndex],
88
+ text: '&apos;'.repeat(length),
89
+ });
78
90
  if (previousSibling?.type === 'text' && previousSibling.data.endsWith(`'`)) {
79
- refError = (0, lint_1.generateForSelf)(this, { start }, 'lonely-apos', message);
91
+ refError = (0, lint_1.generateForSelf)(this, rect, 'lonely-apos', message);
80
92
  const { startIndex: endIndex, startLine: endLine, startCol: endCol } = refError, [, { length }] = /(?:^|[^'])('+)$/u.exec(previousSibling.data), startIndex = start - length;
81
93
  errors.push({
82
94
  ...refError,
@@ -85,17 +97,11 @@ let QuoteToken = (() => {
85
97
  startCol: endCol - length,
86
98
  endLine,
87
99
  endCol,
88
- suggestions: [
89
- {
90
- desc: 'escape',
91
- range: [startIndex, endIndex],
92
- text: '&apos;'.repeat(length),
93
- },
94
- ],
100
+ suggestions: [getSuggestion(startIndex, endIndex, length)],
95
101
  });
96
102
  }
97
103
  if (nextSibling?.type === 'text' && nextSibling.data.startsWith(`'`)) {
98
- refError ??= (0, lint_1.generateForSelf)(this, { start }, 'lonely-apos', message);
104
+ refError ??= (0, lint_1.generateForSelf)(this, rect, 'lonely-apos', message);
99
105
  const { endIndex: startIndex, endLine: startLine, endCol: startCol } = refError, [{ length }] = /^'+/u.exec(nextSibling.data), endIndex = startIndex + length;
100
106
  errors.push({
101
107
  ...refError,
@@ -104,23 +110,11 @@ let QuoteToken = (() => {
104
110
  startLine,
105
111
  startCol,
106
112
  endCol: startCol + length,
107
- suggestions: [
108
- {
109
- desc: 'escape',
110
- range: [startIndex, endIndex],
111
- text: '&apos;'.repeat(length),
112
- },
113
- ],
113
+ suggestions: [getSuggestion(startIndex, endIndex, length)],
114
114
  });
115
115
  }
116
116
  if (bold && this.closest('heading-title')) {
117
- refError ??= (0, lint_1.generateForSelf)(this, { start }, 'lonely-apos', message);
118
- errors.push({
119
- ...refError,
120
- rule: 'bold-header',
121
- message: index_1.default.msg('bold in section header'),
122
- severity: 'warning',
123
- });
117
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'bold-header', 'bold in section header', 'warning'));
124
118
  }
125
119
  return errors;
126
120
  }
@@ -19,7 +19,7 @@ class OnlyincludeToken extends index_2.Token {
19
19
  /** @throws `RangeError` 不允许包含`</onlyinclude>` */
20
20
  set innerText(text) {
21
21
  if (text.includes('</onlyinclude>')) {
22
- throw new RangeError('不允许包含 "</onlyinclude>"');
22
+ throw new RangeError('"</onlyinclude>" is not allowed in the text!');
23
23
  }
24
24
  this.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
25
25
  }
@@ -25,8 +25,6 @@ export declare abstract class ParamTagToken extends Token {
25
25
  /** @class */
26
26
  constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
27
27
  /** @override */
28
- text(): string;
29
- /** @override */
30
28
  cloneNode(this: this & {
31
29
  constructor: new (...args: any[]) => unknown;
32
30
  }): this;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParamTagToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
+ const rect_1 = require("../../lib/rect");
5
6
  const debug_1 = require("../../util/debug");
6
7
  const constants_1 = require("../../util/constants");
7
8
  const singleLine_1 = require("../../mixin/singleLine");
@@ -31,7 +32,7 @@ class ParamTagToken extends index_2.Token {
31
32
  toString() {
32
33
  return super.toString('\n');
33
34
  }
34
- /** @override */
35
+ /** @private */
35
36
  text() {
36
37
  return super.text('\n');
37
38
  }
@@ -41,12 +42,11 @@ class ParamTagToken extends index_2.Token {
41
42
  }
42
43
  /** @private */
43
44
  lint(start = this.getAbsoluteIndex()) {
44
- let rect;
45
+ const rect = new rect_1.BoundingRect(this, start);
45
46
  return this.childNodes.filter(child => {
46
47
  const { childNodes } = child, i = childNodes.findIndex(({ type }) => type !== 'text'), str = (i >= 0 ? childNodes.slice(0, i).map(String).join('') : child.toString()).trim();
47
48
  return str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str);
48
49
  }).map(child => {
49
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
50
50
  const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', index_1.default.msg('invalid parameter of <$1>', this.name));
51
51
  e.suggestions = [
52
52
  {
@@ -47,6 +47,9 @@ const index_2 = require("./index");
47
47
  * @param name 预定的参数名
48
48
  */
49
49
  const getName = (name) => name.text().replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
50
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
51
+ /https?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\0\t\n\p{Zs}]*$/iu;
52
+ const linkRegex = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu');
50
53
  /**
51
54
  * 模板或魔术字参数
52
55
  * @classdesc `{childNodes: [Token, Token]}`
@@ -75,7 +78,7 @@ let ParameterToken = (() => {
75
78
  /* NOT FOR BROWSER */
76
79
  set anon(value) {
77
80
  if (value) {
78
- throw new Error('无法将命名参数转换为匿名参数!');
81
+ throw new Error('Cannot convert named parameter to anonymous parameter!');
79
82
  }
80
83
  this.parentNode?.anonToNamed();
81
84
  }
@@ -154,9 +157,7 @@ let ParameterToken = (() => {
154
157
  }
155
158
  /** @private */
156
159
  lint(start = this.getAbsoluteIndex(), re) {
157
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
158
- /https?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*$/iu;
159
- const errors = super.lint(start, re), { firstChild } = this, link = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu').exec(firstChild.text())?.[0];
160
+ const errors = super.lint(start, re), { firstChild } = this, link = linkRegex.exec(firstChild.text())?.[0];
160
161
  if (link && new URL(link).search) {
161
162
  const e = (0, lint_1.generateForChild)(firstChild, { start }, 'unescaped', 'unescaped query string in an anonymous parameter');
162
163
  e.startIndex = e.endIndex;
@@ -203,7 +204,7 @@ let ParameterToken = (() => {
203
204
  * @param token 待替换的节点
204
205
  */
205
206
  safeReplaceWith(token) {
206
- index_1.default.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
207
+ index_1.default.warn(`${this.constructor.name}.safeReplaceWith regress to AstNode.replaceWith.`);
207
208
  this.replaceWith(token);
208
209
  }
209
210
  /** 获取参数值 */
@@ -230,21 +231,21 @@ let ParameterToken = (() => {
230
231
  const { parentNode, anon } = this;
231
232
  // 必须检测是否是TranscludeToken
232
233
  if (parentNode?.isTemplate() === false) {
233
- throw new Error('rename 方法仅用于模板参数!');
234
+ throw new Error('ParameterToken.rename method is only for template parameters!');
234
235
  }
235
236
  else if (anon) {
236
237
  parentNode?.anonToNamed();
237
238
  }
238
239
  const root = index_1.default.parse(key, this.getAttribute('include'), undefined, this.getAttribute('config')), name = getName(root);
239
240
  if (this.name === name) {
240
- index_1.default.warn('未改变实际参数名', name);
241
+ index_1.default.warn('The actual parameter name is not changed', name);
241
242
  }
242
243
  else if (parentNode?.hasArg(name)) {
243
244
  if (force) {
244
- index_1.default.warn('参数更名造成重复参数', name);
245
+ index_1.default.warn('Parameter renaming causes duplicated parameters', name);
245
246
  }
246
247
  else {
247
- throw new RangeError(`参数更名造成重复参数:${name}`);
248
+ throw new RangeError(`Parameter renaming causes duplicated parameters: ${name}`);
248
249
  }
249
250
  }
250
251
  this.firstChild.replaceChildren(...root.childNodes);
@@ -3,6 +3,10 @@ import { Token } from './index';
3
3
  import { SyntaxToken } from './syntax';
4
4
  import { RedirectTargetToken } from './link/redirectTarget';
5
5
  import type { LintError } from '../base';
6
+ /**
7
+ * 重定向
8
+ * @classdesc `{childNodes: [SyntaxToken, LinkToken]}`
9
+ */
6
10
  export declare abstract class RedirectToken extends Token {
7
11
  #private;
8
12
  readonly type = "redirect";
@@ -25,4 +29,3 @@ export declare abstract class RedirectToken extends Token {
25
29
  /** @override */
26
30
  cloneNode(): this;
27
31
  }
28
- export {};
@@ -48,11 +48,11 @@ const redirectTarget_1 = require("./link/redirectTarget");
48
48
  * @classdesc `{childNodes: [SyntaxToken, LinkToken]}`
49
49
  */
50
50
  let RedirectToken = (() => {
51
- let _classDecorators = [fixed_1.fixedToken];
51
+ let _classDecorators = [fixed_1.fixedToken, (0, hidden_1.hiddenToken)()];
52
52
  let _classDescriptor;
53
53
  let _classExtraInitializers = [];
54
54
  let _classThis;
55
- let _classSuper = (0, hidden_1.hiddenToken)(index_2.Token);
55
+ let _classSuper = index_2.Token;
56
56
  var RedirectToken = class extends _classSuper {
57
57
  static { _classThis = this; }
58
58
  static {
@@ -77,7 +77,9 @@ let RedirectToken = (() => {
77
77
  super(undefined, config, accum);
78
78
  this.#pre = pre;
79
79
  this.#post = post;
80
- const pattern = new RegExp(`^(?:${config.redirection.join('|')})\\s*(?::\\s*)?$`, 'iu');
80
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
81
+ /^(?:#redirect|#重定向)\s*(?::\s*)?$/iu;
82
+ const pattern = new RegExp(String.raw `^(?:${config.redirection.join('|')})\s*(?::\s*)?$`, 'iu');
81
83
  this.append(new syntax_1.SyntaxToken(syntax, pattern, 'redirect-syntax', config, accum, {
82
84
  AstText: ':',
83
85
  }),
@@ -1,5 +1,5 @@
1
- import Parser from '../index';
2
1
  import { Token } from './index';
2
+ import type { Config } from '../base';
3
3
  import type { SyntaxBase } from '../mixin/syntax';
4
4
  declare type SyntaxTypes = 'plain' | 'heading-trail' | 'magic-word-name' | 'table-syntax' | 'redirect-syntax';
5
5
  /** NOT FOR BROWSER */
@@ -10,7 +10,7 @@ export interface SyntaxToken extends SyntaxBase {
10
10
  export declare class SyntaxToken extends Token {
11
11
  type: SyntaxTypes;
12
12
  /** @param pattern 语法正则 */
13
- constructor(wikitext: string | undefined, pattern: RegExp, type?: SyntaxTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
13
+ constructor(wikitext: string | undefined, pattern: RegExp, type?: SyntaxTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
14
14
  /** @override */
15
15
  cloneNode(): this;
16
16
  }
@@ -38,8 +38,7 @@ exports.SyntaxToken = void 0;
38
38
  const debug_1 = require("../util/debug");
39
39
  const constants_1 = require("../util/constants");
40
40
  const syntax_1 = require("../mixin/syntax");
41
- const index_1 = require("../index");
42
- const index_2 = require("./index");
41
+ const index_1 = require("./index");
43
42
  /** NOT FOR BROWSER END */
44
43
  /** 满足特定语法格式的plain Token */
45
44
  let SyntaxToken = (() => {
@@ -47,7 +46,7 @@ let SyntaxToken = (() => {
47
46
  let _classDescriptor;
48
47
  let _classExtraInitializers = [];
49
48
  let _classThis;
50
- let _classSuper = index_2.Token;
49
+ let _classSuper = index_1.Token;
51
50
  var SyntaxToken = class extends _classSuper {
52
51
  static { _classThis = this; }
53
52
  static {
@@ -58,7 +57,7 @@ let SyntaxToken = (() => {
58
57
  __runInitializers(_classThis, _classExtraInitializers);
59
58
  }
60
59
  /** @param pattern 语法正则 */
61
- constructor(wikitext, pattern, type = 'plain', config = index_1.default.getConfig(), accum = [], acceptable) {
60
+ constructor(wikitext, pattern, type = 'plain', config, accum, acceptable) {
62
61
  super(wikitext, config, accum, acceptable);
63
62
  this.type = type;
64
63
  /* NOT FOR BROWSER */
@@ -71,7 +70,7 @@ let SyntaxToken = (() => {
71
70
  /* NOT FOR BROWSER */
72
71
  /** @override */
73
72
  cloneNode() {
74
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
73
+ const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAcceptable();
75
74
  return debug_1.Shadow.run(() => {
76
75
  const token = new SyntaxToken(undefined, this.pattern, this.type, config, [], acceptable);
77
76
  token.append(...cloned);
@@ -1,7 +1,6 @@
1
- import Parser from '../../index';
2
1
  import { TrBaseToken } from './trBase';
3
2
  import { SyntaxToken } from '../syntax';
4
- import type { LintError, AST } from '../../base';
3
+ import type { Config, LintError, AST } from '../../base';
5
4
  import type { SyntaxBase } from '../../mixin/syntax';
6
5
  import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
7
6
  import type { TableCoords } from './trBase';
@@ -41,7 +40,7 @@ export declare abstract class TableToken extends TrBaseToken {
41
40
  * @param syntax 表格语法
42
41
  * @param attr 表格属性
43
42
  */
44
- constructor(syntax: string, attr?: string, config?: Parser.Config, accum?: Token[]);
43
+ constructor(syntax: string, attr?: string, config?: Config, accum?: Token[]);
45
44
  /**
46
45
  * 闭合表格语法
47
46
  * @param syntax 表格结尾语法
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TableToken = exports.Layout = exports.isRowEnd = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
+ const rect_1 = require("../../lib/rect");
5
6
  const debug_1 = require("../../util/debug");
6
7
  const string_1 = require("../../util/string");
7
8
  const constants_1 = require("../../util/constants");
@@ -63,16 +64,16 @@ class TableToken extends trBase_1.TrBaseToken {
63
64
  * @param syntax 表格语法
64
65
  * @param attr 表格属性
65
66
  */
66
- constructor(syntax, attr, config = index_1.default.getConfig(), accum = []) {
67
+ constructor(syntax, attr, config, accum) {
67
68
  super(/^(?:\{\||\{\{\{\s*!\s*\}\}|\{\{\s*\(!\s*\}\})$/u, syntax, attr, config, accum, {
68
69
  Token: 2, SyntaxToken: [0, -1], AttributesToken: 1, TdToken: '2:', TrToken: '2:',
69
70
  });
70
71
  }
71
72
  /** @private */
72
73
  lint(start = this.getAbsoluteIndex(), re) {
73
- const errors = super.lint(start, re);
74
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
74
75
  if (!this.closed) {
75
- errors.push((0, lint_1.generateForChild)(this.firstChild, { start }, 'unclosed-table', index_1.default.msg('unclosed $1', 'table')));
76
+ errors.push((0, lint_1.generateForChild)(this.firstChild, rect, 'unclosed-table', index_1.default.msg('unclosed $1', 'table')));
76
77
  }
77
78
  const layout = this.getLayout(), { length } = layout;
78
79
  if (length > 1) {
@@ -85,7 +86,7 @@ class TableToken extends trBase_1.TrBaseToken {
85
86
  else if (max < high) {
86
87
  high = max;
87
88
  }
88
- const { colspan } = this.getNthCell(row[row.length - 1]), min = max - colspan + 1;
89
+ const min = row.indexOf(row[max - 1]) + 1;
89
90
  if (min > high) {
90
91
  break;
91
92
  }
@@ -94,7 +95,7 @@ class TableToken extends trBase_1.TrBaseToken {
94
95
  }
95
96
  }
96
97
  if (j < length) {
97
- const e = (0, lint_1.generateForChild)(this.getNthRow(j), { start }, 'table-layout', 'inconsistent table layout', 'warning');
98
+ const e = (0, lint_1.generateForChild)(this.getNthRow(j), rect, 'table-layout', 'inconsistent table layout', 'warning');
98
99
  e.startIndex++;
99
100
  e.startLine++;
100
101
  e.startCol = 0;
@@ -206,7 +207,7 @@ class TableToken extends trBase_1.TrBaseToken {
206
207
  /* NOT FOR BROWSER */
207
208
  }
208
209
  else if (n < 0 || n > nRows || n === nRows && !insert) {
209
- throw new RangeError(`不存在第 ${n} 行!`);
210
+ throw new RangeError(`The table does not have row ${n}!`);
210
211
  /* NOT FOR BROWSER END */
211
212
  }
212
213
  else if (isRow) {
@@ -244,11 +245,11 @@ class TableToken extends trBase_1.TrBaseToken {
244
245
  i += i < 0 ? this.length : 0;
245
246
  const previous = this.childNodes[i - 1];
246
247
  if (typeof token !== 'string' && token.type === 'td' && previous?.type === 'tr') {
247
- index_1.default.warn('改为将单元格插入当前行。');
248
+ index_1.default.warn('The table cell is inserted into the current row instead.');
248
249
  return previous.insertAt(token);
249
250
  }
250
251
  else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.pattern !== closingPattern) {
251
- throw new SyntaxError(`表格的闭合部分不符合语法:${(0, string_1.noWrap)(token.toString())}`);
252
+ throw new SyntaxError(`The closing part of the table is invalid: ${(0, string_1.noWrap)(token.toString())}`);
252
253
  }
253
254
  return super.insertAt(token, i);
254
255
  }
@@ -42,8 +42,6 @@ export declare abstract class TdToken extends TableBaseToken {
42
42
  * @param inner 内部wikitext
43
43
  */
44
44
  constructor(syntax: string, inner?: string, config?: Parser.Config, accum?: Token[]);
45
- /** @override */
46
- text(): string;
47
45
  /** 是否位于行首 */
48
46
  isIndependent(): boolean;
49
47
  /**
@@ -67,8 +65,6 @@ export declare abstract class TdToken extends TableBaseToken {
67
65
  */
68
66
  setAttr<T extends string>(key: T, value: TdAttrSetter<T>): void;
69
67
  setAttr(prop: Record<string, string | number | boolean>): void;
70
- /** @override */
71
- escape(): void;
72
68
  }
73
69
  /**
74
70
  * 创建新的单元格
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.createTd = exports.TdToken = void 0;
38
38
  const lint_1 = require("../../util/lint");
39
+ const rect_1 = require("../../lib/rect");
39
40
  const constants_1 = require("../../util/constants");
40
41
  const debug_1 = require("../../util/debug");
41
42
  const fixed_1 = require("../../mixin/fixed");
@@ -65,6 +66,7 @@ let TdToken = (() => {
65
66
  }
66
67
  type = 'td';
67
68
  #innerSyntax = '';
69
+ #syntax;
68
70
  /* NOT FOR BROWSER END */
69
71
  /** rowspan */
70
72
  get rowspan() {
@@ -117,6 +119,15 @@ let TdToken = (() => {
117
119
  }
118
120
  /** 表格语法信息 */
119
121
  #getSyntax() {
122
+ if (index_1.default.viewOnly) {
123
+ this.#syntax ??= this.#computeSyntax();
124
+ return this.#syntax;
125
+ }
126
+ this.#syntax = undefined;
127
+ return this.#computeSyntax();
128
+ }
129
+ /** 表格语法信息 */
130
+ #computeSyntax() {
120
131
  const syntax = this.firstChild.text(),
121
132
  /* NOT FOR BROWSER */
122
133
  esc = syntax.includes('{{'),
@@ -144,7 +155,7 @@ let TdToken = (() => {
144
155
  }
145
156
  /* NOT FOR BROWSER END */
146
157
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
147
- const result = previousSibling.#getSyntax();
158
+ const result = { ...previousSibling.#getSyntax() };
148
159
  /* NOT FOR BROWSER */
149
160
  const str = previousSibling.lastChild.toString();
150
161
  result.escape ||= esc;
@@ -175,7 +186,7 @@ let TdToken = (() => {
175
186
  const { childNodes: [syntax, attr, inner] } = this;
176
187
  return syntax.toString() + attr.toString() + this.#innerSyntax + inner.toString();
177
188
  }
178
- /** @override */
189
+ /** @private */
179
190
  text() {
180
191
  /* NOT FOR BROWSER */
181
192
  this.#correct();
@@ -195,13 +206,12 @@ let TdToken = (() => {
195
206
  }
196
207
  /** @private */
197
208
  lint(start = this.getAbsoluteIndex(), re) {
198
- const errors = super.lint(start, re);
199
- start += this.getRelativeIndex(this.length - 1);
209
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start + this.getRelativeIndex(this.length - 1));
200
210
  for (const child of this.lastChild.childNodes) {
201
211
  if (child.type === 'text') {
202
212
  const { data } = child;
203
213
  if (data.includes('|')) {
204
- const isError = data.includes('||'), e = (0, lint_1.generateForChild)(child, { start }, 'pipe-like', 'additional "|" in a table cell', isError ? 'error' : 'warning');
214
+ const isError = data.includes('||'), e = (0, lint_1.generateForChild)(child, rect, 'pipe-like', 'additional "|" in a table cell', isError ? 'error' : 'warning');
205
215
  if (isError) {
206
216
  const syntax = { caption: '|+', td: '|', th: '!' }[this.subtype];
207
217
  e.fix = {
@@ -314,14 +324,14 @@ let TdToken = (() => {
314
324
  v = value === 1 ? false : String(value);
315
325
  }
316
326
  else {
317
- v = value;
327
+ v = String(value);
318
328
  }
319
329
  super.setAttr(key, v);
320
330
  if (!this.childNodes[1].toString()) {
321
331
  this.#innerSyntax = '';
322
332
  }
323
333
  }
324
- /** @override */
334
+ /** @private */
325
335
  escape() {
326
336
  super.escape();
327
337
  if (this.childNodes[1].toString()) {