wikiparser-node 0.9.0-m → 0.9.1-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 (77) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/extensions/editor.css +62 -0
  3. package/extensions/editor.js +328 -0
  4. package/extensions/ui.css +119 -0
  5. package/package.json +12 -10
  6. package/config/default.json +0 -831
  7. package/config/llwiki.json +0 -595
  8. package/config/moegirl.json +0 -685
  9. package/config/zhwiki.json +0 -803
  10. package/index.js +0 -81
  11. package/lib/element.js +0 -136
  12. package/lib/node.js +0 -236
  13. package/lib/text.js +0 -150
  14. package/lib/title.js +0 -56
  15. package/mixin/hidden.js +0 -18
  16. package/parser/brackets.js +0 -125
  17. package/parser/commentAndExt.js +0 -58
  18. package/parser/converter.js +0 -45
  19. package/parser/externalLinks.js +0 -32
  20. package/parser/hrAndDoubleUnderscore.js +0 -37
  21. package/parser/html.js +0 -41
  22. package/parser/links.js +0 -93
  23. package/parser/list.js +0 -58
  24. package/parser/magicLinks.js +0 -40
  25. package/parser/quotes.js +0 -63
  26. package/parser/table.js +0 -113
  27. package/src/arg.js +0 -93
  28. package/src/atom/hidden.js +0 -11
  29. package/src/atom/index.js +0 -26
  30. package/src/attribute.js +0 -290
  31. package/src/attributes.js +0 -150
  32. package/src/converter.js +0 -70
  33. package/src/converterFlags.js +0 -97
  34. package/src/converterRule.js +0 -74
  35. package/src/extLink.js +0 -60
  36. package/src/gallery.js +0 -95
  37. package/src/hasNowiki/index.js +0 -32
  38. package/src/hasNowiki/pre.js +0 -28
  39. package/src/heading.js +0 -83
  40. package/src/html.js +0 -139
  41. package/src/imageParameter.js +0 -139
  42. package/src/imagemap.js +0 -140
  43. package/src/imagemapLink.js +0 -29
  44. package/src/index.js +0 -410
  45. package/src/link/category.js +0 -13
  46. package/src/link/file.js +0 -132
  47. package/src/link/galleryImage.js +0 -62
  48. package/src/link/index.js +0 -115
  49. package/src/magicLink.js +0 -66
  50. package/src/nested/choose.js +0 -23
  51. package/src/nested/combobox.js +0 -22
  52. package/src/nested/index.js +0 -66
  53. package/src/nested/references.js +0 -22
  54. package/src/nowiki/comment.js +0 -47
  55. package/src/nowiki/dd.js +0 -13
  56. package/src/nowiki/doubleUnderscore.js +0 -26
  57. package/src/nowiki/hr.js +0 -22
  58. package/src/nowiki/index.js +0 -34
  59. package/src/nowiki/list.js +0 -13
  60. package/src/nowiki/noinclude.js +0 -14
  61. package/src/nowiki/quote.js +0 -55
  62. package/src/onlyinclude.js +0 -39
  63. package/src/paramTag/index.js +0 -66
  64. package/src/paramTag/inputbox.js +0 -32
  65. package/src/parameter.js +0 -97
  66. package/src/syntax.js +0 -23
  67. package/src/table/index.js +0 -46
  68. package/src/table/td.js +0 -118
  69. package/src/table/tr.js +0 -74
  70. package/src/tagPair/ext.js +0 -128
  71. package/src/tagPair/include.js +0 -26
  72. package/src/tagPair/index.js +0 -77
  73. package/src/transclude.js +0 -336
  74. package/util/base.js +0 -17
  75. package/util/diff.js +0 -76
  76. package/util/lint.js +0 -55
  77. package/util/string.js +0 -75
