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,11 +1,13 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrBaseToken = void 0;
2
4
  const lint_1 = require("../../util/lint");
3
- const Parser = require("../../index");
4
- const Token = require("..");
5
- const TableBaseToken = require("./base");
6
- const TdToken = require("./td");
5
+ const index_1 = require("../../index");
6
+ const __1 = require("..");
7
+ const base_1 = require("./base");
8
+ const td_1 = require("./td");
7
9
  /** 表格行或表格 */
8
- class TrBaseToken extends TableBaseToken {
10
+ class TrBaseToken extends base_1.TableBaseToken {
9
11
  /**
10
12
  * @override
11
13
  * @browser
@@ -51,7 +53,7 @@ class TrBaseToken extends TableBaseToken {
51
53
  /** 修复简单的表格语法错误 */
52
54
  #correct() {
53
55
  const { childNodes: [, , child] } = this;
54
- if (child?.constructor === Token) {
56
+ if (child?.constructor === __1.Token) {
55
57
  const { firstChild } = child;
56
58
  if (firstChild?.type !== 'text') {
57
59
  child.prepend('\n');
@@ -72,7 +74,7 @@ class TrBaseToken extends TableBaseToken {
72
74
  */
73
75
  removeAt(i) {
74
76
  const child = this.childNodes.at(i);
75
- if (child instanceof TdToken && child.isIndependent()) {
77
+ if (child instanceof td_1.TdToken && child.isIndependent()) {
76
78
  const { nextSibling } = child;
77
79
  if (nextSibling?.type === 'td') {
78
80
  nextSibling.independence();
@@ -86,24 +88,29 @@ class TrBaseToken extends TableBaseToken {
86
88
  * @param i 插入位置
87
89
  */
88
90
  insertAt(token, i = this.length) {
89
- if (!Parser.running && !(token instanceof TrBaseToken)) {
90
- this.typeError('insertAt', 'TrToken');
91
+ if (!index_1.default.running && token.type !== 'td') {
92
+ if (this.type === 'tr') {
93
+ this.typeError('insertAt', 'TdToken');
94
+ }
95
+ else if (token.type !== 'tr') {
96
+ this.typeError('insertAt', 'TrToken', 'TdToken');
97
+ }
91
98
  }
92
99
  const child = this.childNodes.at(i);
93
- if (token instanceof TdToken && token.isIndependent() && child instanceof TdToken) {
100
+ if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
94
101
  child.independence();
95
102
  }
96
103
  return super.insertAt(token, i);
97
104
  }
98
105
  /** 获取行数 */
99
106
  getRowCount() {
100
- return Number(this.childNodes.some(child => child instanceof TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
107
+ return Number(this.childNodes.some(child => child instanceof td_1.TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
101
108
  }
102
109
  /** 获取列数 */
103
110
  getColCount() {
104
111
  let count = 0, last = 0;
105
112
  for (const child of this.childNodes) {
106
- if (child instanceof TdToken) {
113
+ if (child instanceof td_1.TdToken) {
107
114
  last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
108
115
  count += last;
109
116
  }
@@ -112,9 +119,6 @@ class TrBaseToken extends TableBaseToken {
112
119
  }
113
120
  /** @ignore */
114
121
  getNthCol(n, insert = false) {
115
- if (!Number.isInteger(n)) {
116
- this.typeError('getNthCol', 'Number');
117
- }
118
122
  const nCols = this.getColCount();
119
123
  let m = n < 0 ? n + nCols : n;
120
124
  if (m < 0 || m > nCols || m === nCols && !insert) {
@@ -122,7 +126,7 @@ class TrBaseToken extends TableBaseToken {
122
126
  }
123
127
  let last = 0;
124
128
  for (const child of this.childNodes.slice(2)) {
125
- if (child instanceof TdToken) {
129
+ if (child instanceof td_1.TdToken) {
126
130
  if (child.isIndependent()) {
127
131
  last = Number(child.subtype !== 'caption');
128
132
  }
@@ -145,9 +149,9 @@ class TrBaseToken extends TableBaseToken {
145
149
  * @param attr 单元格属性
146
150
  */
147
151
  insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
148
- const token = TdToken.create(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
152
+ const token = td_1.TdToken.create(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
149
153
  return this.insertBefore(token, this.getNthCol(column, true));
150
154
  }
151
155
  }
152
- Parser.classes['TrBaseToken'] = __filename;
153
- module.exports = TrBaseToken;
156
+ exports.TrBaseToken = TrBaseToken;
157
+ index_1.default.classes['TrBaseToken'] = __filename;
@@ -1,10 +1,10 @@
1
- import * as Parser from '../../index';
2
- import Token = require('..');
3
- import TagPairToken = require('.');
4
- import AttributesToken = require('../attributes');
1
+ import { Token } from '..';
2
+ import { TagPairToken } from '.';
3
+ import { AttributesToken } from '../attributes';
4
+ import type { LintError, Config } from '../../index';
5
5
  declare const ExtToken_base: (abstract new (...args: any[]) => {
6
- childNodes: import("../../lib/node").AstNodeTypes[];
7
- readonly "__#12@#attributesChild": AttributesToken;
6
+ childNodes: import("../../index").AstNodes[];
7
+ readonly "__#4@#attributesChild": AttributesToken;
8
8
  readonly attributes: Record<string, string | true>;
9
9
  className: string;
10
10
  readonly classList: Set<string>;
@@ -26,7 +26,7 @@ declare const ExtToken_base: (abstract new (...args: any[]) => {
26
26
  * 扩展标签
27
27
  * @classdesc `{childNodes: [AttributesToken, Token]}`
28
28
  */
29
- declare abstract class ExtToken extends ExtToken_base {
29
+ export declare abstract class ExtToken extends ExtToken_base {
30
30
  readonly type = "ext";
31
31
  childNodes: [AttributesToken, Token];
32
32
  abstract get children(): [AttributesToken, Token];
@@ -42,13 +42,13 @@ declare abstract class ExtToken extends ExtToken_base {
42
42
  * @param inner 内部wikitext
43
43
  * @param closed 是否封闭
44
44
  */
45
- constructor(name: string, attr?: string, inner?: string, closed?: string | undefined, config?: Parser.Config, accum?: Token[]);
45
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Config, accum?: Token[]);
46
46
  /**
47
47
  * @override
48
48
  * @browser
49
49
  */
50
- lint(start?: number): Parser.LintError[];
50
+ lint(start?: number): LintError[];
51
51
  /** @override */
52
52
  cloneNode(): this;
53
53
  }
54
- export = ExtToken;
54
+ export {};
@@ -1,18 +1,30 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtToken = void 0;
2
4
  const lint_1 = require("../../util/lint");
3
- const base_1 = require("../../util/base");
4
- const attributesParent = require("../../mixin/attributesParent");
5
- const Parser = require("../../index");
6
- const Token = require("..");
7
- const TagPairToken = require(".");
8
- const AttributesToken = require("../attributes");
5
+ const attributesParent_1 = require("../../mixin/attributesParent");
6
+ const index_1 = require("../../index");
7
+ const __1 = require("..");
8
+ const _1 = require(".");
9
+ const attributes_1 = require("../attributes");
10
+ /**
11
+ * 从数组中删除指定元素
12
+ * @param arr 数组
13
+ * @param ele 元素
14
+ */
15
+ const del = (arr, ele) => {
16
+ const set = new Set(arr);
17
+ set.delete(ele);
18
+ return [...set];
19
+ };
9
20
  /**
10
21
  * 扩展标签
11
22
  * @classdesc `{childNodes: [AttributesToken, Token]}`
12
23
  */
13
- class ExtToken extends attributesParent(TagPairToken) {
24
+ class ExtToken extends (0, attributesParent_1.attributesParent)(_1.TagPairToken) {
14
25
  type = 'ext';
15
26
  /** @override */
27
+ // eslint-disable-next-line class-methods-use-this
16
28
  get closed() {
17
29
  return true;
18
30
  }
@@ -23,13 +35,14 @@ class ExtToken extends attributesParent(TagPairToken) {
23
35
  * @param inner 内部wikitext
24
36
  * @param closed 是否封闭
25
37
  */
26
- constructor(name, attr = '', inner = '', closed = undefined, config = Parser.getConfig(), accum = []) {
38
+ constructor(name, attr = '', inner = '', closed, config = index_1.default.getConfig(), accum = []) {
27
39
  const lcName = name.toLowerCase(),
28
- attrToken = new AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: (0, base_1.del)(config.ext, lcName), excludes: [...config.excludes ?? []] };
40
+ // @ts-expect-error abstract class
41
+ attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
29
42
  let innerToken;
30
43
  switch (lcName) {
31
44
  case 'tab':
32
- newConfig.ext = (0, base_1.del)(newConfig.ext, 'tabs');
45
+ newConfig.ext = del(newConfig.ext, 'tabs');
33
46
  // fall through
34
47
  case 'indicator':
35
48
  case 'poem':
@@ -42,59 +55,68 @@ class ExtToken extends attributesParent(TagPairToken) {
42
55
  if (lcName === 'poem') {
43
56
  newConfig.excludes.push('heading');
44
57
  }
45
- innerToken = new Token(inner, newConfig, true, accum);
58
+ innerToken = new __1.Token(inner, newConfig, true, accum);
46
59
  break;
47
60
  case 'pre': {
48
- const PreToken = require('../pre');
61
+ const { PreToken } = require('../pre');
62
+ // @ts-expect-error abstract class
49
63
  innerToken = new PreToken(inner, newConfig, accum);
50
64
  break;
51
65
  }
52
66
  case 'dynamicpagelist': {
53
- const ParamTagToken = require('../paramTag');
67
+ const { ParamTagToken } = require('../paramTag');
68
+ // @ts-expect-error abstract class
54
69
  innerToken = new ParamTagToken(inner, newConfig, accum);
55
70
  break;
56
71
  }
57
72
  case 'inputbox': {
58
73
  newConfig.excludes.push('heading');
59
- const InputboxToken = require('../paramTag/inputbox');
74
+ const { InputboxToken } = require('../paramTag/inputbox');
75
+ // @ts-expect-error abstract class
60
76
  innerToken = new InputboxToken(inner, newConfig, accum);
61
77
  break;
62
78
  }
63
79
  case 'references': {
64
- const NestedToken = require('../nested');
80
+ const { NestedToken } = require('../nested');
81
+ // @ts-expect-error abstract class
65
82
  innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], newConfig, accum);
66
83
  break;
67
84
  }
68
85
  case 'choose': {
69
- const NestedToken = require('../nested');
86
+ const { NestedToken } = require('../nested');
87
+ // @ts-expect-error abstract class
70
88
  innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu, ['option', 'choicetemplate'], newConfig, accum);
71
89
  break;
72
90
  }
73
91
  case 'combobox': {
74
- const NestedToken = require('../nested');
92
+ const { NestedToken } = require('../nested');
93
+ // @ts-expect-error abstract class
75
94
  innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], newConfig, accum);
76
95
  break;
77
96
  }
78
97
  case 'gallery': {
79
- const GalleryToken = require('../gallery');
98
+ const { GalleryToken } = require('../gallery');
99
+ // @ts-expect-error abstract class
80
100
  innerToken = new GalleryToken(inner, newConfig, accum);
81
101
  break;
82
102
  }
83
103
  case 'imagemap': {
84
- const ImagemapToken = require('../imagemap');
104
+ const { ImagemapToken } = require('../imagemap');
105
+ // @ts-expect-error abstract class
85
106
  innerToken = new ImagemapToken(inner, newConfig, accum);
86
107
  break;
87
108
  }
88
109
  // 更多定制扩展的代码示例:
89
110
  // ```
90
111
  // case 'extensionName': {
91
- // const ExtensionToken: typeof import('../extension') = require('../extension');
112
+ // const {ExtensionToken}: typeof import('../extension') = require('../extension');
92
113
  // innerToken = new ExtensionToken(inner, newConfig, accum);
93
114
  // break;
94
115
  // }
95
116
  // ```
96
117
  default: {
97
- const NowikiToken = require('../nowiki');
118
+ const { NowikiToken } = require('../nowiki');
119
+ // @ts-expect-error abstract class
98
120
  innerToken = new NowikiToken(inner, newConfig);
99
121
  }
100
122
  }
@@ -116,12 +138,13 @@ class ExtToken extends attributesParent(TagPairToken) {
116
138
  /** @override */
117
139
  cloneNode() {
118
140
  const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = String(this.firstChild);
119
- return Parser.run(() => {
141
+ return index_1.default.run(() => {
142
+ // @ts-expect-error abstract class
120
143
  const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
121
144
  token.lastChild.safeReplaceWith(inner);
122
145
  return token;
123
146
  });
124
147
  }
125
148
  }
126
- Parser.classes['ExtToken'] = __filename;
127
- module.exports = ExtToken;
149
+ exports.ExtToken = ExtToken;
150
+ index_1.default.classes['ExtToken'] = __filename;
@@ -1,9 +1,8 @@
1
- import * as Parser from '../../index';
2
- import TagPairToken = require('.');
3
- import Token = require('..');
4
- import AstText = require('../../lib/text');
1
+ import { TagPairToken } from '.';
2
+ import type { AstText, Token } from '../../internal';
5
3
  declare const IncludeToken_base: ((abstract new (...args: any[]) => {
6
4
  text(): string;
5
+ /** @browser */
7
6
  length: number;
8
7
  toString(selector?: string | undefined, separator?: string | undefined): string;
9
8
  insertAt(token: unknown, i?: number | undefined): unknown;
@@ -14,7 +13,7 @@ declare const IncludeToken_base: ((abstract new (...args: any[]) => {
14
13
  * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
15
14
  * @classdesc `{childNodes: [AstText, AstText]}`
16
15
  */
17
- declare abstract class IncludeToken extends IncludeToken_base {
16
+ export declare abstract class IncludeToken extends IncludeToken_base {
18
17
  /** @browser */
19
18
  readonly type = "include";
20
19
  childNodes: [AstText, AstText];
@@ -30,7 +29,7 @@ declare abstract class IncludeToken extends IncludeToken_base {
30
29
  * @param inner 内部wikitext
31
30
  * @param closed 是否封闭
32
31
  */
33
- constructor(name: string, attr?: string, inner?: string | undefined, closed?: string | undefined, config?: Parser.Config, accum?: Token[]);
32
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: import("../../index").Config, accum?: Token[]);
34
33
  /** @override */
35
34
  cloneNode(): this;
36
35
  /**
@@ -41,4 +40,4 @@ declare abstract class IncludeToken extends IncludeToken_base {
41
40
  /** 清除标签属性 */
42
41
  removeAttr(): void;
43
42
  }
44
- export = IncludeToken;
43
+ export {};
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
- const hidden = require("../../mixin/hidden");
3
- const Parser = require("../../index");
4
- const TagPairToken = require(".");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IncludeToken = void 0;
4
+ const hidden_1 = require("../../mixin/hidden");
5
+ const index_1 = require("../../index");
6
+ const _1 = require(".");
5
7
  /**
6
8
  * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
7
9
  * @classdesc `{childNodes: [AstText, AstText]}`
8
10
  */
9
- class IncludeToken extends hidden(TagPairToken) {
11
+ class IncludeToken extends (0, hidden_1.hidden)(_1.TagPairToken) {
10
12
  /** @browser */
11
13
  type = 'include';
12
14
  /**
@@ -16,13 +18,14 @@ class IncludeToken extends hidden(TagPairToken) {
16
18
  * @param inner 内部wikitext
17
19
  * @param closed 是否封闭
18
20
  */
19
- constructor(name, attr = '', inner = undefined, closed = undefined, config = Parser.getConfig(), accum = []) {
21
+ constructor(name, attr = '', inner, closed, config = index_1.default.getConfig(), accum = []) {
20
22
  super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
21
23
  }
22
24
  /** @override */
23
25
  cloneNode() {
24
26
  const tags = this.getAttribute('tags'), config = this.getAttribute('config'), inner = this.selfClosing ? undefined : this.lastChild.data, closing = this.selfClosing || !this.closed ? undefined : tags[1];
25
- return Parser.run(() => new IncludeToken(tags[0], this.firstChild.data, inner, closing, config));
27
+ // @ts-expect-error abstract class
28
+ return index_1.default.run(() => new IncludeToken(tags[0], this.firstChild.data, inner, closing, config));
26
29
  }
27
30
  /**
28
31
  * @override
@@ -36,5 +39,5 @@ class IncludeToken extends hidden(TagPairToken) {
36
39
  super.setText('');
37
40
  }
38
41
  }
39
- Parser.classes['IncludeToken'] = __filename;
40
- module.exports = IncludeToken;
42
+ exports.IncludeToken = IncludeToken;
43
+ index_1.default.classes['IncludeToken'] = __filename;
@@ -1,23 +1,24 @@
1
- import * as Parser from '../../index';
2
- import Token = require('..');
3
- import type { AstNodeTypes, TokenAttributeGetter } from '../../lib/node';
1
+ import { Token } from '..';
2
+ import type { AstNodes } from '../../lib/node';
4
3
  declare const TagPairToken_base: ((abstract new (...args: any[]) => {
5
4
  removeAt(): never;
6
- insertAt(token: string, i?: number | undefined): import("../../lib/text");
7
- insertAt<T extends AstNodeTypes>(token: T, i?: number | undefined): T;
5
+ insertAt(token: string, i?: number | undefined): import("../../index").AstText;
6
+ insertAt<T extends AstNodes>(token: T, i?: number | undefined): T;
8
7
  length: number;
9
8
  toString(selector?: string | undefined, separator?: string | undefined): string;
9
+ /** @browser */
10
10
  text(separator?: string | undefined): string;
11
11
  }) & {
12
- readonly fixed: true; /** @browser */
12
+ readonly fixed: true;
13
13
  }) & typeof Token;
14
14
  /** 成对标签 */
15
- declare abstract class TagPairToken extends TagPairToken_base {
15
+ export declare abstract class TagPairToken extends TagPairToken_base {
16
16
  #private;
17
17
  type: 'ext' | 'include';
18
18
  name: string;
19
- abstract get firstChild(): AstNodeTypes;
20
- abstract get lastChild(): AstNodeTypes;
19
+ childNodes: [AstNodes, AstNodes];
20
+ abstract get firstChild(): AstNodes;
21
+ abstract get lastChild(): AstNodes;
21
22
  /**
22
23
  * 是否闭合
23
24
  * @browser
@@ -36,7 +37,7 @@ declare abstract class TagPairToken extends TagPairToken_base {
36
37
  * @param inner 内部wikitext
37
38
  * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
38
39
  */
39
- constructor(name: string, attr: string | Token, inner: string | Token, closed: string | undefined, config?: Parser.Config, accum?: Token[]);
40
+ constructor(name: string, attr: string | Token, inner: string | Token, closed?: string, config?: import("../../index").Config, accum?: Token[]);
40
41
  /**
41
42
  * @override
42
43
  * @browser
@@ -53,4 +54,4 @@ declare abstract class TagPairToken extends TagPairToken_base {
53
54
  */
54
55
  print(): string;
55
56
  }
56
- export = TagPairToken;
57
+ export {};
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
- const Parser = require("../../index");
3
- const fixed = require("../../mixin/fixed");
4
- const Token = require("..");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TagPairToken = void 0;
4
+ const fixed_1 = require("../../mixin/fixed");
5
+ const index_1 = require("../../index");
6
+ const __1 = require("..");
5
7
  /** 成对标签 */
6
- class TagPairToken extends fixed(Token) {
8
+ class TagPairToken extends (0, fixed_1.fixed)(__1.Token) {
7
9
  /** @browser */
8
10
  #selfClosing;
9
11
  /** @browser */
@@ -26,7 +28,7 @@ class TagPairToken extends fixed(Token) {
26
28
  }
27
29
  set selfClosing(value) {
28
30
  if (value !== this.#selfClosing && this.lastChild.text()) {
29
- Parser.warn(`<${this.name}>标签内部的${value ? '文本将被隐藏' : '原有文本将再次可见'}!`);
31
+ index_1.default.warn(`<${this.name}>标签内部的${value ? '文本将被隐藏' : '原有文本将再次可见'}!`);
30
32
  }
31
33
  this.#selfClosing = value;
32
34
  }
@@ -41,7 +43,7 @@ class TagPairToken extends fixed(Token) {
41
43
  * @param inner 内部wikitext
42
44
  * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
43
45
  */
44
- constructor(name, attr, inner, closed, config = Parser.getConfig(), accum = []) {
46
+ constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
45
47
  super(undefined, config, true);
46
48
  this.setAttribute('name', name.toLowerCase());
47
49
  this.#tags = [name, closed || name];
@@ -67,7 +69,7 @@ class TagPairToken extends fixed(Token) {
67
69
  return '';
68
70
  }
69
71
  else if (!this.closed && nextSibling) {
70
- Parser.error(`自动闭合 <${name}>`, lastChild);
72
+ index_1.default.error(`自动闭合 <${name}>`, lastChild);
71
73
  this.#closed = true;
72
74
  }
73
75
  return this.#selfClosing
@@ -89,8 +91,8 @@ class TagPairToken extends fixed(Token) {
89
91
  return this.#tags[0].length + 1;
90
92
  }
91
93
  /** @private */
92
- getGaps() {
93
- return 1;
94
+ getGaps(i) {
95
+ return i === 0 ? 1 : 1;
94
96
  }
95
97
  /**
96
98
  * @override
@@ -107,5 +109,5 @@ class TagPairToken extends fixed(Token) {
107
109
  return key === 'tags' ? [...this.#tags] : super.getAttribute(key);
108
110
  }
109
111
  }
110
- Parser.classes['TagPairToken'] = __filename;
111
- module.exports = TagPairToken;
112
+ exports.TagPairToken = TagPairToken;
113
+ index_1.default.classes['TagPairToken'] = __filename;
@@ -1,14 +1,13 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
3
- import ParameterToken = require('./parameter');
4
- import AtomToken = require('./atom');
5
- import SyntaxToken = require('./syntax');
6
- import type { TokenAttributeGetter } from '../lib/node';
1
+ import { Token } from '.';
2
+ import { ParameterToken } from './parameter';
3
+ import { AtomToken } from './atom';
4
+ import { SyntaxToken } from './syntax';
5
+ import type { LintError } from '../index';
7
6
  /**
8
7
  * 模板或魔术字
9
8
  * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
10
9
  */
11
- declare abstract class TranscludeToken extends Token {
10
+ export declare abstract class TranscludeToken extends Token {
12
11
  #private;
13
12
  /** @browser */
14
13
  type: 'template' | 'magic-word';
@@ -28,7 +27,7 @@ declare abstract class TranscludeToken extends Token {
28
27
  * @param parts 参数各部分
29
28
  * @throws `SyntaxError` 非法的模板名称
30
29
  */
31
- constructor(title: string, parts: ([string] | [string | number, string])[], config?: Parser.Config, accum?: Token[]);
30
+ constructor(title: string, parts: ([string] | [string | number, string])[], config?: import("../index").Config, accum?: Token[]);
32
31
  /**
33
32
  * 设置引用修饰符
34
33
  * @browser
@@ -59,7 +58,7 @@ declare abstract class TranscludeToken extends Token {
59
58
  * @override
60
59
  * @browser
61
60
  */
62
- lint(start?: number): Parser.LintError[];
61
+ lint(start?: number): LintError[];
63
62
  /**
64
63
  * @override
65
64
  * @browser
@@ -199,4 +198,3 @@ declare abstract class TranscludeToken extends Token {
199
198
  */
200
199
  escapeTables(): TranscludeToken;
201
200
  }
202
- export = TranscludeToken;