wikiparser-node 0.6.1 → 0.6.5-b

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 (82) hide show
  1. package/bundle/bundle.min.js +40 -0
  2. package/package.json +9 -11
  3. package/README.md +0 -39
  4. package/config/default.json +0 -832
  5. package/config/llwiki.json +0 -630
  6. package/config/moegirl.json +0 -727
  7. package/config/zhwiki.json +0 -1269
  8. package/index.js +0 -277
  9. package/lib/element.js +0 -612
  10. package/lib/node.js +0 -771
  11. package/lib/ranges.js +0 -130
  12. package/lib/text.js +0 -175
  13. package/lib/title.js +0 -70
  14. package/mixin/attributeParent.js +0 -113
  15. package/mixin/fixedToken.js +0 -40
  16. package/mixin/hidden.js +0 -21
  17. package/mixin/sol.js +0 -68
  18. package/parser/brackets.js +0 -118
  19. package/parser/commentAndExt.js +0 -63
  20. package/parser/converter.js +0 -45
  21. package/parser/externalLinks.js +0 -31
  22. package/parser/hrAndDoubleUnderscore.js +0 -36
  23. package/parser/html.js +0 -42
  24. package/parser/links.js +0 -97
  25. package/parser/list.js +0 -59
  26. package/parser/magicLinks.js +0 -41
  27. package/parser/quotes.js +0 -64
  28. package/parser/selector.js +0 -175
  29. package/parser/table.js +0 -114
  30. package/src/arg.js +0 -198
  31. package/src/atom/hidden.js +0 -13
  32. package/src/atom/index.js +0 -43
  33. package/src/attribute.js +0 -460
  34. package/src/charinsert.js +0 -91
  35. package/src/converter.js +0 -176
  36. package/src/converterFlags.js +0 -279
  37. package/src/converterRule.js +0 -259
  38. package/src/extLink.js +0 -175
  39. package/src/gallery.js +0 -146
  40. package/src/hasNowiki/index.js +0 -42
  41. package/src/hasNowiki/pre.js +0 -40
  42. package/src/heading.js +0 -123
  43. package/src/html.js +0 -230
  44. package/src/imageParameter.js +0 -276
  45. package/src/imagemap.js +0 -205
  46. package/src/imagemapLink.js +0 -43
  47. package/src/index.js +0 -842
  48. package/src/link/category.js +0 -49
  49. package/src/link/file.js +0 -321
  50. package/src/link/galleryImage.js +0 -125
  51. package/src/link/index.js +0 -347
  52. package/src/magicLink.js +0 -135
  53. package/src/nested/choose.js +0 -24
  54. package/src/nested/combobox.js +0 -23
  55. package/src/nested/index.js +0 -88
  56. package/src/nested/references.js +0 -23
  57. package/src/nowiki/comment.js +0 -71
  58. package/src/nowiki/dd.js +0 -59
  59. package/src/nowiki/doubleUnderscore.js +0 -56
  60. package/src/nowiki/hr.js +0 -41
  61. package/src/nowiki/index.js +0 -56
  62. package/src/nowiki/list.js +0 -16
  63. package/src/nowiki/noinclude.js +0 -28
  64. package/src/nowiki/quote.js +0 -63
  65. package/src/onlyinclude.js +0 -61
  66. package/src/paramTag/index.js +0 -83
  67. package/src/paramTag/inputbox.js +0 -42
  68. package/src/parameter.js +0 -214
  69. package/src/syntax.js +0 -91
  70. package/src/table/index.js +0 -981
  71. package/src/table/td.js +0 -308
  72. package/src/table/tr.js +0 -299
  73. package/src/tagPair/ext.js +0 -122
  74. package/src/tagPair/include.js +0 -60
  75. package/src/tagPair/index.js +0 -126
  76. package/src/transclude.js +0 -751
  77. package/tool/index.js +0 -1199
  78. package/util/base.js +0 -17
  79. package/util/debug.js +0 -73
  80. package/util/diff.js +0 -76
  81. package/util/lint.js +0 -40
  82. package/util/string.js +0 -105
