wikiparser-node 1.0.0-beta.0 → 1.0.0-beta.2

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 (133) hide show
  1. package/config/.schema.json +26 -0
  2. package/dist/index.d.ts +11 -9
  3. package/dist/index.js +22 -24
  4. package/dist/internal.d.ts +44 -0
  5. package/dist/lib/element.d.ts +42 -32
  6. package/dist/lib/element.js +59 -56
  7. package/dist/lib/node.d.ts +29 -36
  8. package/dist/lib/node.js +33 -48
  9. package/dist/lib/range.d.ts +132 -0
  10. package/dist/lib/range.js +387 -0
  11. package/dist/lib/ranges.d.ts +2 -12
  12. package/dist/lib/ranges.js +6 -11
  13. package/dist/lib/text.d.ts +11 -5
  14. package/dist/lib/text.js +25 -13
  15. package/dist/lib/title.d.ts +4 -5
  16. package/dist/lib/title.js +17 -7
  17. package/dist/mixin/attributesParent.js +6 -3
  18. package/dist/mixin/fixed.js +8 -5
  19. package/dist/mixin/hidden.js +7 -3
  20. package/dist/mixin/singleLine.js +6 -3
  21. package/dist/mixin/sol.js +6 -3
  22. package/dist/parser/{brackets.js → braces.js} +34 -26
  23. package/dist/parser/commentAndExt.js +25 -15
  24. package/dist/parser/converter.js +16 -9
  25. package/dist/parser/externalLinks.js +15 -9
  26. package/dist/parser/hrAndDoubleUnderscore.js +17 -10
  27. package/dist/parser/html.js +18 -9
  28. package/dist/parser/links.js +22 -14
  29. package/dist/parser/list.js +20 -10
  30. package/dist/parser/magicLinks.js +14 -7
  31. package/dist/parser/quotes.js +21 -11
  32. package/dist/parser/selector.js +19 -12
  33. package/dist/parser/table.js +25 -16
  34. package/dist/src/arg.d.ts +7 -8
  35. package/dist/src/arg.js +27 -24
  36. package/dist/src/atom.d.ts +4 -5
  37. package/dist/src/atom.js +9 -7
  38. package/dist/src/attribute.d.ts +13 -13
  39. package/dist/src/attribute.js +28 -25
  40. package/dist/src/attributes.d.ts +11 -10
  41. package/dist/src/attributes.js +40 -45
  42. package/dist/src/converter.d.ts +5 -7
  43. package/dist/src/converter.js +22 -16
  44. package/dist/src/converterFlags.d.ts +11 -12
  45. package/dist/src/converterFlags.js +17 -14
  46. package/dist/src/converterRule.d.ts +9 -10
  47. package/dist/src/converterRule.js +27 -27
  48. package/dist/src/extLink.d.ts +4 -6
  49. package/dist/src/extLink.js +25 -22
  50. package/dist/src/gallery.d.ts +9 -13
  51. package/dist/src/gallery.js +28 -23
  52. package/dist/src/heading.d.ts +11 -11
  53. package/dist/src/heading.js +19 -19
  54. package/dist/src/hidden.d.ts +4 -5
  55. package/dist/src/hidden.js +10 -8
  56. package/dist/src/html.d.ts +15 -12
  57. package/dist/src/html.js +18 -15
  58. package/dist/src/imageParameter.d.ts +11 -13
  59. package/dist/src/imageParameter.js +21 -16
  60. package/dist/src/imagemap.d.ts +11 -15
  61. package/dist/src/imagemap.js +26 -21
  62. package/dist/src/imagemapLink.d.ts +12 -17
  63. package/dist/src/imagemapLink.js +19 -14
  64. package/dist/src/index.d.ts +24 -20
  65. package/dist/src/index.js +65 -75
  66. package/dist/src/link/base.d.ts +8 -10
  67. package/dist/src/link/base.js +28 -22
  68. package/dist/src/link/category.d.ts +2 -3
  69. package/dist/src/link/category.js +7 -5
  70. package/dist/src/link/file.d.ts +9 -11
  71. package/dist/src/link/file.js +53 -26
  72. package/dist/src/link/galleryImage.d.ts +8 -8
  73. package/dist/src/link/galleryImage.js +18 -16
  74. package/dist/src/link/index.d.ts +6 -6
  75. package/dist/src/link/index.js +14 -16
  76. package/dist/src/magicLink.d.ts +9 -6
  77. package/dist/src/magicLink.js +23 -18
  78. package/dist/src/nested.d.ts +10 -10
  79. package/dist/src/nested.js +25 -17
  80. package/dist/src/nowiki/base.d.ts +7 -8
  81. package/dist/src/nowiki/base.js +10 -8
  82. package/dist/src/nowiki/comment.d.ts +7 -7
  83. package/dist/src/nowiki/comment.js +12 -9
  84. package/dist/src/nowiki/dd.d.ts +2 -3
  85. package/dist/src/nowiki/dd.js +7 -11
  86. package/dist/src/nowiki/doubleUnderscore.d.ts +5 -7
  87. package/dist/src/nowiki/doubleUnderscore.js +11 -8
  88. package/dist/src/nowiki/hr.d.ts +6 -7
  89. package/dist/src/nowiki/hr.js +11 -8
  90. package/dist/src/nowiki/index.d.ts +5 -7
  91. package/dist/src/nowiki/index.js +8 -6
  92. package/dist/src/nowiki/list.d.ts +4 -4
  93. package/dist/src/nowiki/list.js +8 -6
  94. package/dist/src/nowiki/noinclude.d.ts +3 -3
  95. package/dist/src/nowiki/noinclude.js +8 -6
  96. package/dist/src/nowiki/quote.d.ts +6 -7
  97. package/dist/src/nowiki/quote.js +11 -8
  98. package/dist/src/onlyinclude.d.ts +3 -5
  99. package/dist/src/onlyinclude.js +9 -7
  100. package/dist/src/paramTag/index.d.ts +8 -10
  101. package/dist/src/paramTag/index.js +15 -13
  102. package/dist/src/paramTag/inputbox.d.ts +4 -6
  103. package/dist/src/paramTag/inputbox.js +10 -8
  104. package/dist/src/parameter.d.ts +11 -12
  105. package/dist/src/parameter.js +25 -22
  106. package/dist/src/pre.d.ts +5 -10
  107. package/dist/src/pre.js +16 -11
  108. package/dist/src/syntax.d.ts +6 -7
  109. package/dist/src/syntax.js +12 -10
  110. package/dist/src/table/base.d.ts +14 -9
  111. package/dist/src/table/base.js +18 -15
  112. package/dist/src/table/index.d.ts +24 -17
  113. package/dist/src/table/index.js +39 -67
  114. package/dist/src/table/td.d.ts +17 -21
  115. package/dist/src/table/td.js +20 -28
  116. package/dist/src/table/tr.d.ts +6 -11
  117. package/dist/src/table/tr.js +8 -6
  118. package/dist/src/table/trBase.d.ts +12 -22
  119. package/dist/src/table/trBase.js +23 -19
  120. package/dist/src/tagPair/ext.d.ts +10 -10
  121. package/dist/src/tagPair/ext.js +47 -24
  122. package/dist/src/tagPair/include.d.ts +6 -7
  123. package/dist/src/tagPair/include.js +11 -8
  124. package/dist/src/tagPair/index.d.ts +12 -11
  125. package/dist/src/tagPair/index.js +13 -11
  126. package/dist/src/transclude.d.ts +8 -10
  127. package/dist/src/transclude.js +70 -77
  128. package/dist/util/debug.js +2 -12
  129. package/dist/util/diff.js +4 -2
  130. package/dist/util/lint.js +5 -5
  131. package/dist/util/string.js +2 -31
  132. package/package.json +13 -13
  133. package/dist/util/base.js +0 -26
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConverterFlagsToken = void 0;
2
4
  const lint_1 = require("../util/lint");
