wikiparser-node 0.10.0 → 0.11.0-m

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 (155) hide show
  1. package/README.md +44 -32
  2. package/config/.schema.json +1 -8
  3. package/config/default.json +1 -2
  4. package/config/llwiki.json +1 -36
  5. package/config/moegirl.json +1 -45
  6. package/config/zhwiki.json +1 -467
  7. package/dist/index.d.ts +110 -0
  8. package/dist/lib/element.d.ts +48 -0
  9. package/dist/lib/node.d.ts +108 -0
  10. package/dist/lib/text.d.ts +30 -0
  11. package/dist/lib/title.d.ts +15 -0
  12. package/dist/mixin/hidden.d.ts +8 -0
  13. package/dist/parser/brackets.d.ts +12 -0
  14. package/dist/parser/commentAndExt.d.ts +8 -0
  15. package/dist/parser/converter.d.ts +7 -0
  16. package/dist/parser/externalLinks.d.ts +7 -0
  17. package/dist/parser/hrAndDoubleUnderscore.d.ts +11 -0
  18. package/dist/parser/html.d.ts +7 -0
  19. package/dist/parser/links.d.ts +7 -0
  20. package/dist/parser/list.d.ts +7 -0
  21. package/dist/parser/magicLinks.d.ts +7 -0
  22. package/dist/parser/quotes.d.ts +7 -0
  23. package/dist/parser/table.d.ts +11 -0
  24. package/dist/src/arg.d.ts +25 -0
  25. package/dist/src/atom/hidden.d.ts +5 -0
  26. package/dist/src/atom/index.d.ts +14 -0
  27. package/dist/src/attribute.d.ts +42 -0
  28. package/dist/src/attributes.d.ts +33 -0
  29. package/dist/src/converter.d.ts +29 -0
  30. package/dist/src/converterFlags.d.ts +27 -0
  31. package/dist/src/converterRule.d.ts +29 -0
  32. package/dist/src/extLink.d.ts +22 -0
  33. package/dist/src/gallery.d.ts +19 -0
  34. package/dist/src/hasNowiki/index.d.ts +14 -0
  35. package/dist/src/hasNowiki/pre.d.ts +13 -0
  36. package/dist/src/heading.d.ts +24 -0
  37. package/dist/src/html.d.ts +33 -0
  38. package/dist/src/imageParameter.d.ts +23 -0
  39. package/dist/src/imagemap.d.ts +26 -0
  40. package/dist/src/imagemapLink.d.ts +16 -0
  41. package/dist/src/index.d.ts +53 -0
  42. package/dist/src/link/category.d.ts +8 -0
  43. package/dist/src/link/file.d.ts +27 -0
  44. package/dist/src/link/galleryImage.d.ts +15 -0
  45. package/dist/src/link/index.d.ts +29 -0
  46. package/dist/src/magicLink.d.ts +14 -0
  47. package/dist/src/nested/choose.d.ts +13 -0
  48. package/dist/src/nested/combobox.d.ts +13 -0
  49. package/dist/src/nested/index.d.ts +20 -0
  50. package/dist/src/nested/references.d.ts +13 -0
  51. package/dist/src/nowiki/comment.d.ts +19 -0
  52. package/dist/src/nowiki/dd.d.ts +8 -0
  53. package/dist/src/nowiki/doubleUnderscore.d.ts +12 -0
  54. package/dist/src/nowiki/hr.d.ts +13 -0
  55. package/dist/src/nowiki/index.d.ts +18 -0
  56. package/dist/src/nowiki/list.d.ts +8 -0
  57. package/dist/src/nowiki/noinclude.d.ts +8 -0
  58. package/dist/src/nowiki/quote.d.ts +20 -0
  59. package/dist/src/onlyinclude.d.ts +17 -0
  60. package/dist/src/paramTag/index.d.ts +24 -0
  61. package/dist/src/paramTag/inputbox.d.ts +8 -0
  62. package/dist/src/parameter.d.ts +28 -0
  63. package/dist/src/syntax.d.ts +15 -0
  64. package/dist/src/table/index.d.ts +16 -0
  65. package/dist/src/table/td.d.ts +39 -0
  66. package/dist/src/table/tr.d.ts +17 -0
  67. package/dist/src/tagPair/ext.d.ts +17 -0
  68. package/dist/src/tagPair/include.d.ts +16 -0
  69. package/dist/src/tagPair/index.d.ts +28 -0
  70. package/dist/src/transclude.d.ts +75 -0
  71. package/dist/util/lint.d.ts +28 -0
  72. package/dist/util/string.d.ts +31 -0
  73. package/i18n/zh-hans.json +1 -1
  74. package/i18n/zh-hant.json +1 -1
  75. package/index.js +5 -257
  76. package/lib/element.js +7 -482
  77. package/lib/node.js +11 -540
  78. package/lib/text.js +3 -96
  79. package/lib/title.js +1 -28
  80. package/mixin/hidden.js +0 -3
  81. package/package.json +11 -5
  82. package/parser/brackets.js +3 -2
  83. package/parser/commentAndExt.js +8 -6
  84. package/parser/converter.js +1 -2
  85. package/parser/externalLinks.js +1 -2
  86. package/parser/hrAndDoubleUnderscore.js +1 -2
  87. package/parser/html.js +1 -2
  88. package/parser/links.js +5 -6
  89. package/parser/list.js +1 -2
  90. package/parser/magicLinks.js +1 -2
  91. package/parser/quotes.js +1 -2
  92. package/parser/table.js +1 -2
  93. package/src/arg.js +4 -118
  94. package/src/atom/hidden.js +0 -2
  95. package/src/atom/index.js +1 -18
  96. package/src/attribute.js +6 -190
  97. package/src/attributes.js +5 -308
  98. package/src/converter.js +3 -109
  99. package/src/converterFlags.js +1 -188
  100. package/src/converterRule.js +2 -184
  101. package/src/extLink.js +2 -122
  102. package/src/gallery.js +2 -56
  103. package/src/hasNowiki/index.js +1 -13
  104. package/src/hasNowiki/pre.js +1 -13
  105. package/src/heading.js +4 -55
  106. package/src/html.js +5 -120
  107. package/src/imageParameter.js +3 -165
  108. package/src/imagemap.js +3 -62
  109. package/src/imagemapLink.js +2 -14
  110. package/src/index.js +9 -530
  111. package/src/link/category.js +1 -32
  112. package/src/link/file.js +3 -158
  113. package/src/link/galleryImage.js +3 -61
  114. package/src/link/index.js +4 -273
  115. package/src/magicLink.js +6 -87
  116. package/src/nested/choose.js +1 -2
  117. package/src/nested/combobox.js +1 -2
  118. package/src/nested/index.js +8 -32
  119. package/src/nested/references.js +1 -2
  120. package/src/nowiki/comment.js +2 -26
  121. package/src/nowiki/dd.js +1 -47
  122. package/src/nowiki/doubleUnderscore.js +1 -31
  123. package/src/nowiki/hr.js +2 -21
  124. package/src/nowiki/index.js +2 -24
  125. package/src/nowiki/list.js +2 -5
  126. package/src/nowiki/noinclude.js +0 -14
  127. package/src/nowiki/quote.js +2 -16
  128. package/src/onlyinclude.js +2 -27
  129. package/src/paramTag/index.js +2 -25
  130. package/src/paramTag/inputbox.js +2 -5
  131. package/src/parameter.js +6 -148
  132. package/src/syntax.js +1 -69
  133. package/src/table/index.js +2 -939
  134. package/src/table/td.js +6 -226
  135. package/src/table/tr.js +3 -248
  136. package/src/tagPair/ext.js +4 -23
  137. package/src/tagPair/include.js +1 -25
  138. package/src/tagPair/index.js +3 -52
  139. package/src/transclude.js +6 -513
  140. package/typings/api.d.ts +9 -0
  141. package/typings/index.d.ts +51 -0
  142. package/typings/node.d.ts +16 -0
  143. package/typings/parser.d.ts +5 -0
  144. package/typings/token.d.ts +28 -0
  145. package/util/lint.js +2 -0
  146. package/util/string.js +0 -51
  147. package/lib/ranges.js +0 -130
  148. package/mixin/attributeParent.js +0 -117
  149. package/mixin/fixedToken.js +0 -40
  150. package/mixin/singleLine.js +0 -31
  151. package/mixin/sol.js +0 -54
  152. package/parser/selector.js +0 -177
  153. package/src/charinsert.js +0 -97
  154. package/tool/index.js +0 -1202
  155. package/util/debug.js +0 -73