package/src/link/index.js DELETED
@@ -1,347 +0,0 @@
1
- 'use strict';
2
-
3
- const Title = require('../../lib/title'),
4
- {noWrap} = require('../../util/string'),
5
- {undo} = require('../../util/debug'),
6
- Parser = require('../..'),
7
- AstText = require('../../lib/text'),
8
- Token = require('..');
9
-
10
- /**
11
- * 内链
12
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
13
- */
14
- class LinkToken extends Token {
15
- type = 'link';
16
- #bracket = true;
17
- #delimiter;
18
-
19
- /** 完整链接,和FileToken保持一致 */
20
- get link() {
21
- return String(this.#getTitle());
22
- }
23
-
24
- set link(link) {
25
- this.setTarget(link);
26
- }
27
-
28
- /** 是否链接到自身 */
29
- get selfLink() {
30
- return !this.#getTitle().title;
31
- }
32
-
33
- set selfLink(selfLink) {
34
- if (selfLink === true) {
35
- this.asSelfLink();
36
- }
37
- }
38
-
39
- /** fragment */
40
- get fragment() {
41
- return this.#getTitle().fragment;
42
- }
43
-
44
- set fragment(fragment) {
45
- this.setFragment(fragment);
46
- }
47
-
48
- /** interwiki */
49
- get interwiki() {
50
- return this.#getTitle().interwiki;
51
- }
52
-
53
- set interwiki(interwiki) {
54
- if (typeof interwiki !== 'string') {
55
- this.typeError('set interwiki', 'String');
56
- }
57
- const {prefix, main, fragment} = this.#getTitle(),
58
- link = `${interwiki}:${prefix}${main}${fragment && '#'}${fragment}`;
59
- if (interwiki && !this.isInterwiki(link)) {
60
- throw new RangeError(`${interwiki} 不是合法的跨维基前缀!`);
61
- }
62
- this.setTarget(link);
63
- }
64
-
65
- /** 链接显示文字 */
66
- get innerText() {
67
- if (this.type === 'link') {
68
- return this.childNodes.length > 1
69
- ? this.lastChild.text()
70
- : this.firstChild.text().replace(/^\s*:/u, '');
71
- }
72
- return undefined;
73
- }
74
-
75
- /**
76
- * @param {string} link 链接标题
77
- * @param {string|undefined} linkText 链接显示文字
78
- * @param {Title} title 链接标题对象
79
- * @param {accum} accum
80
- * @param {string} delimiter `|`
81
- */
82
- constructor(link, linkText, title, config = Parser.getConfig(), accum = [], delimiter = '|') {
83
- super(undefined, config, true, accum, {AtomToken: 0, Token: 1});
84
- const AtomToken = require('../atom');
85
- this.insertAt(new AtomToken(link, 'link-target', config, accum, {
86
- 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
87
- }));
88
- if (linkText !== undefined) {
89
- const inner = new Token(linkText, config, true, accum, {'Stage-5': ':', ConverterToken: ':'});
90
- inner.type = 'link-text';
91
- this.insertAt(inner.setAttribute('stage', Parser.MAX_STAGE - 1));
92
- }
93
- this.#delimiter = delimiter;
94
- this.getAttribute('protectChildren')(0);
95
- }
96
-
97
- /**
98
- * @override
99
- * @throws `Error` 非法的内链目标
100
- * @throws `Error` 不可更改命名空间
101
- */
102
- afterBuild() {
103
- this.setAttribute('name', this.normalizeTitle(this.firstChild.text()).title);
104
- if (this.#delimiter?.includes('\0')) {
105
- this.#delimiter = this.getAttribute('buildFromStr')(this.#delimiter).map(String).join('');
106
- }
107
- const /** @type {AstListener} */ linkListener = (e, data) => {
108
- const {prevTarget} = e;
109
- if (prevTarget?.type === 'link-target') {
110
- const name = prevTarget.text(),
111
- {title, interwiki, ns, valid} = this.normalizeTitle(name);
112
- if (!valid) {
113
- undo(e, data);
114
- throw new Error(`非法的内链目标:${name}`);
115
- } else if (this.type === 'category' && (interwiki || ns !== 14)
116
- || this.type === 'file' && (interwiki || ns !== 6)
117
- ) {
118
- undo(e, data);
119
- throw new Error(`${this.type === 'file' ? '文件' : '分类'}链接不可更改命名空间:${name}`);
120
- } else if (this.type === 'link' && !interwiki && (ns === 6 || ns === 14) && name.trim()[0] !== ':') {
121
- const /** @type {{firstChild: AstText}} */ {firstChild} = prevTarget;
122
- if (firstChild.type === 'text') {
123
- firstChild.insertData(0, ':');
124
- } else {
125
- prevTarget.prepend(':');
126
- }
127
- }
128
- this.setAttribute('name', title);
129
- }
130
- };
131
- this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
132
- return this;
133
- }
134
-
135
- /**
136
- * @override
137
- * @template {string} T
138
- * @param {T} key 属性键
139
- * @param {TokenAttribute<T>} value 属性值
140
- */
141
- setAttribute(key, value) {
142
- if (key === 'bracket') {
143
- this.#bracket = Boolean(value);
144
- return this;
145
- }
146
- return super.setAttribute(key, value);
147
- }
148
-
149
- /**
150
- * @override
151
- * @param {string} selector
152
- */
153
- toString(selector) {
154
- const str = super.toString(selector, this.#delimiter);
155
- return this.#bracket && !(selector && this.matches(selector)) ? `[[${str}]]` : str;
156
- }
157
-
158
- /** @override */
159
- getPadding() {
160
- return 2;
161
- }
162
-
163
- /** @override */
164
- getGaps() {
165
- return this.#delimiter.length;
166
- }
167
-
168
- /** @override */
169
- print() {
170
- return super.print(this.#bracket ? {pre: '[[', post: ']]', sep: this.#delimiter} : {sep: this.#delimiter});
171
- }
172
-
173
- /** 生成Title对象 */
174
- #getTitle() {
175
- return this.normalizeTitle(this.firstChild.text());
176
- }
177
-
178
- /**
179
- * @override
180
- * @this {LinkToken & {constructor: typeof LinkToken}}
181
- */
182
- cloneNode() {
183
- const [link, ...linkText] = this.cloneChildNodes();
184
- return Parser.run(() => {
185
- const token = new this.constructor('', undefined, this.#getTitle(), this.getAttribute('config'));
186
- token.firstChild.safeReplaceWith(link);
187
- token.append(...linkText);
188
- return token.afterBuild();
189
- });
190
- }
191
-
192
- /** @override */
193
- text() {
194
- const str = super.text('|');
195
- return this.#bracket ? `[[${str}]]` : str;
196
- }
197
-
198
- /**
199
- * 设置链接目标
200
- * @param {string} link 链接目标
201
- * @throws `SyntaxError` 非法的链接目标
202
- */
203
- setTarget(link) {
204
- link = String(link);
205
- if (this.type === 'link' && !/^\s*[:#]/u.test(link)) {
206
- link = `:${link}`;
207
- }
208
- const root = Parser.parse(`[[${link}]]`, this.getAttribute('include'), 6, this.getAttribute('config')),
209
- {length, firstChild: wikiLink} = root,
210
- {type, firstChild, length: linkLength} = wikiLink;
211
- if (length !== 1 || type !== this.type || linkLength !== 1) {
212
- const msgs = {link: '内链', file: '文件链接', category: '分类'};
213
- throw new SyntaxError(`非法的${msgs[this.type]}目标:${link}`);
214
- }
215
- wikiLink.destroy(true);
216
- this.firstChild.safeReplaceWith(firstChild);
217
- }
218
-
219
- /**
220
- * 设置跨语言链接
221
- * @param {string} lang 语言前缀
222
- * @param {string} link 页面标题
223
- * @throws `SyntaxError` 非法的跨语言链接
224
- */
225
- setLangLink(lang, link) {
226
- if (typeof lang !== 'string') {
227
- this.typeError('setLangLink', 'String');
228
- }
229
- link = String(link).trim();
230
- const [char] = link;
231
- if (char === '#') {
232
- throw new SyntaxError('跨语言链接不能仅为fragment!');
233
- } else if (char === ':') {
234
- link = link.slice(1);
235
- }
236
- const root = Parser.parse(`[[${lang}:${link}]]`, this.getAttribute('include'), 6, this.getAttribute('config')),
237
- /** @type {Token & {firstChild: LinkToken}} */ {length, firstChild: wikiLink} = root,
238
- {type, length: linkLength, interwiki, firstChild} = wikiLink;
239
- if (length !== 1 || type !== 'link' || linkLength !== 1 || interwiki !== lang.toLowerCase()) {
240
- throw new SyntaxError(`非法的跨语言链接目标:${lang}:${link}`);
241
- }
242
- wikiLink.destroy(true);
243
- this.firstChild.safeReplaceWith(firstChild);
244
- }
245
-
246
- /**
247
- * 设置fragment
248
- * @param {string} fragment fragment
249
- * @param {boolean} page 是否是其他页面
250
- * @throws `SyntaxError` 非法的fragment
251
- */
252
- #setFragment(fragment, page = true) {
253
- fragment = String(fragment).replaceAll(/[<>[\]#|=]/gu, p => encodeURIComponent(p));
254
- const include = this.getAttribute('include'),
255
- config = this.getAttribute('config'),
256
- root = Parser.parse(`[[${page ? `:${this.name}` : ''}#${fragment}]]`, include, 6, config),
257
- {length, firstChild: wikiLink} = root,
258
- {type, length: linkLength, firstChild} = wikiLink;
259
- if (length !== 1 || type !== 'link' || linkLength !== 1) {
260
- throw new SyntaxError(`非法的 fragment:${fragment}`);
261
- } else if (page) {
262
- Parser.warn(`${this.constructor.name}.setFragment 方法会同时规范化页面名!`);
263
- }
264
- wikiLink.destroy(true);
265
- this.firstChild.safeReplaceWith(firstChild);
266
- }
267
-
268
- /**
269
- * 设置fragment
270
- * @param {string} fragment fragment
271
- */
272
- setFragment(fragment) {
273
- this.#setFragment(fragment);
274
- }
275
-
276
- /**
277
- * 修改为到自身的链接
278
- * @param {string} fragment fragment
279
- * @throws `RangeError` 空fragment
280
- */
281
- asSelfLink(fragment = this.fragment) {
282
- fragment = String(fragment);
283
- if (!fragment.trim()) {
284
- throw new RangeError(`${this.constructor.name}.asSelfLink 方法必须指定非空的 fragment!`);
285
- }
286
- this.#setFragment(fragment, false);
287
- }
288
-
289
- /**
290
- * 设置链接显示文字
291
- * @param {string} linkText 链接显示文字
292
- * @throws `SyntaxError` 非法的链接显示文字
293
- */
294
- setLinkText(linkText = '') {
295
- linkText = String(linkText);
296
- let lastChild;
297
- const config = this.getAttribute('config');
298
- if (linkText) {
299
- const root = Parser.parse(`[[${
300
- this.type === 'category' ? 'Category:' : ''
301
- }L|${linkText}]]`, this.getAttribute('include'), 6, config),
302
- {length, firstChild: wikiLink} = root;
303
- if (length !== 1 || wikiLink.type !== this.type || wikiLink.childNodes.length !== 2) {
304
- throw new SyntaxError(`非法的${this.type === 'link' ? '内链文字' : '分类关键字'}:${noWrap(linkText)}`);
305
- }
306
- ({lastChild} = wikiLink);
307
- } else {
308
- lastChild = Parser.run(() => new Token('', config));
309
- lastChild.setAttribute('stage', 7).type = 'link-text';
310
- }
311
- if (this.childNodes.length === 1) {
312
- this.insertAt(lastChild);
313
- } else {
314
- this.lastChild.safeReplaceWith(lastChild);
315
- }
316
- }
317
-
318
- /**
319
- * 自动生成管道符后的链接文字
320
- * @throws `Error` 带有"#"或"%"时不可用
321
- */
322
- pipeTrick() {
323
- const linkText = this.firstChild.text();
324
- if (linkText.includes('#') || linkText.includes('%')) {
325
- throw new Error('Pipe trick 不能用于带有"#"或"%"的场合!');
326
- }
327
- const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)\(.+\)$/u.exec(linkText);
328
- if (m1) {
329
- this.setLinkText(m1[1].trim());
330
- return;
331
- }
332
- const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)(.+)$/u.exec(linkText);
333
- if (m2) {
334
- this.setLinkText(m2[1].trim());
335
- return;
336
- }
337
- const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?:(?<!\()\(.+\))?(?:, |,|، )./u.exec(linkText);
338
- if (m3) {
339
- this.setLinkText(m3[1].trim());
340
- return;
341
- }
342
- this.setLinkText(linkText);
343
- }
344
- }
345
-
346
- Parser.classes.LinkToken = __filename;
347
- module.exports = LinkToken;
package/src/magicLink.js DELETED
@@ -1,135 +0,0 @@
1
- 'use strict';
2
-
3
- const {generateForChild} = require('../util/lint'),
4
- Parser = require('..'),
5
- Token = require('.');
6
-
7
- /**
8
- * 自由外链
9
- * @classdesc `{childNodes: [...AstText|CommentToken|IncludeToken|NoincludeToken]}`
10
- */
11
- class MagicLinkToken extends Token {
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
-
42
- /**
43
- * @param {string} url 网址
44
- * @param {boolean} doubleSlash 是否接受"//"作为协议
45
- * @param {accum} accum
46
- */
47
- constructor(url, doubleSlash, config = Parser.getConfig(), accum = []) {
48
- super(url, config, true, accum, {'Stage-1': ':', '!ExtToken': ''});
49
- if (doubleSlash) {
50
- this.type = 'ext-link-url';
51
- }
52
- this.#protocolRegex = new RegExp(`^(?:${config.protocol}${doubleSlash ? '|//' : ''})`, 'iu');
53
- }
54
-
55
- /**
56
- * @override
57
- * @param {number} start 起始位置
58
- */
59
- lint(start = 0) {
60
- const errors = super.lint(start);
61
- let /** @type {{top: number, left: number}} */ rect;
62
- for (const child of this.childNodes) {
63
- const str = String(child);
64
- if (child.type !== 'text' || !/[,;。:!?()【】]/u.test(str)) {
65
- continue;
66
- }
67
- rect ||= this.getRootNode().posFromIndex(start);
68
- const refError = generateForChild(child, rect, 'URL中的全角标点', 'warning');
69
- errors.push(...[...str.matchAll(/[,;。:!?()【】]/gu)].map(({index}) => {
70
- const lines = str.slice(0, index).split('\n'),
71
- {length: top} = lines,
72
- {length: left} = lines.at(-1),
73
- startLine = refError.startLine + top - 1,
74
- startCol = top > 1 ? left : refError.startCol + left;
75
- return {...refError, startLine, endLine: startLine, startCol, endCol: startCol + 1};
76
- }));
77
- }
78
- return errors;
79
- }
80
-
81
- /** @override */
82
- cloneNode() {
83
- const cloned = this.cloneChildNodes();
84
- return Parser.run(() => {
85
- const token = new MagicLinkToken(undefined, this.type === 'ext-link-url', this.getAttribute('config'));
86
- token.append(...cloned);
87
- token.afterBuild();
88
- return token;
89
- });
90
- }
91
-
92
- /**
93
- * 获取网址
94
- * @throws `Error` 非标准协议
95
- */
96
- getUrl() {
97
- let url = this.text();
98
- if (url.startsWith('//')) {
99
- url = `https:${url}`;
100
- }
101
- try {
102
- return new URL(url);
103
- } catch (e) {
104
- if (e instanceof TypeError && e.message === 'Invalid URL') {
105
- throw new Error(`非标准协议的外部链接:${url}`);
106
- }
107
- throw e;
108
- }
109
- }
110
-
111
- /**
112
- * 设置外链目标
113
- * @param {string|URL} url 含协议的网址
114
- * @throws `SyntaxError` 非法的自由外链目标
115
- */
116
- setTarget(url) {
117
- url = String(url);
118
- const root = Parser.parse(url, this.getAttribute('include'), 9, this.getAttribute('config')),
119
- {length, firstChild: freeExtLink} = root;
120
- if (length !== 1 || freeExtLink.type !== 'free-ext-link') {
121
- throw new SyntaxError(`非法的自由外链目标:${url}`);
122
- }
123
- this.replaceChildren(...freeExtLink.childNodes);
124
- }
125
-
126
- /** 是否是模板或魔术字参数 */
127
- isParamValue() {
128
- const ParameterToken = require('./parameter');
129
- const /** @type {ParameterToken} */ parameter = this.closest('parameter');
130
- return parameter?.getValue() === this.text();
131
- }
132
- }
133
-
134
- Parser.classes.MagicLinkToken = __filename;
135
- module.exports = MagicLinkToken;
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- const Parser = require('../..'),
4
- NestedToken = require('.');
5
-
6
- /**
7
- * `<choose>`
8
- * @classdesc `{childNodes: [...ExtToken|NoincludeToken]}`
9
- */
10
- class ChooseToken extends NestedToken {
11
- name = 'choose';
12
-
13
- /**
14
- * @param {string|undefined} wikitext wikitext
15
- * @param {accum} accum
16
- */
17
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
18
- const regex = /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu;
19
- super(wikitext, regex, ['option', 'choicetemplate'], config, accum);
20
- }
21
- }
22
-
23
- Parser.classes.ChooseToken = __filename;
24
- module.exports = ChooseToken;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const Parser = require('../..'),
4
- NestedToken = require('.');
5
-
6
- /**
7
- * `<combobox>`
8
- * @classdesc `{childNodes: [...ExtToken|NoincludeToken]}`
9
- */
10
- class ComboboxToken extends NestedToken {
11
- name = 'combobox';
12
-
13
- /**
14
- * @param {string|undefined} wikitext wikitext
15
- * @param {accum} accum
16
- */
17
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
18
- super(wikitext, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], config, accum);
19
- }
20
- }
21
-
22
- Parser.classes.ComboboxToken = __filename;
23
- module.exports = ComboboxToken;
@@ -1,88 +0,0 @@
1
- 'use strict';
2
-
3
- const {generateForChild} = require('../../util/lint'),
4
- Parser = require('../..'),
5
- Token = require('..');
6
-
7
- /**
8
- * 嵌套式的扩展标签
9
- * @classdesc `{childNodes: [...ExtToken|NoincludeToken]}`
10
- */
11
- class NestedToken extends Token {
12
- type = 'ext-inner';
13
- #tags;
14
-
15
- /**
16
- * @param {string|undefined} wikitext wikitext
17
- * @param {RegExp} regex 内层正则
18
- * @param {string[]} tags 内层标签名
19
- * @param {accum} accum
20
- */
21
- constructor(wikitext, regex, tags, config = Parser.getConfig(), accum = []) {
22
- const ExtToken = require('../tagPair/ext'),
23
- NoincludeToken = require('../nowiki/noinclude');
24
- const text = wikitext?.replaceAll(
25
- regex,
26
- /** @type {function(...string): string} */ (_, name, attr, inner, closing) => {
27
- const str = `\0${accum.length + 1}e\x7F`;
28
- new ExtToken(name, attr, inner, closing, config, accum);
29
- return str;
30
- },
31
- )?.replaceAll(/(?<=^|\0\d+e\x7F).*?(?=$|\0\d+e\x7F)/gsu, substr => {
32
- if (substr === '') {
33
- return '';
34
- }
35
- new NoincludeToken(substr, config, accum);
36
- return `\0${accum.length}c\x7F`;
37
- });
38
- super(text, config, true, accum, {NoincludeToken: ':', ExtToken: ':'});
39
- this.#tags = tags;
40
- }
41
-
42
- /**
43
- * @override
44
- * @param {number} start 起始位置
45
- */
46
- lint(start = 0) {
47
- let rect;
48
- return [
49
- ...super.lint(start),
50
- ...this.childNodes.filter(child => {
51
- if (child.type === 'ext') {
52
- return false;
53
- }
54
- const str = String(child).trim();
55
- return str && !/^<!--.*-->$/u.test(str);
56
- }).map(child => {
57
- rect ||= this.getRootNode().posFromIndex(start);
58
- return generateForChild(child, rect, `<${this.name}>内的无效内容`);
59
- }),
60
- ];
61
- }
62
-
63
- /**
64
- * @override
65
- * @template {string|Token} T
66
- * @param {T} token 待插入的子节点
67
- * @param {number} i 插入位置
68
- */
69
- insertAt(token, i = this.childNodes.length) {
70
- return token.type === 'ext' && !this.#tags.includes(token.name)
71
- ? this.typeError(`${this.constructor.name}只能以${this.#tags.join('或')}标签作为子节点!`)
72
- : super.insertAt(token, i);
73
- }
74
-
75
- /** @override */
76
- cloneNode() {
77
- const cloned = this.cloneChildNodes(),
78
- config = this.getAttribute('config');
79
- return Parser.run(() => {
80
- const token = new this.constructor(undefined, config);
81
- token.append(...cloned);
82
- return token;
83
- });
84
- }
85
- }
86
-
87
- Parser.classes.NestedToken = __filename;
88
- module.exports = NestedToken;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const Parser = require('../..'),
4
- NestedToken = require('.');
5
-
6
- /**
7
- * `<references>`
8
- * @classdesc `{childNodes: [...ExtToken|NoincludeToken]}`
9
- */
10
- class ReferencesToken extends NestedToken {
11
- name = 'references';
12
-
13
- /**
14
- * @param {string|undefined} wikitext wikitext
15
- * @param {accum} accum
16
- */
17
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
18
- super(wikitext, /<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], config, accum);
19
- }
20
- }
21
-
22
- Parser.classes.ReferencesToken = __filename;
23
- module.exports = ReferencesToken;