3
- const Parser = require("../index");
4
- const Token = require(".");
5
- const AtomToken = require("./atom");
5
+ const index_1 = require("../index");
6
+ const _1 = require(".");
7
+ const atom_1 = require("./atom");
6
8
  const definedFlags = new Set(['A', 'T', 'R', 'D', '-', 'H', 'N']);
7
9
  /**
8
10
  * 转换flags
9
11
  * @classdesc `{childNodes: ...AtomToken}`
10
12
  */
11
- class ConverterFlagsToken extends Token {
13
+ class ConverterFlagsToken extends _1.Token {
12
14
  /** @browser */
13
15
  type = 'converter-flags';
14
16
  /** @browser */
@@ -17,11 +19,11 @@ class ConverterFlagsToken extends Token {
17
19
  * @browser
18
20
  * @param flags 转换类型标记
19
21
  */
20
- constructor(flags, config = Parser.getConfig(), accum = []) {
22
+ constructor(flags, config = index_1.default.getConfig(), accum = []) {
21
23
  super(undefined, config, true, accum, {
22
24
  AtomToken: ':',
23
25
  });
24
- this.append(...flags.map(flag => new AtomToken(flag, 'converter-flag', config, accum)));
26
+ this.append(...flags.map(flag => new atom_1.AtomToken(flag, 'converter-flag', config, accum)));
25
27
  }
26
28
  /** @private */
27
29
  afterBuild() {
@@ -48,8 +50,8 @@ class ConverterFlagsToken extends Token {
48
50
  return super.text(';');
49
51
  }
50
52
  /** @private */
51
- getGaps() {
52
- return 1;
53
+ getGaps(i) {
54
+ return i < this.length - 1 ? 1 : 0;
53
55
  }
54
56
  /**
55
57
  * @override
@@ -96,7 +98,8 @@ class ConverterFlagsToken extends Token {
96
98
  /** @override */
97
99
  cloneNode() {
98
100
  const cloned = this.cloneChildNodes();
99
- return Parser.run(() => {
101
+ return index_1.default.run(() => {
102
+ // @ts-expect-error abstract class
100
103
  const token = new ConverterFlagsToken([], this.getAttribute('config'));
101
104
  token.append(...cloned);
102
105
  token.afterBuild();
@@ -183,14 +186,14 @@ class ConverterFlagsToken extends Token {
183
186
  * @param flag 转换类型标记
184
187
  */
185
188
  hasFlag(flag) {
186
- return typeof flag === 'string' ? this.#flags.includes(flag) : this.typeError('hasFlag', 'String');
189
+ return this.#flags.includes(flag);
187
190
  }
188
191
  /**
189
192
  * 是否具有某有效的转换类型标记
190
193
  * @param flag 转换类型标记
191
194
  */
192
195
  hasEffectiveFlag(flag) {
193
- return typeof flag === 'string' ? this.getEffectiveFlags().has(flag) : this.typeError('hasEffectiveFlag', 'String');
196
+ return this.getEffectiveFlags().has(flag);
194
197
  }
195
198
  /**
196
199
  * 移除某转换类型标记
@@ -206,7 +209,7 @@ class ConverterFlagsToken extends Token {
206
209
  * @param flag 转换类型标记
207
210
  */
208
211
  #newFlag(flag) {
209
- const token = Parser.run(() => new AtomToken(flag, 'converter-flag', this.getAttribute('config')));
212
+ const token = index_1.default.run(() => new atom_1.AtomToken(flag, 'converter-flag', this.getAttribute('config')));
210
213
  this.insertAt(token);
211
214
  }
212
215
  /**
@@ -231,5 +234,5 @@ class ConverterFlagsToken extends Token {
231
234
  }
232
235
  }
233
236
  }
234
- Parser.classes['ConverterFlagsToken'] = __filename;
235
- module.exports = ConverterFlagsToken;
237
+ exports.ConverterFlagsToken = ConverterFlagsToken;
238
+ index_1.default.classes['ConverterFlagsToken'] = __filename;
@@ -1,11 +1,11 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
3
- import AtomToken = require('./atom');
1
+ import { Token } from '.';
2
+ import { AtomToken } from './atom';
3
+ import type { ConverterToken, ConverterFlagsToken } from '../internal';
4
4
  /**
5
5
  * 转换规则
6
6
  * @classdesc `{childNodes: ...AtomToken}`
7
7
  */
8
- declare abstract class ConverterRuleToken extends Token {
8
+ export declare abstract class ConverterRuleToken extends Token {
9
9
  /** @browser */
10
10
  readonly type = "converter-rule";
11
11
  childNodes: [AtomToken] | [AtomToken, AtomToken] | [AtomToken, AtomToken, AtomToken];
@@ -14,10 +14,10 @@ declare abstract class ConverterRuleToken extends Token {
14
14
  abstract get firstElementChild(): AtomToken;
15
15
  abstract get lastChild(): AtomToken;
16
16
  abstract get lastElementChild(): AtomToken;
17
- abstract get parentNode(): import('./converter') | undefined;
18
- abstract get parentElement(): import('./converter') | undefined;
19
- abstract get previousSibling(): import('./converterFlags') | this;
20
- abstract get previousElementSibling(): import('./converterFlags') | this;
17
+ abstract get parentNode(): ConverterToken | undefined;
18
+ abstract get parentElement(): ConverterToken | undefined;
19
+ abstract get previousSibling(): ConverterFlagsToken | this;
20
+ abstract get previousElementSibling(): ConverterFlagsToken | this;
21
21
  abstract get nextSibling(): this | undefined;
22
22
  abstract get nextElementSibling(): this | undefined;
23
23
  /** 语言变体 */
@@ -36,7 +36,7 @@ declare abstract class ConverterRuleToken extends Token {
36
36
  * @param rule 转换规则
37
37
  * @param hasColon 是否带有":"
38
38
  */
39
- constructor(rule: string, hasColon?: boolean, config?: Parser.Config, accum?: Token[]);
39
+ constructor(rule: string, hasColon?: boolean, config?: import("../index").Config, accum?: Token[]);
40
40
  /**
41
41
  * @override
42
42
  * @browser
@@ -94,4 +94,3 @@ declare abstract class ConverterRuleToken extends Token {
94
94
  /** 修改为双向转换 */
95
95
  makeBidirectional(): void;
96
96
  }
97
- export = ConverterRuleToken;
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConverterRuleToken = void 0;
2
4
  const debug_1 = require("../util/debug");
3
5
  const string_1 = require("../util/string");
4
- const Parser = require("../index");
5
- const Token = require(".");
6
- const AtomToken = require("./atom");
6
+ const index_1 = require("../index");
7
+ const _1 = require(".");
8
+ const atom_1 = require("./atom");
7
9
  /**
8
10
  * 转换规则
9
11
  * @classdesc `{childNodes: ...AtomToken}`
10
12
  */
11
- class ConverterRuleToken extends Token {
13
+ class ConverterRuleToken extends _1.Token {
12
14
  /** @browser */
13
15
  type = 'converter-rule';
14
16
  /** 语言变体 */
@@ -57,23 +59,23 @@ class ConverterRuleToken extends Token {
57
59
  * @param rule 转换规则
58
60
  * @param hasColon 是否带有":"
59
61
  */
60
- constructor(rule, hasColon = true, config = Parser.getConfig(), accum = []) {
62
+ constructor(rule, hasColon = true, config = index_1.default.getConfig(), accum = []) {
61
63
  super(undefined, config, true, accum);
62
64
  if (hasColon) {
63
65
  const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
64
66
  if (config.variants.includes(v.trim())) {
65
- super.insertAt(new AtomToken(v, 'converter-rule-variant', config, accum));
66
- super.insertAt(new AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
67
+ super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
68
+ super.insertAt(new atom_1.AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
67
69
  if (j !== -1) {
68
- super.insertAt(new AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
70
+ super.insertAt(new atom_1.AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
69
71
  }
70
72
  }
71
73
  else {
72
- super.insertAt(new AtomToken(rule, 'converter-rule-noconvert', config, accum));
74
+ super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-noconvert', config, accum));
73
75
  }
74
76
  }
75
77
  else {
76
- super.insertAt(new AtomToken(rule, 'converter-rule-noconvert', config, accum));
78
+ super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-noconvert', config, accum));
77
79
  }
78
80
  this.protectChildren('1:');
79
81
  }
@@ -102,9 +104,9 @@ class ConverterRuleToken extends Token {
102
104
  return super.text(':');
103
105
  }
104
106
  /** @private */
105
- getGaps(i = 0) {
106
- const { length } = this, j = i < 0 ? i + length : i;
107
- return j === 0 && length === 3 ? 2 : 1;
107
+ getGaps(i) {
108
+ const { length } = this;
109
+ return i === 0 && length === 3 ? 2 : 1;
108
110
  }
109
111
  /**
110
112
  * @override
@@ -121,7 +123,8 @@ class ConverterRuleToken extends Token {
121
123
  /** @override */
122
124
  cloneNode() {
123
125
  const cloned = this.cloneChildNodes(), placeholders = ['', 'zh:', '=>zh:'], placeholder = placeholders[cloned.length - 1];
124
- return Parser.run(() => {
126
+ return index_1.default.run(() => {
127
+ // @ts-expect-error abstract class
125
128
  const token = new ConverterRuleToken(placeholder, placeholder, this.getAttribute('config'));
126
129
  for (let i = 0; i < cloned.length; i++) {
127
130
  token.childNodes[i].safeReplaceWith(cloned[i]);
@@ -179,17 +182,17 @@ class ConverterRuleToken extends Token {
179
182
  * @throws `SyntaxError` 非法的转换目标
180
183
  */
181
184
  setTo(to) {
182
- const config = this.getAttribute('config'), include = this.getAttribute('include'), root = Parser.parse(`-{|${config.variants[0] ?? 'zh'}:${to}}-`, include, undefined, config), { length, firstChild: converter } = root;
185
+ const config = this.getAttribute('config'), include = this.getAttribute('include'), root = index_1.default.parse(`-{|${config.variants[0] ?? 'zh'}:${to}}-`, include, undefined, config), { length, firstChild: converter } = root;
183
186
  if (length !== 1 || converter.type !== 'converter') {
184
187
  throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
185
188
  }
186
189
  const { lastChild: converterRule } = converter;
187
- if (converter.length !== 2 || converterRule.length !== 2) {
188
- throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
190
+ if (converter.length === 2 && converterRule.length === 2) {
191
+ const { lastChild } = converterRule;
192
+ converterRule.destroy();
193
+ this.lastChild.safeReplaceWith(lastChild);
189
194
  }
190
- const { lastChild } = converterRule;
191
- converterRule.destroy();
192
- this.lastChild.safeReplaceWith(lastChild);
195
+ throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
193
196
  }
194
197
  /**
195
198
  * 设置语言变体
@@ -197,15 +200,12 @@ class ConverterRuleToken extends Token {
197
200
  * @throws `RangeError` 无效的语言变体
198
201
  */
199
202
  setVariant(variant) {
200
- if (typeof variant !== 'string') {
201
- this.typeError('setVariant', 'String');
202
- }
203
203
  const config = this.getAttribute('config'), v = variant.trim();
204
204
  if (!config.variants.includes(v)) {
205
205
  throw new RangeError(`无效的语言变体:${v}`);
206
206
  }
207
207
  else if (this.length === 1) {
208
- super.insertAt(Parser.run(() => new AtomToken(variant, 'converter-rule-variant', config)), 0);
208
+ super.insertAt(index_1.default.run(() => new atom_1.AtomToken(variant, 'converter-rule-variant', config)), 0);
209
209
  }
210
210
  else {
211
211
  this.childNodes.at(-2).setText(variant);
@@ -222,7 +222,7 @@ class ConverterRuleToken extends Token {
222
222
  if (!variant) {
223
223
  throw new Error('请先指定语言变体!');
224
224
  }
225
- const config = this.getAttribute('config'), root = Parser.parse(`-{|${from}=>${variant}:}-`, this.getAttribute('include'), undefined, config), { length, firstChild: converter } = root;
225
+ const config = this.getAttribute('config'), root = index_1.default.parse(`-{|${from}=>${variant}:}-`, this.getAttribute('include'), undefined, config), { length, firstChild: converter } = root;
226
226
  if (length !== 1 || converter.type !== 'converter') {
227
227
  throw new SyntaxError(`非法的转换原文:${(0, string_1.noWrap)(from)}`);
228
228
  }
@@ -251,5 +251,5 @@ class ConverterRuleToken extends Token {
251
251
  }
252
252
  }
253
253
  }
254
- Parser.classes['ConverterRuleToken'] = __filename;
255
- module.exports = ConverterRuleToken;
254
+ exports.ConverterRuleToken = ConverterRuleToken;
255
+ index_1.default.classes['ConverterRuleToken'] = __filename;
@@ -1,11 +1,10 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
3
- import MagicLinkToken = require('./magicLink');
1
+ import { Token } from '.';
2
+ import { MagicLinkToken } from './magicLink';
4
3
  /**
5
4
  * 外链
6
5
  * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
7
6
  */
8
- declare abstract class ExtLinkToken extends Token {
7
+ export declare abstract class ExtLinkToken extends Token {
9
8
  #private;
10
9
  /** @browser */
11
10
  readonly type = "ext-link";
@@ -29,7 +28,7 @@ declare abstract class ExtLinkToken extends Token {
29
28
  * @param space 空白字符
30
29
  * @param text 链接文字
31
30
  */
32
- constructor(url: string, space?: string, text?: string, config?: Parser.Config, accum?: Token[]);
31
+ constructor(url: string, space?: string, text?: string, config?: import("../index").Config, accum?: Token[]);
33
32
  /**
34
33
  * @override
35
34
  * @browser
@@ -62,4 +61,3 @@ declare abstract class ExtLinkToken extends Token {
62
61
  */
63
62
  setLinkText(str: string): void;
64
63
  }
65
- export = ExtLinkToken;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtLinkToken = void 0;
2
4
  const string_1 = require("../util/string");
3
- const Parser = require("../index");
4
- const Token = require(".");
5
- const MagicLinkToken = require("./magicLink");
5
+ const index_1 = require("../index");
6
+ const _1 = require(".");
7
+ const magicLink_1 = require("./magicLink");
6
8
  /**
7
9
  * 外链
8
10
  * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
9
11
  */
10
- class ExtLinkToken extends Token {
12
+ class ExtLinkToken extends _1.Token {
11
13
  /** @browser */
12
14
  type = 'ext-link';
13
15
  /** @browser */
@@ -38,18 +40,18 @@ class ExtLinkToken extends Token {
38
40
  * @param space 空白字符
39
41
  * @param text 链接文字
40
42
  */
41
- constructor(url, space = '', text = '', config = Parser.getConfig(), accum = []) {
43
+ constructor(url, space = '', text = '', config = index_1.default.getConfig(), accum = []) {
42
44
  super(undefined, config, true, accum, {
43
45
  MagicLinkToken: 0, Token: 1,
44
46
  });
45
- this.insertAt(new MagicLinkToken(url, true, config, accum));
47
+ this.insertAt(new magicLink_1.MagicLinkToken(url, true, config, accum));
46
48
  this.#space = space;
47
49
  if (text) {
48
- const inner = new Token(text, config, true, accum, {
50
+ const inner = new _1.Token(text, config, true, accum, {
49
51
  'Stage-7': ':', ConverterToken: ':',
50
52
  });
51
53
  inner.type = 'ext-link-text';
52
- this.insertAt(inner.setAttribute('stage', Parser.MAX_STAGE - 1));
54
+ this.insertAt(inner.setAttribute('stage', index_1.default.MAX_STAGE - 1));
53
55
  }
54
56
  this.protectChildren(0);
55
57
  }
@@ -81,21 +83,22 @@ class ExtLinkToken extends Token {
81
83
  return 1;
82
84
  }
83
85
  /** @private */
84
- getGaps() {
86
+ getGaps(i) {
85
87
  this.#correct();
86
- return this.#space.length;
88
+ return i === 0 ? this.#space.length : 0;
87
89
  }
88
90
  /**
89
91
  * @override
90
92
  * @browser
91
93
  */
92
94
  print() {
93
- return super.print(this.length > 1 ? { pre: '[', sep: this.#space, post: ']' } : { pre: '[', post: `${this.#space}]` });
95
+ return super.print(this.length === 1 ? { pre: '[', post: `${this.#space}]` } : { pre: '[', sep: this.#space, post: ']' });
94
96
  }
95
97
  /** @override */
96
98
  cloneNode() {
97
99
  const [url, text] = this.cloneChildNodes();
98
- return Parser.run(() => {
100
+ return index_1.default.run(() => {
101
+ // @ts-expect-error abstract class
99
102
  const token = new ExtLinkToken(undefined, '', '', this.getAttribute('config'));
100
103
  token.firstChild.safeReplaceWith(url);
101
104
  if (text) {
@@ -122,13 +125,13 @@ class ExtLinkToken extends Token {
122
125
  * @throws `SyntaxError` 非法的外链目标
123
126
  */
124
127
  setTarget(url) {
125
- const strUrl = String(url), root = Parser.parse(`[${strUrl}]`, this.getAttribute('include'), 8, this.getAttribute('config')), { length, firstChild: extLink } = root;
126
- if (length !== 1 || extLink.type !== 'ext-link' || extLink.length !== 1) {
127
- throw new SyntaxError(`非法的外链目标:${strUrl}`);
128
+ const strUrl = String(url), root = index_1.default.parse(`[${strUrl}]`, this.getAttribute('include'), 8, this.getAttribute('config')), { length, firstChild: extLink } = root;
129
+ if (length === 1 && extLink instanceof ExtLinkToken && extLink.length === 1) {
130
+ const { firstChild } = extLink;
131
+ extLink.destroy();
132
+ this.firstChild.safeReplaceWith(firstChild);
128
133
  }
129
- const { firstChild } = extLink;
130
- extLink.destroy();
131
- this.firstChild.safeReplaceWith(firstChild);
134
+ throw new SyntaxError(`非法的外链目标:${strUrl}`);
132
135
  }
133
136
  /**
134
137
  * 设置链接显示文字
@@ -136,8 +139,8 @@ class ExtLinkToken extends Token {
136
139
  * @throws `SyntaxError` 非法的链接显示文字
137
140
  */
138
141
  setLinkText(str) {
139
- const root = Parser.parse(`[//url ${str}]`, this.getAttribute('include'), 8, this.getAttribute('config')), { length, firstChild: extLink } = root;
140
- if (length !== 1 || extLink.type !== 'ext-link' || extLink.length !== 2) {
142
+ const root = index_1.default.parse(`[//url ${str}]`, this.getAttribute('include'), 8, this.getAttribute('config')), { length, firstChild: extLink } = root;
143
+ if (length !== 1 || !(extLink instanceof ExtLinkToken) || extLink.length !== 2) {
141
144
  throw new SyntaxError(`非法的外链文字:${(0, string_1.noWrap)(str)}`);
142
145
  }
143
146
  const { lastChild } = extLink;
@@ -150,5 +153,5 @@ class ExtLinkToken extends Token {
150
153
  this.#space ||= ' ';
151
154
  }
152
155
  }
153
- Parser.classes['ExtLinkToken'] = __filename;
154
- module.exports = ExtLinkToken;
156
+ exports.ExtLinkToken = ExtLinkToken;
157
+ index_1.default.classes['ExtLinkToken'] = __filename;
@@ -1,16 +1,13 @@
1
- import * as Parser from '../index';
2
- import AstText = require('../lib/text');
3
- import Token = require('.');
4
- import GalleryImageToken = require('./link/galleryImage');
5
- import HiddenToken = require('./hidden');
6
- import AttributesToken = require('./attributes');
7
- import ExtToken = require('./tagPair/ext');
8
- import type { AstNodeTypes } from '../lib/node';
1
+ import { Token } from '.';
2
+ import { GalleryImageToken } from './link/galleryImage';
3
+ import { HiddenToken } from './hidden';
4
+ import type { LintError } from '../index';
5
+ import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
9
6
  /**
10
7
  * gallery标签
11
8
  * @classdesc `{childNodes: ...(GalleryImageToken|HiddenToken|AstText)}`
12
9
  */
13
- declare abstract class GalleryToken extends Token {
10
+ export declare abstract class GalleryToken extends Token {
14
11
  /** @browser */
15
12
  readonly type = "ext-inner";
16
13
  childNodes: (GalleryImageToken | HiddenToken | AstText)[];
@@ -31,7 +28,7 @@ declare abstract class GalleryToken extends Token {
31
28
  * @browser
32
29
  * @param inner 标签内部wikitext
33
30
  */
34
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
31
+ constructor(inner?: string, config?: import("../index").Config, accum?: Token[]);
35
32
  /**
36
33
  * @override
37
34
  * @browser
@@ -51,7 +48,7 @@ declare abstract class GalleryToken extends Token {
51
48
  * @override
52
49
  * @browser
53
50
  */
54
- lint(start?: number): Parser.LintError[];
51
+ lint(start?: number): LintError[];
55
52
  /** @override */
56
53
  cloneNode(): this;
57
54
  /**
@@ -69,6 +66,5 @@ declare abstract class GalleryToken extends Token {
69
66
  */
70
67
  insertAt(token: string, i?: number): AstText;
71
68
  /** @ignore */
72
- insertAt<T extends AstNodeTypes>(token: T, i?: number): T;
69
+ insertAt<T extends AstNodes>(token: T, i?: number): T;
73
70
  }
74
- export = GalleryToken;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const Token = require(".");
4
- const GalleryImageToken = require("./link/galleryImage");
5
- const HiddenToken = require("./hidden");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GalleryToken = void 0;
4
+ const index_1 = require("../index");
5
+ const _1 = require(".");
6
+ const galleryImage_1 = require("./link/galleryImage");
7
+ const hidden_1 = require("./hidden");
6
8
  /**
7
9
  * gallery标签
8
10
  * @classdesc `{childNodes: ...(GalleryImageToken|HiddenToken|AstText)}`
9
11
  */
10
- class GalleryToken extends Token {
12
+ class GalleryToken extends _1.Token {
11
13
  /** @browser */
12
14
  type = 'ext-inner';
13
15
  /** 所有图片 */
@@ -18,7 +20,7 @@ class GalleryToken extends Token {
18
20
  * @browser
19
21
  * @param inner 标签内部wikitext
20
22
  */
21
- constructor(inner, config = Parser.getConfig(), accum = []) {
23
+ constructor(inner, config = index_1.default.getConfig(), accum = []) {
22
24
  super(undefined, config, true, accum, {
23
25
  AstText: ':', GalleryImageToken: ':', HiddenToken: ':',
24
26
  });
@@ -26,7 +28,7 @@ class GalleryToken extends Token {
26
28
  const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
27
29
  if (!matches) {
28
30
  super.insertAt((line.trim()
29
- ? new HiddenToken(line, config, [], {
31
+ ? new hidden_1.HiddenToken(line, config, [], {
30
32
  AstText: ':',
31
33
  })
32
34
  : line));
@@ -34,10 +36,11 @@ class GalleryToken extends Token {
34
36
  }
35
37
  const [, file, alt] = matches, title = this.normalizeTitle(file, 6, true, true);
36
38
  if (title.valid) {
37
- super.insertAt(new GalleryImageToken('gallery', file, alt, config, accum));
39
+ // @ts-expect-error abstract class
40
+ super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
38
41
  }
39
42
  else {
40
- super.insertAt(new HiddenToken(line, config, [], {
43
+ super.insertAt(new hidden_1.HiddenToken(line, config, [], {
41
44
  AstText: ':',
42
45
  }));
43
46
  }
@@ -58,8 +61,8 @@ class GalleryToken extends Token {
58
61
  return super.text('\n').replace(/\n\s*\n/gu, '\n');
59
62
  }
60
63
  /** @private */
61
- getGaps() {
62
- return 1;
64
+ getGaps(i) {
65
+ return i < this.length - 1 ? 1 : 0;
63
66
  }
64
67
  /**
65
68
  * @override
@@ -74,14 +77,14 @@ class GalleryToken extends Token {
74
77
  */
75
78
  lint(start = this.getAbsoluteIndex()) {
76
79
  const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
77
- for (let i = 0, startIndex = start; i < this.length; i++) {
80
+ for (let i = 0; i < this.length; i++) {
78
81
  const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
79
82
  if (child.type === 'hidden' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
80
83
  errors.push({
81
- message: Parser.msg('invalid content in <$1>', 'gallery'),
84
+ message: index_1.default.msg('invalid content in <$1>', 'gallery'),
82
85
  severity: 'error',
83
- startIndex,
84
- endIndex: startIndex + length,
86
+ startIndex: start,
87
+ endIndex: start + length,
85
88
  startLine,
86
89
  endLine: startLine,
87
90
  startCol,
@@ -90,16 +93,17 @@ class GalleryToken extends Token {
90
93
  });
91
94
  }
92
95
  else if (child.type !== 'hidden' && child.type !== 'text') {
93
- errors.push(...child.lint(startIndex));
96
+ errors.push(...child.lint(start));
94
97
  }
95
- startIndex += length + 1;
98
+ start += length + 1;
96
99
  }
97
100
  return errors;
98
101
  }
99
102
  /** @override */
100
103
  cloneNode() {
101
104
  const cloned = this.cloneChildNodes();
102
- return Parser.run(() => {
105
+ return index_1.default.run(() => {
106
+ // @ts-expect-error abstract class
103
107
  const token = new GalleryToken(undefined, this.getAttribute('config'));
104
108
  token.append(...cloned);
105
109
  return token;
@@ -114,19 +118,20 @@ class GalleryToken extends Token {
114
118
  insertImage(file, i = this.length) {
115
119
  const title = this.normalizeTitle(file, 6, true, true);
116
120
  if (title.valid) {
117
- const token = Parser.run(
118
- () => new GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
121
+ const token = index_1.default.run(
122
+ // @ts-expect-error abstract class
123
+ () => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
119
124
  return this.insertAt(token, i);
120
125
  }
121
126
  throw new SyntaxError(`非法的文件名:${file}`);
122
127
  }
123
128
  /** @ignore */
124
129
  insertAt(token, i = 0) {
125
- if (typeof token === 'string' && token.trim() || token instanceof HiddenToken) {
130
+ if (typeof token === 'string' && token.trim() || token instanceof hidden_1.HiddenToken) {
126
131
  throw new RangeError('请勿向图库中插入不可见内容!');
127
132
  }
128
133
  return super.insertAt(token, i);
129
134
  }
130
135
  }
131
- Parser.classes['GalleryToken'] = __filename;
132
- module.exports = GalleryToken;
136
+ exports.GalleryToken = GalleryToken;
137
+ index_1.default.classes['GalleryToken'] = __filename;
@@ -1,18 +1,18 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
3
- import SyntaxToken = require('./syntax');
1
+ import { Token } from '.';
2
+ import { SyntaxToken } from './syntax';
3
+ import type { LintError } from '../index';
4
4
  declare const HeadingToken_base: (abstract new (...args: any[]) => {
5
- "__#14@#isRoot"(): boolean;
5
+ "__#7@#isRoot"(): boolean;
6
6
  prependNewLine(): string;
7
- toString(selector?: string | undefined): string; /** 内部wikitext */
7
+ toString(selector?: string | undefined): string;
8
8
  getPadding(): number;
9
9
  text(): string;
10
10
  length: number;
11
11
  insertAt(token: unknown, i?: number | undefined): unknown;
12
12
  }) & ((abstract new (...args: any[]) => {
13
13
  removeAt(): never;
14
- insertAt(token: string, i?: number | undefined): import("../lib/text");
15
- insertAt<T extends import("../lib/node").AstNodeTypes>(token: T, i?: number | undefined): T;
14
+ insertAt(token: string, i?: number | undefined): import("../index").AstText;
15
+ insertAt<T extends import("../index").AstNodes>(token: T, i?: number | undefined): T;
16
16
  length: number;
17
17
  toString(selector?: string | undefined, separator?: string | undefined): string;
18
18
  text(separator?: string | undefined): string;
@@ -23,7 +23,7 @@ declare const HeadingToken_base: (abstract new (...args: any[]) => {
23
23
  * 章节标题
24
24
  * @classdesc `{childNodes: [Token, SyntaxToken]}`
25
25
  */
26
- declare abstract class HeadingToken extends HeadingToken_base {
26
+ export declare abstract class HeadingToken extends HeadingToken_base {
27
27
  #private;
28
28
  /** @browser */
29
29
  readonly type = "heading";
@@ -48,7 +48,7 @@ declare abstract class HeadingToken extends HeadingToken_base {
48
48
  * @param level 标题层级
49
49
  * @param input 标题文字
50
50
  */
51
- constructor(level: number, input: string[], config?: Parser.Config, accum?: Token[]);
51
+ constructor(level: number, input: string[], config?: import("../index").Config, accum?: Token[]);
52
52
  /**
53
53
  * @override
54
54
  * @browser
@@ -68,7 +68,7 @@ declare abstract class HeadingToken extends HeadingToken_base {
68
68
  * @override
69
69
  * @browser
70
70
  */
71
- lint(start?: number): Parser.LintError[];
71
+ lint(start?: number): LintError[];
72
72
  /** @override */
73
73
  cloneNode(): this;
74
74
  /**
@@ -79,4 +79,4 @@ declare abstract class HeadingToken extends HeadingToken_base {
79
79
  /** 移除标题后的不可见内容 */
80
80
  removeTrail(): void;
81
81
  }
82
- export = HeadingToken;
82
+ export {};