@@ -1,139 +0,0 @@
1
- 'use strict';
2
-
3
- const {extUrlChar, extUrlCharFirst} = require('../util/string'),
4
- {generateForSelf} = require('../util/lint'),
5
- Title = require('../lib/title'),
6
- Parser = require('..'),
7
- Token = require('.');
8
-
9
- const params = new Set(['alt', 'link', 'lang', 'page', 'caption']);
10
-
11
- /**
12
- * 检查图片参数是否合法
13
- * @template {string} T
14
- * @param {T} key 参数名
15
- * @param {string} value 参数值
16
- * @returns {T extends 'link' ? string|Title : boolean}
17
- */
18
- const validate = (key, value, config = Parser.getConfig(), halfParsed = false) => {
19
- value = value.replace(/\0\d+t\x7F/gu, '').trim();
20
- switch (key) {
21
- case 'width':
22
- return /^(?:\d+x?|\d*x\d+)$/u.test(value);
23
- case 'link': {
24
- if (!value) {
25
- return '';
26
- }
27
- const regex = new RegExp(`(?:(?:${config.protocol}|//)${extUrlCharFirst}|\0\\d+m\x7F)${
28
- extUrlChar
29
- }(?=\0\\d+t\x7F|$)`, 'iu');
30
- if (regex.test(value)) {
31
- return value;
32
- } else if (value.startsWith('[[') && value.endsWith(']]')) {
33
- value = value.slice(2, -2);
34
- }
35
- const title = Parser.normalizeTitle(value, 0, false, config, halfParsed, true, true);
36
- return title.valid && title;
37
- }
38
- case 'lang':
39
- return config.variants.includes(value);
40
- case 'alt':
41
- case 'class':
42
- case 'manualthumb':
43
- return true;
44
- default:
45
- return !isNaN(value);
46
- }
47
- };
48
-
49
- /**
50
- * 图片参数
51
- * @classdesc `{childNodes: ...(AstText|Token)}`
52
- */
53
- class ImageParameterToken extends Token {
54
- type = 'image-parameter';
55
- #syntax = '';
56
-
57
- /** 图片链接 */
58
- get link() {
59
- return this.name === 'link' ? validate('link', super.text(), this.getAttribute('config')) : undefined;
60
- }
61
-
62
- /**
63
- * @param {string} str 图片参数
64
- * @param {accum} accum
65
- */
66
- constructor(str, config = Parser.getConfig(), accum = []) {
67
- let mt;
68
- const regexes = Object.entries(config.img).map(
69
- /** @returns {[string, string, RegExp]} */
70
- ([syntax, param]) => [syntax, param, new RegExp(`^(\\s*)${syntax.replace('$1', '(.*)')}(\\s*)$`, 'u')],
71
- ),
72
- param = regexes.find(([, key, regex]) => {
73
- mt = regex.exec(str);
74
- return mt && (mt.length !== 4 || validate(key, mt[2], config, true) !== false);
75
- });
76
- if (param) {
77
- if (mt.length === 3) {
78
- super(undefined, config, true, accum);
79
- this.#syntax = str;
80
- } else {
81
- super(mt[2], config, true, accum, {
82
- });
83
- this.#syntax = `${mt[1]}${param[0]}${mt[3]}`;
84
- }
85
- this.setAttribute('name', param[1]);
86
- return;
87
- }
88
- super(str, {...config, excludes: [...config.excludes, 'list']}, true, accum);
89
- this.setAttribute('name', 'caption').setAttribute('stage', 7);
90
- }
91
-
92
- /** @override */
93
- afterBuild() {
94
- if (this.parentNode.type === 'gallery-image' && !params.has(this.name)) {
95
- this.setAttribute('name', 'invalid');
96
- }
97
- }
98
-
99
- /** @override */
100
- isPlain() {
101
- return this.name === 'caption';
102
- }
103
-
104
- /**
105
- * @override
106
- */
107
- toString(selector) {
108
- return this.#syntax
109
- ? this.#syntax.replace('$1', super.toString(selector))
110
- : super.toString(selector);
111
- }
112
-
113
- /** @override */
114
- text() {
115
- return this.#syntax ? this.#syntax.replace('$1', super.text()).trim() : super.text().trim();
116
- }
117
-
118
- /** @override */
119
- getPadding() {
120
- return Math.max(0, this.#syntax.indexOf('$1'));
121
- }
122
-
123
- /**
124
- * @override
125
- * @this {ImageParameterToken & {link: Title}}
126
- * @param {number} start 起始位置
127
- */
128
- lint(start = this.getAbsoluteIndex()) {
129
- const errors = super.lint(start);
130
- if (this.name === 'invalid') {
131
- errors.push(generateForSelf(this, {start}, 'invalid gallery image parameter'));
132
- } else if (this.link?.encoded) {
133
- errors.push(generateForSelf(this, {start}, 'unnecessary URL encoding in an internal link'));
134
- }
135
- return errors;
136
- }
137
- }
138
-
139
- module.exports = ImageParameterToken;
package/src/imagemap.js DELETED
@@ -1,140 +0,0 @@
1
- 'use strict';
2
-
3
- const {generateForSelf, generateForChild} = require('../util/lint'),
4
- Parser = require('..'),
5
- Token = require('.'),
6
- NoincludeToken = require('./nowiki/noinclude'),
7
- GalleryImageToken = require('./link/galleryImage'),
8
- ImagemapLinkToken = require('./imagemapLink');
9
-
10
- /**
11
- * `<imagemap>`
12
- * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
13
- */
14
- class ImagemapToken extends Token {
15
- type = 'ext-inner';
16
- name = 'imagemap';
17
-
18
- /**
19
- * 图片
20
- * @returns {GalleryImageToken}
21
- */
22
- get image() {
23
- return this.childNodes.find(({type}) => type === 'imagemap-image');
24
- }
25
-
26
- /**
27
- * @param {string} inner 标签内部wikitext
28
- * @param {accum} accum
29
- * @throws `SyntaxError` 没有合法图片
30
- */
31
- constructor(inner, config = Parser.getConfig(), accum = []) {
32
- super(undefined, config, true, accum, {
33
- });
34
- if (!inner) {
35
- return;
36
- }
37
- const lines = inner.split('\n'),
38
- protocols = new Set(config.protocol.split('|')),
39
- SingleLineNoincludeToken = NoincludeToken,
40
- fallback = /** @param {string} line 一行文本 */ line => {
41
- super.insertAt(new SingleLineNoincludeToken(line, config, accum));
42
- };
43
- let first = true,
44
- error = false;
45
- for (const line of lines) {
46
- const trimmed = line.trim();
47
- if (error || !trimmed || trimmed[0] === '#') {
48
- //
49
- } else if (first) {
50
- const [file, ...options] = line.split('|'),
51
- title = this.normalizeTitle(file, 0, true);
52
- if (title.valid && title.ns === 6) {
53
- const token = new GalleryImageToken(
54
- file, options.length > 0 ? options.join('|') : undefined, config, accum,
55
- );
56
- token.type = 'imagemap-image';
57
- super.insertAt(token);
58
- first = false;
59
- continue;
60
- } else {
61
- error = true;
62
- }
63
- } else if (line.trim().split(/[\t ]/u)[0] === 'desc') {
64
- super.insertAt(line);
65
- continue;
66
- } else if (line.includes('[')) {
67
- const i = line.indexOf('['),
68
- substr = line.slice(i),
69
- mtIn = /^\[{2}([^|]+)(?:\|([^\]]+))?\]{2}[\w\s]*$/u.exec(substr);
70
- if (mtIn) {
71
- const title = this.normalizeTitle(mtIn[1], 0, true, false, true);
72
- if (title.valid) {
73
- super.insertAt(new ImagemapLinkToken(
74
- line.slice(0, i),
75
- mtIn.slice(1),
76
- substr.slice(substr.indexOf(']]') + 2),
77
- config,
78
- accum,
79
- ));
80
- continue;
81
- }
82
- } else if (protocols.has(substr.slice(1, substr.indexOf(':') + 1))
83
- || protocols.has(substr.slice(1, substr.indexOf('//') + 2))
84
- ) {
85
- const mtEx = /^\[([^\]\s]+)(?:(\s+)(\S[^\]]*)?)?\][\w\s]*$/u.exec(substr);
86
- if (mtEx) {
87
- super.insertAt(new ImagemapLinkToken(
88
- line.slice(0, i),
89
- mtEx.slice(1),
90
- substr.slice(substr.indexOf(']') + 1),
91
- config,
92
- accum,
93
- ));
94
- continue;
95
- }
96
- }
97
- }
98
- fallback(line);
99
- }
100
- }
101
-
102
- /**
103
- * @override
104
- */
105
- toString(selector) {
106
- return super.toString(selector, '\n');
107
- }
108
-
109
- /** @override */
110
- text() {
111
- return super.text('\n').replace(/\n{2,}/gu, '\n');
112
- }
113
-
114
- /** @override */
115
- getGaps() {
116
- return 1;
117
- }
118
-
119
- /**
120
- * @override
121
- * @param {number} start 起始位置
122
- */
123
- lint(start = this.getAbsoluteIndex()) {
124
- const errors = super.lint(start),
125
- rect = {start, ...this.getRootNode().posFromIndex(start)};
126
- if (this.image) {
127
- errors.push(
128
- ...this.childNodes.filter(child => {
129
- const str = String(child).trim();
130
- return child.type === 'noinclude' && str && str[0] !== '#';
131
- }).map(child => generateForChild(child, rect, 'invalid link in <imagemap>')),
132
- );
133
- } else {
134
- errors.push(generateForSelf(this, rect, '<imagemap> without an image'));
135
- }
136
- return errors;
137
- }
138
- }
139
-
140
- module.exports = ImagemapToken;
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- const Title = require('../lib/title'),
4
- Token = require('.'),
5
- NoincludeToken = require('./nowiki/noinclude'),
6
- LinkToken = require('./link'),
7
- ExtLinkToken = require('./extLink');
8
-
9
- /**
10
- * `<imagemap>`内的链接
11
- * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
12
- */
13
- class ImagemapLinkToken extends Token {
14
- type = 'imagemap-link';
15
-
16
- /**
17
- * @param {string} pre 链接前的文本
18
- * @param {[string, string, string|Title]} linkStuff 内外链接
19
- * @param {string} post 链接后的文本
20
- * @param {accum} accum
21
- */
22
- constructor(pre, linkStuff, post, config, accum) {
23
- const SomeLinkToken = linkStuff.length === 2 ? LinkToken : ExtLinkToken;
24
- super(undefined, config, true, accum);
25
- this.append(pre, new SomeLinkToken(...linkStuff, config, accum), new NoincludeToken(post, config, accum));
26
- }
27
- }
28
-
29
- module.exports = ImagemapLinkToken;
package/src/index.js DELETED
@@ -1,410 +0,0 @@
1
- 'use strict';
2
-
3
- /*
4
- * PHP解析器的步骤:
5
- * -1. 替换签名和`{{subst:}}`,参见Parser::preSaveTransform;这在revision中不可能保留,可以跳过
6
- * 0. 移除特定字符`\0`和`\x7F`,参见Parser::parse
7
- * 1. 注释/扩展标签('<'相关),参见Preprocessor_Hash::buildDomTreeArrayFromText和Sanitizer::decodeTagAttributes
8
- * 2. 模板/模板变量/标题,注意rightmost法则,以及`-{`和`[[`可以破坏`{{`或`{{{`语法,
9
- * 参见Preprocessor_Hash::buildDomTreeArrayFromText
10
- * 3. HTML标签(允许不匹配),参见Sanitizer::internalRemoveHtmlTags
11
- * 4. 表格,参见Parser::handleTables
12
- * 5. 水平线和状态开关,参见Parser::internalParse
13
- * 6. 内链,含文件和分类,参见Parser::handleInternalLinks2
14
- * 7. `'`,参见Parser::doQuotes
15
- * 8. 外链,参见Parser::handleExternalLinks
16
- * 9. ISBN、RFC(未来将废弃,不予支持)和自由外链,参见Parser::handleMagicLinks
17
- * 10. 段落和列表,参见BlockLevelPass::execute
18
- * 11. 转换,参见LanguageConverter::recursiveConvertTopLevel
19
- */
20
-
21
- /*
22
- * \0\d+.\x7F标记Token:
23
- * e: ExtToken
24
- * a: AttributeToken
25
- * c: CommentToken、NoIncludeToken和IncludeToken
26
- * !: `{{!}}`专用
27
- * {: `{{(!}}`专用
28
- * }: `{{!)}}`专用
29
- * -: `{{!-}}`专用
30
- * +: `{{!!}}`专用
31
- * ~: `{{=}}`专用
32
- * s: `{{{|subst:}}}`
33
- * m: `{{fullurl:}}`、`{{canonicalurl:}}`或`{{filepath:}}`
34
- * t: ArgToken或TranscludeToken
35
- * h: HeadingToken
36
- * x: HtmlToken
37
- * b: TableToken
38
- * r: HrToken
39
- * u: DoubleUnderscoreToken
40
- * l: LinkToken
41
- * q: QuoteToken
42
- * w: ExtLinkToken
43
- * d: ListToken
44
- * v: ConverterToken
45
- */
46
-
47
- const {text} = require('../util/string'),
48
- Parser = require('..'),
49
- AstElement = require('../lib/element'),
50
- AstText = require('../lib/text');
51
- const {MAX_STAGE} = Parser;
52
-
53
- /**
54
- * 所有节点的基类
55
- * @classdesc `{childNodes: ...(AstText|Token)}`
56
- */
57
- class Token extends AstElement {
58
- type = 'root';
59
- #stage = 0; // 解析阶段,参见顶部注释。只对plain Token有意义。
60
- #config;
61
- // 这个数组起两个作用:1. 数组中的Token会在build时替换`/\0\d+.\x7F/`标记;2. 数组中的Token会依次执行parseOnce和build方法。
62
- #accum;
63
- /** @type {boolean} */ #include;
64
-
65
- /**
66
- * 将维基语法替换为占位符
67
- * @param {number} n 解析阶段
68
- * @param {boolean} include 是否嵌入
69
- */
70
- #parseOnce = (n = this.#stage, include = false) => {
71
- if (n < this.#stage || !this.isPlain() || this.length === 0) {
72
- return this;
73
- }
74
- switch (n) {
75
- case 0:
76
- if (this.type === 'root') {
77
- this.#accum.shift();
78
- }
79
- this.#include = Boolean(include);
80
- this.#parseCommentAndExt(include);
81
- break;
82
- case 1:
83
- this.#parseBrackets();
84
- break;
85
- case 2:
86
- this.#parseHtml();
87
- break;
88
- case 3:
89
- this.#parseTable();
90
- break;
91
- case 4:
92
- this.#parseHrAndDoubleUndescore();
93
- break;
94
- case 5:
95
- this.#parseLinks();
96
- break;
97
- case 6:
98
- this.#parseQuotes();
99
- break;
100
-
101
- case 7:
102
- this.#parseExternalLinks();
103
- break;
104
- case 8:
105
- this.#parseMagicLinks();
106
- break;
107
- case 9:
108
- this.#parseList();
109
- break;
110
- case 10:
111
- this.#parseConverter();
112
- // no default
113
- }
114
- if (this.type === 'root') {
115
- for (const token of this.#accum) {
116
- token.getAttribute('parseOnce')(n, include);
117
- }
118
- }
119
- this.#stage++;
120
- return this;
121
- };
122
-
123
- /**
124
- * 重建wikitext
125
- * @template {string} T
126
- * @param {string} str 半解析的字符串
127
- * @param {T} type 返回类型
128
- * @complexity `n`
129
- * @returns {T extends 'string|text' ? string : (Token|AstText)[]}
130
- */
131
- #buildFromStr = (str, type) => {
132
- const nodes = str.split(/[\0\x7F]/u).map((s, i) => {
133
- if (i % 2 === 0) {
134
- return new AstText(s);
135
- } else if (isNaN(s.at(-1))) {
136
- return this.#accum[Number(s.slice(0, -1))];
137
- }
138
- throw new Error(`解析错误!未正确标记的 Token:${s}`);
139
- });
140
- if (type === 'string') {
141
- return nodes.map(String).join('');
142
- } else if (type === 'text') {
143
- return text(nodes);
144
- }
145
- return nodes;
146
- };
147
-
148
- /**
149
- * 将占位符替换为子Token
150
- * @complexity `n`
151
- */
152
- #build = () => {
153
- this.#stage = MAX_STAGE;
154
- const {length, firstChild} = this,
155
- str = String(firstChild);
156
- if (length === 1 && firstChild.type === 'text' && str.includes('\0')) {
157
- this.replaceChildren(...this.#buildFromStr(str));
158
- this.normalize();
159
- if (this.type === 'root') {
160
- for (const token of this.#accum) {
161
- token.getAttribute('build')();
162
- }
163
- }
164
- }
165
- };
166
-
167
- /**
168
- * @param {string} wikitext wikitext
169
- * @param {accum} accum
170
- */
171
- constructor(wikitext, config = Parser.getConfig(), halfParsed = false, accum = [], acceptable = undefined) {
172
- super();
173
- if (typeof wikitext === 'string') {
174
- this.insertAt(halfParsed ? wikitext : wikitext.replace(/[\0\x7F]/gu, ''));
175
- }
176
- this.#config = config;
177
- this.#accum = accum;
178
- accum.push(this);
179
- }
180
-
181
- /**
182
- * @override
183
- * @template {string} T
184
- * @param {T} key 属性键
185
- * @returns {TokenAttribute<T>}
186
- */
187
- getAttribute(key) {
188
- switch (key) {
189
- case 'config':
190
- return structuredClone(this.#config);
191
- case 'accum':
192
- return this.#accum;
193
- case 'parseOnce':
194
- return this.#parseOnce;
195
- case 'buildFromStr':
196
- return this.#buildFromStr;
197
- case 'build':
198
- return this.#build;
199
- case 'include': {
200
- if (this.#include !== undefined) {
201
- return this.#include;
202
- }
203
- const root = this.getRootNode();
204
- if (root.type === 'root' && root !== this) {
205
- return root.getAttribute('include');
206
- }
207
- return false;
208
- }
209
- default:
210
- return super.getAttribute(key);
211
- }
212
- }
213
-
214
- /**
215
- * @override
216
- * @template {string} T
217
- * @param {T} key 属性键
218
- * @param {TokenAttribute<T>} value 属性值
219
- */
220
- setAttribute(key, value) {
221
- switch (key) {
222
- case 'stage':
223
- if (this.#stage === 0 && this.type === 'root') {
224
- this.#accum.shift();
225
- }
226
- this.#stage = value;
227
- return this;
228
- default:
229
- return super.setAttribute(key, value);
230
- }
231
- }
232
-
233
- /** 是否是普通节点 */
234
- isPlain() {
235
- return this.constructor === Token;
236
- }
237
-
238
- /**
239
- * @override
240
- * @template {string|Token} T
241
- * @param {T} token 待插入的子节点
242
- * @param {number} i 插入位置
243
- * @complexity `n`
244
- * @returns {T extends Token ? Token : AstText}
245
- */
246
- insertAt(token, i = this.length) {
247
- if (typeof token === 'string') {
248
- token = new AstText(token);
249
- }
250
- super.insertAt(token, i);
251
- if (token.type === 'root') {
252
- token.type = 'plain';
253
- }
254
- return token;
255
- }
256
-
257
- /**
258
- * 规范化页面标题
259
- * @param {string} title 标题(含或不含命名空间前缀)
260
- * @param {number} defaultNs 命名空间
261
- * @param {boolean} decode 是否需要解码
262
- * @param {boolean} selfLink 是否允许selfLink
263
- */
264
- normalizeTitle(title, defaultNs = 0, halfParsed = false, decode = false, selfLink = false) {
265
- return Parser.normalizeTitle(title, defaultNs, this.#include, this.#config, halfParsed, decode, selfLink);
266
- }
267
-
268
- /** 生成部分Token的`name`属性 */
269
- afterBuild() {
270
- if (this.type === 'root') {
271
- for (const token of this.#accum) {
272
- token.afterBuild();
273
- }
274
- }
275
- }
276
-
277
- /**
278
- * 解析、重构、生成部分Token的`name`属性
279
- * @param {number} n 最大解析层级
280
- * @param {boolean} include 是否嵌入
281
- */
282
- parse(n = MAX_STAGE, include = false) {
283
- while (this.#stage < n) {
284
- this.#parseOnce(this.#stage, include);
285
- }
286
- if (n) {
287
- this.#build();
288
- this.afterBuild();
289
- }
290
- return this;
291
- }
292
-
293
- /**
294
- * 解析HTML注释和扩展标签
295
- * @param {boolean} includeOnly 是否嵌入
296
- */
297
- #parseCommentAndExt(includeOnly) {
298
- const parseCommentAndExt = require('../parser/commentAndExt');
299
- this.setText(parseCommentAndExt(String(this.firstChild), this.#config, this.#accum, includeOnly));
300
- }
301
-
302
- /** 解析花括号 */
303
- #parseBrackets() {
304
- const parseBrackets = require('../parser/brackets');
305
- const str = this.type === 'root' ? String(this.firstChild) : `\0${String(this.firstChild)}`,
306
- parsed = parseBrackets(str, this.#config, this.#accum);
307
- this.setText(this.type === 'root' ? parsed : parsed.slice(1));
308
- }
309
-
310
- /** 解析HTML标签 */
311
- #parseHtml() {
312
- if (this.#config.excludes.includes('html')) {
313
- return;
314
- }
315
- const parseHtml = require('../parser/html');
316
- this.setText(parseHtml(String(this.firstChild), this.#config, this.#accum));
317
- }
318
-
319
- /** 解析表格 */
320
- #parseTable() {
321
- if (this.#config.excludes.includes('table')) {
322
- return;
323
- }
324
- const parseTable = require('../parser/table'),
325
- TableToken = require('./table');
326
- this.setText(parseTable(this, this.#config, this.#accum));
327
- for (const table of this.#accum) {
328
- if (table instanceof TableToken && table.type !== 'td') {
329
- table.normalize();
330
- const {childNodes: [, child]} = table;
331
- if (typeof child === 'string' && child.includes('\0')) {
332
- table.removeAt(1);
333
- const inner = new Token(child, this.#config, true, this.#accum);
334
- table.insertAt(inner, 1);
335
- inner.setAttribute('stage', 4);
336
- }
337
- }
338
- }
339
- }
340
-
341
- /** 解析\<hr\>和状态开关 */
342
- #parseHrAndDoubleUndescore() {
343
- if (this.#config.excludes.includes('hr')) {
344
- return;
345
- }
346
- const parseHrAndDoubleUnderscore = require('../parser/hrAndDoubleUnderscore');
347
- this.setText(parseHrAndDoubleUnderscore(this, this.#config, this.#accum));
348
- }
349
-
350
- /** 解析内部链接 */
351
- #parseLinks() {
352
- const parseLinks = require('../parser/links');
353
- this.setText(parseLinks(String(this.firstChild), this.#config, this.#accum));
354
- }
355
-
356
- /** 解析单引号 */
357
- #parseQuotes() {
358
- if (this.#config.excludes.includes('quote')) {
359
- return;
360
- }
361
- const parseQuotes = require('../parser/quotes');
362
- const lines = String(this.firstChild).split('\n');
363
- for (let i = 0; i < lines.length; i++) {
364
- lines[i] = parseQuotes(lines[i], this.#config, this.#accum);
365
- }
366
- this.setText(lines.join('\n'));
367
- }
368
-
369
- /** 解析外部链接 */
370
- #parseExternalLinks() {
371
- if (this.#config.excludes.includes('extLink')) {
372
- return;
373
- }
374
- const parseExternalLinks = require('../parser/externalLinks');
375
- this.setText(parseExternalLinks(String(this.firstChild), this.#config, this.#accum));
376
- }
377
-
378
- /** 解析自由外链 */
379
- #parseMagicLinks() {
380
- if (this.#config.excludes.includes('magicLink')) {
381
- return;
382
- }
383
- const parseMagicLinks = require('../parser/magicLinks');
384
- this.setText(parseMagicLinks(String(this.firstChild), this.#config, this.#accum));
385
- }
386
-
387
- /** 解析列表 */
388
- #parseList() {
389
- if (this.#config.excludes.includes('list')) {
390
- return;
391
- }
392
- const parseList = require('../parser/list');
393
- const lines = String(this.firstChild).split('\n');
394
- let i = this.type === 'root' || this.type === 'ext-inner' && this.name === 'poem' ? 0 : 1;
395
- for (; i < lines.length; i++) {
396
- lines[i] = parseList(lines[i], this.#config, this.#accum);
397
- }
398
- this.setText(lines.join('\n'));
399
- }
400
-
401
- /** 解析语言变体转换 */
402
- #parseConverter() {
403
- if (this.#config.variants?.length > 0) {
404
- const parseConverter = require('../parser/converter');
405
- this.setText(parseConverter(String(this.firstChild), this.#config, this.#accum));
406
- }
407
- }
408
- }
409
-
410
- module.exports = Token;