package/src/magicLink.js CHANGED
@@ -10,34 +10,6 @@ const {generateForChild} = require('../util/lint'),
10
10
  */
11
11
  class MagicLinkToken extends Token {
12
12
  type = 'free-ext-link';
13
- #protocolRegex;
14
-
15
- /** 协议 */
16
- get protocol() {
17
- return this.#protocolRegex.exec(this.text())?.[0];
18
- }
19
-
20
- set protocol(value) {
21
- if (typeof value !== 'string') {
22
- this.typeError('protocol', 'String');
23
- } else if (!new RegExp(`${this.#protocolRegex.source}$`, 'iu').test(value)) {
24
- throw new RangeError(`非法的外链协议:${value}`);
25
- }
26
- const {link} = this;
27
- if (!this.#protocolRegex.test(link)) {
28
- throw new Error(`特殊外链无法更改协议!${link}`);
29
- }
30
- this.replaceChildren(link.replace(this.#protocolRegex, value));
31
- }
32
-
33
- /** 和内链保持一致 */
34
- get link() {
35
- return this.text();
36
- }
37
-
38
- set link(url) {
39
- this.setTarget(url);
40
- }
41
13
 
42
14
  /**
43
15
  * @override
@@ -45,16 +17,18 @@ class MagicLinkToken extends Token {
45
17
  */
46
18
  lint(start = this.getAbsoluteIndex()) {
47
19
  const errors = super.lint(start),
48
- source = `[,;。:!?()]+${this.type === 'ext-link-url' ? '|\\|+' : ''}`;
20
+ source = `[,;。:!?()]+${this.type === 'ext-link-url' ? '|\\|+' : ''}`,
21
+ regex = new RegExp(source, 'u'),
22
+ regexGlobal = new RegExp(source, 'gu');
49
23
  let /** @type {{top: number, left: number}} */ rect;
50
24
  for (const child of this.childNodes) {
51
25
  const str = String(child);
52
- if (child.type !== 'text' || !new RegExp(source, 'u').test(str)) {
26
+ if (child.type !== 'text' || !regex.test(str)) {
53
27
  continue;
54
28
  }
55
29
  rect ||= {start, ...this.getRootNode().posFromIndex(start)};
56
30
  const refError = generateForChild(child, rect, '', 'warning');
57
- errors.push(...[...str.matchAll(new RegExp(source, 'gu'))].map(({index, 0: {0: char, length}}) => {
31
+ errors.push(...[...str.matchAll(regexGlobal)].map(({index, 0: {0: char, length}}) => {
58
32
  const lines = str.slice(0, index).split('\n'),
59
33
  {length: top} = lines,
60
34
  {length: left} = lines.at(-1),
@@ -80,70 +54,15 @@ class MagicLinkToken extends Token {
80
54
  /**
81
55
  * @param {string} url 网址
82
56
  * @param {boolean} doubleSlash 是否接受"//"作为协议
83
- * @param {accum} accum
57
+ * @param {import('../typings/token').accum} accum
84
58
  */
85
59
  constructor(url, doubleSlash, config = Parser.getConfig(), accum = []) {
86
60
  super(url, config, true, accum, {
87
- 'Stage-1': ':', '!ExtToken': '',
88
61
  });
89
62
  if (doubleSlash) {
90
63
  this.type = 'ext-link-url';
91
64
  }
92
- this.#protocolRegex = new RegExp(`^(?:${config.protocol}${doubleSlash ? '|//' : ''})`, 'iu');
93
- }
94
-
95
- /** @override */
96
- cloneNode() {
97
- const cloned = this.cloneChildNodes();
98
- return Parser.run(() => {
99
- const token = new MagicLinkToken(undefined, this.type === 'ext-link-url', this.getAttribute('config'));
100
- token.append(...cloned);
101
- token.afterBuild();
102
- return token;
103
- });
104
- }
105
-
106
- /**
107
- * 获取网址
108
- * @throws `Error` 非标准协议
109
- */
110
- getUrl() {
111
- let url = this.text();
112
- if (url.startsWith('//')) {
113
- url = `https:${url}`;
114
- }
115
- try {
116
- return new URL(url);
117
- } catch (e) {
118
- if (e instanceof TypeError && e.message === 'Invalid URL') {
119
- throw new Error(`非标准协议的外部链接:${url}`);
120
- }
121
- throw e;
122
- }
123
- }
124
-
125
- /**
126
- * 设置外链目标
127
- * @param {string|URL} url 含协议的网址
128
- * @throws `SyntaxError` 非法的自由外链目标
129
- */
130
- setTarget(url) {
131
- url = String(url);
132
- const root = Parser.parse(url, this.getAttribute('include'), 9, this.getAttribute('config')),
133
- {length, firstChild: freeExtLink} = root;
134
- if (length !== 1 || freeExtLink.type !== 'free-ext-link') {
135
- throw new SyntaxError(`非法的自由外链目标:${url}`);
136
- }
137
- this.replaceChildren(...freeExtLink.childNodes);
138
- }
139
-
140
- /** 是否是模板或魔术字参数 */
141
- isParamValue() {
142
- const ParameterToken = require('./parameter');
143
- const /** @type {ParameterToken} */ parameter = this.closest('parameter');
144
- return parameter?.getValue() === this.text();
145
65
  }
146
66
  }
147
67
 
148
- Parser.classes.MagicLinkToken = __filename;
149
68
  module.exports = MagicLinkToken;
@@ -12,7 +12,7 @@ class ChooseToken extends NestedToken {
12
12
 
13
13
  /**
14
14
  * @param {string|undefined} wikitext wikitext
15
- * @param {accum} accum
15
+ * @param {import('../../typings/token').accum} accum
16
16
  */
17
17
  constructor(wikitext, config = Parser.getConfig(), accum = []) {
18
18
  const regex = /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu;
@@ -20,5 +20,4 @@ class ChooseToken extends NestedToken {
20
20
  }
21
21
  }
22
22
 
23
- Parser.classes.ChooseToken = __filename;
24
23
  module.exports = ChooseToken;
@@ -12,12 +12,11 @@ class ComboboxToken extends NestedToken {
12
12
 
13
13
  /**
14
14
  * @param {string|undefined} wikitext wikitext
15
- * @param {accum} accum
15
+ * @param {import('../../typings/token').accum} accum
16
16
  */
17
17
  constructor(wikitext, config = Parser.getConfig(), accum = []) {
18
18
  super(wikitext, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], config, accum);
19
19
  }
20
20
  }
21
21
 
22
- Parser.classes.ComboboxToken = __filename;
23
22
  module.exports = ComboboxToken;
@@ -13,13 +13,12 @@ const {generateForChild} = require('../../util/lint'),
13
13
  */
14
14
  class NestedToken extends Token {
15
15
  type = 'ext-inner';
16
- #tags;
17
16
 
18
17
  /**
19
18
  * @param {string|undefined} wikitext wikitext
20
19
  * @param {RegExp} regex 内层正则
21
20
  * @param {string[]} tags 内层标签名
22
- * @param {accum} accum
21
+ * @param {import('../../typings/token').accum} accum
23
22
  */
24
23
  constructor(wikitext, regex, tags, config = Parser.getConfig(), accum = []) {
25
24
  const text = wikitext?.replace(
@@ -34,14 +33,15 @@ class NestedToken extends Token {
34
33
  }
35
34
  return str;
36
35
  },
37
- )?.replace(/(?<=^|\0\d+[ce]\x7F)[^\0]+(?=$|\0\d+[ce]\x7F)/gu, substr => {
38
- new NoincludeToken(substr, config, accum);
39
- return `\0${accum.length}c\x7F`;
40
- });
36
+ )?.replace(
37
+ /(?<=^|\0\d+[ce]\x7F)[^\0]+(?=$|\0\d+[ce]\x7F)/gu,
38
+ substr => {
39
+ new NoincludeToken(substr, config, accum);
40
+ return `\0${accum.length}c\x7F`;
41
+ },
42
+ );
41
43
  super(text, config, true, accum, {
42
- NoincludeToken: ':', ExtToken: ':',
43
44
  });
44
- this.#tags = tags;
45
45
  }
46
46
 
47
47
  /**
@@ -64,30 +64,6 @@ class NestedToken extends Token {
64
64
  }),
65
65
  ];
66
66
  }
67
-
68
- /**
69
- * @override
70
- * @template {string|Token} T
71
- * @param {T} token 待插入的子节点
72
- * @param {number} i 插入位置
73
- */
74
- insertAt(token, i = this.length) {
75
- return token.type === 'ext' && !this.#tags.includes(token.name)
76
- ? this.typeError(`${this.constructor.name}只能以${this.#tags.join('或')}标签作为子节点!`)
77
- : super.insertAt(token, i);
78
- }
79
-
80
- /** @override */
81
- cloneNode() {
82
- const cloned = this.cloneChildNodes(),
83
- config = this.getAttribute('config');
84
- return Parser.run(() => {
85
- const token = new this.constructor(undefined, config);
86
- token.append(...cloned);
87
- return token;
88
- });
89
- }
90
67
  }
91
68
 
92
- Parser.classes.NestedToken = __filename;
93
69
  module.exports = NestedToken;
@@ -12,12 +12,11 @@ class ReferencesToken extends NestedToken {
12
12
 
13
13
  /**
14
14
  * @param {string|undefined} wikitext wikitext
15
- * @param {accum} accum
15
+ * @param {import('../../typings/token').accum} accum
16
16
  */
17
17
  constructor(wikitext, config = Parser.getConfig(), accum = []) {
18
18
  super(wikitext, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], config, accum);
19
19
  }
20
20
  }
21
21
 
22
- Parser.classes.ReferencesToken = __filename;
23
22
  module.exports = ReferencesToken;
@@ -13,20 +13,14 @@ class CommentToken extends hidden(NowikiToken) {
13
13
  type = 'comment';
14
14
  closed;
15
15
 
16
- /** 内部wikitext */
17
- get innerText() {
18
- return String(this.firstChild);
19
- }
20
-
21
16
  /**
22
17
  * @param {string} wikitext wikitext
23
18
  * @param {boolean} closed 是否闭合
24
- * @param {accum} accum
19
+ * @param {import('../../typings/token').accum} accum
25
20
  */
26
21
  constructor(wikitext, closed = true, config = Parser.getConfig(), accum = []) {
27
22
  super(wikitext, config, accum);
28
23
  this.closed = closed;
29
- Object.defineProperty(this, 'closed', {enumerable: false});
30
24
  }
31
25
 
32
26
  /** @override */
@@ -34,11 +28,6 @@ class CommentToken extends hidden(NowikiToken) {
34
28
  return 4;
35
29
  }
36
30
 
37
- /** @override */
38
- print() {
39
- return super.print({pre: '&lt;!--', post: this.closed ? '--&gt;' : ''});
40
- }
41
-
42
31
  /**
43
32
  * @override
44
33
  * @param {number} start 起始位置
@@ -49,23 +38,10 @@ class CommentToken extends hidden(NowikiToken) {
49
38
 
50
39
  /**
51
40
  * @override
52
- * @param {string} selector
53
41
  */
54
42
  toString(selector) {
55
- if (!this.closed && this.nextSibling) {
56
- Parser.error('自动闭合HTML注释', this);
57
- this.closed = true;
58
- }
59
- return selector && this.matches(selector)
60
- ? ''
61
- : `<!--${String(this.firstChild)}${this.closed ? '-->' : ''}`;
62
- }
63
-
64
- /** @override */
65
- cloneNode() {
66
- return Parser.run(() => new CommentToken(String(this.firstChild), this.closed, this.getAttribute('config')));
43
+ return `<!--${String(this.firstChild)}${this.closed ? '-->' : ''}`;
67
44
  }
68
45
  }
69
46
 
70
- Parser.classes.CommentToken = __filename;
71
47
  module.exports = CommentToken;
package/src/nowiki/dd.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const Parser = require('../..'),
4
- NowikiToken = require('.');
3
+ const NowikiToken = require('.');
5
4
 
6
5
  /**
7
6
  * :
@@ -9,51 +8,6 @@ const Parser = require('../..'),
9
8
  */
10
9
  class DdToken extends NowikiToken {
11
10
  type = 'dd';
12
-
13
- /** 是否包含<dt> */
14
- get dt() {
15
- return String(this).includes(';');
16
- }
17
-
18
- /** 是否包含<ul> */
19
- get ul() {
20
- return String(this).includes('*');
21
- }
22
-
23
- /** 是否包含<ol> */
24
- get ol() {
25
- return String(this).includes('#');
26
- }
27
-
28
- /** 缩进数 */
29
- get indent() {
30
- return String(this).split(':').length - 1;
31
- }
32
-
33
- set indent(indent) {
34
- if (this.type === 'dd') {
35
- if (!Number.isInteger(indent)) {
36
- this.typeError('set indent', 'Number');
37
- } else if (indent < 0) {
38
- throw new RangeError(`indent 应为自然数!${indent}`);
39
- }
40
- this.setText(':'.repeat(indent));
41
- }
42
- }
43
-
44
- /**
45
- * @override
46
- * @param {string} str 新文本
47
- * @throws `RangeError` 错误的列表语法
48
- */
49
- setText(str) {
50
- const src = this.type === 'dd' ? ':' : ';:*#';
51
- if (new RegExp(`[^${src}]`, 'u').test(str)) {
52
- throw new RangeError(`${this.constructor.name} 仅能包含${[...src].map(c => `"${c}"`).join('、')}!`);
53
- }
54
- return super.setText(str);
55
- }
56
11
  }
57
12
 
58
- Parser.classes.DdToken = __filename;
59
13
  module.exports = DdToken;
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const hidden = require('../../mixin/hidden'),
4
- Parser = require('../..'),
5
4
  NowikiToken = require('.');
6
5
 
7
6
  /**
@@ -16,41 +15,12 @@ class DoubleUnderscoreToken extends hidden(NowikiToken) {
16
15
  return 2;
17
16
  }
18
17
 
19
- /** @override */
20
- print() {
21
- return super.print({pre: '__', post: '__'});
22
- }
23
-
24
18
  /**
25
19
  * @override
26
- * @param {string} selector
27
20
  */
28
21
  toString(selector) {
29
- return selector && this.matches(selector) ? '' : `__${String(this.firstChild)}__`;
30
- }
31
-
32
- /**
33
- * @param {string} word 状态开关名
34
- * @param {accum} accum
35
- */
36
- constructor(word, config = Parser.getConfig(), accum = []) {
37
- super(word, config, accum);
38
- this.setAttribute('name', word.toLowerCase());
39
- }
40
-
41
- /** @override */
42
- cloneNode() {
43
- return Parser.run(() => new DoubleUnderscoreToken(String(this.firstChild), this.getAttribute('config')));
44
- }
45
-
46
- /**
47
- * @override
48
- * @throws `Error` 禁止修改
49
- */
50
- setText() {
51
- throw new Error(`禁止修改 ${this.constructor.name}!`);
22
+ return `__${String(this.firstChild)}__`;
52
23
  }
53
24
  }
54
25
 
55
- Parser.classes.DoubleUnderscoreToken = __filename;
56
26
  module.exports = DoubleUnderscoreToken;
package/src/nowiki/hr.js CHANGED
@@ -1,41 +1,22 @@
1
1
  'use strict';
2
2
 
3
3
  const Parser = require('../..'),
4
- sol = require('../../mixin/sol'),
5
4
  NowikiToken = require('.');
6
5
 
7
6
  /**
8
7
  * `<hr>`
9
8
  * @classdesc `{childNodes: [AstText]}`
10
9
  */
11
- class HrToken extends sol(NowikiToken) {
10
+ class HrToken extends NowikiToken {
12
11
  type = 'hr';
13
12
 
14
13
  /**
15
14
  * @param {number} n 字符串长度
16
- * @param {accum} accum
15
+ * @param {import('../../typings/token').accum} accum
17
16
  */
18
17
  constructor(n, config = Parser.getConfig(), accum = []) {
19
18
  super('-'.repeat(n), config, accum);
20
19
  }
21
-
22
- /** @override */
23
- cloneNode() {
24
- return Parser.run(() => new HrToken(String(this).length, this.getAttribute('config')));
25
- }
26
-
27
- /**
28
- * @override
29
- * @param {string} str 新文本
30
- * @throws `RangeError` 错误的\<hr\>语法
31
- */
32
- setText(str) {
33
- if (str.length < 4 || /[^-]/u.test(str)) {
34
- throw new RangeError('<hr>总是写作不少于4个的连续"-"!');
35
- }
36
- return super.setText(str);
37
- }
38
20
  }
39
21
 
40
- Parser.classes.HrToken = __filename;
41
22
  module.exports = HrToken;
@@ -1,21 +1,19 @@
1
1
  'use strict';
2
2
 
3
3
  const {generateForSelf} = require('../../util/lint'),
4
- fixedToken = require('../../mixin/fixedToken'),
5
4
  Parser = require('../..'),
6
- AstText = require('../../lib/text'),
7
5
  Token = require('..');
8
6
 
9
7
  /**
10
8
  * 纯文字Token,不会被解析
11
9
  * @classdesc `{childNodes: [AstText]}`
12
10
  */
13
- class NowikiToken extends fixedToken(Token) {
11
+ class NowikiToken extends Token {
14
12
  type = 'ext-inner';
15
13
 
16
14
  /**
17
15
  * @param {string} wikitext wikitext
18
- * @param {accum} accum
16
+ * @param {import('../../typings/token').accum} accum
19
17
  */
20
18
  constructor(wikitext, config = Parser.getConfig(), accum = []) {
21
19
  super(wikitext, config, true, accum);
@@ -31,26 +29,6 @@ class NowikiToken extends fixedToken(Token) {
31
29
  ? [generateForSelf(this, {start}, Parser.msg('nothing should be in <$1>', name))]
32
30
  : super.lint(start);
33
31
  }
34
-
35
- /**
36
- * @override
37
- * @this {NowikiToken & {firstChild: AstText, constructor: typeof NowikiToken}}
38
- */
39
- cloneNode() {
40
- const {constructor, firstChild: {data}, type} = this,
41
- token = Parser.run(() => new constructor(data, this.getAttribute('config')));
42
- token.type = type;
43
- return token;
44
- }
45
-
46
- /**
47
- * @override
48
- * @param {string} str 新文本
49
- */
50
- setText(str) {
51
- return super.setText(str, 0);
52
- }
53
32
  }
54
33
 
55
- Parser.classes.NowikiToken = __filename;
56
34
  module.exports = NowikiToken;
@@ -1,16 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const sol = require('../../mixin/sol'),
4
- Parser = require('../..'),
5
- DdToken = require('./dd');
3
+ const DdToken = require('./dd');
6
4
 
7
5
  /**
8
6
  * ;:*#
9
7
  * @classdesc `{childNodes: [AstText]}`
10
8
  */
11
- class ListToken extends sol(DdToken) {
9
+ class ListToken extends DdToken {
12
10
  type = 'list';
13
11
  }
14
12
 
15
- Parser.classes.ListToken = __filename;
16
13
  module.exports = ListToken;
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const hidden = require('../../mixin/hidden'),
4
- Parser = require('../..'),
5
4
  NowikiToken = require('.');
6
5
 
7
6
  /**
@@ -10,19 +9,6 @@ const hidden = require('../../mixin/hidden'),
10
9
  */
11
10
  class NoincludeToken extends hidden(NowikiToken) {
12
11
  type = 'noinclude';
13
-
14
- /**
15
- * @override
16
- * @param {string} str 新文本
17
- * @throws `Error` 不可更改
18
- */
19
- setText(str) {
20
- if (/^<\/?(?:(?:no|only)include|includeonly)(?:\s.*)?\/?>$/isu.test(String(this))) {
21
- throw new Error(`${this.constructor.name} 不可更改文字内容!`);
22
- }
23
- return super.setText(str);
24
- }
25
12
  }
26
13
 
27
- Parser.classes.NoincludeToken = __filename;
28
14
  module.exports = NoincludeToken;
@@ -14,11 +14,10 @@ class QuoteToken extends NowikiToken {
14
14
 
15
15
  /**
16
16
  * @param {number} n 字符串长度
17
- * @param {accum} accum
17
+ * @param {import('../../typings/token').accum} accum
18
18
  */
19
19
  constructor(n, config = Parser.getConfig(), accum = []) {
20
20
  super(`'`.repeat(n), config, accum);
21
- this.setAttribute('name', String(n));
22
21
  }
23
22
 
24
23
  /**
@@ -29,7 +28,7 @@ class QuoteToken extends NowikiToken {
29
28
  lint(start = this.getAbsoluteIndex()) {
30
29
  const {previousSibling, nextSibling} = this,
31
30
  message = Parser.msg('lonely "$1"', `'`),
32
- /** @type {LintError[]} */ errors = [];
31
+ /** @type {import('../../typings/token').LintError[]} */ errors = [];
33
32
  let refError, wikitext;
34
33
  if (previousSibling?.type === 'text' && previousSibling.data.endsWith(`'`)) {
35
34
  refError = generateForSelf(this, {start}, message);
@@ -51,19 +50,6 @@ class QuoteToken extends NowikiToken {
51
50
  }
52
51
  return errors;
53
52
  }
54
-
55
- /**
56
- * @override
57
- * @param {string} str 新文本
58
- * @throws `RangeError` 错误的单引号语法
59
- */
60
- setText(str) {
61
- if (str === `''` || str === `'''` || str === `'''''`) {
62
- return super.setText(str);
63
- }
64
- throw new RangeError(`${this.constructor.name} 的内部文本只能为连续 2/3/5 个"'"!`);
65
- }
66
53
  }
67
54
 
68
- Parser.classes.QuoteToken = __filename;
69
55
  module.exports = QuoteToken;
@@ -10,14 +10,9 @@ const Parser = require('..'),
10
10
  class OnlyincludeToken extends Token {
11
11
  type = 'onlyinclude';
12
12
 
13
- /** 内部wikitext */
14
- get innerText() {
15
- return this.text();
16
- }
17
-
18
13
  /**
19
14
  * @param {string} inner 标签内部wikitext
20
- * @param {accum} accum
15
+ * @param {import('../typings/token').accum} accum
21
16
  */
22
17
  constructor(inner, config = Parser.getConfig(), accum = []) {
23
18
  super(inner, config, true, accum);
@@ -25,10 +20,9 @@ class OnlyincludeToken extends Token {
25
20
 
26
21
  /**
27
22
  * @override
28
- * @param {string} selector
29
23
  */
30
24
  toString(selector) {
31
- return selector && this.matches(selector) ? '' : `<onlyinclude>${super.toString(selector)}</onlyinclude>`;
25
+ return `<onlyinclude>${super.toString()}</onlyinclude>`;
32
26
  }
33
27
 
34
28
  /** @override */
@@ -36,29 +30,10 @@ class OnlyincludeToken extends Token {
36
30
  return 13;
37
31
  }
38
32
 
39
- /** @override */
40
- print() {
41
- return super.print({
42
- pre: '<span class="wpb-ext">&lt;onlyinclude&gt;</span>',
43
- post: '<span class="wpb-ext">&lt;/onlyinclude&gt;</span>',
44
- });
45
- }
46
-
47
33
  /** @override */
48
34
  isPlain() {
49
35
  return true;
50
36
  }
51
-
52
- /** @override */
53
- cloneNode() {
54
- const cloned = this.cloneChildNodes();
55
- return Parser.run(() => {
56
- const token = new OnlyincludeToken(undefined, this.getAttribute('config'));
57
- token.append(...cloned);
58
- return token;
59
- });
60
- }
61
37
  }
62
38
 
63
- Parser.classes.OnlyincludeToken = __filename;
64
39
  module.exports = OnlyincludeToken;