wikiparser-node 1.13.1-b → 1.13.1
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.
- package/config/.schema.json +203 -0
- package/config/default.json +32 -31
- package/config/enwiki.json +829 -15
- package/config/llwiki.json +56 -21
- package/config/moegirl.json +65 -21
- package/config/zhwiki.json +498 -32
- package/dist/addon/table.js +494 -0
- package/dist/addon/token.js +392 -0
- package/dist/addon/transclude.js +184 -0
- package/dist/base.d.ts +110 -0
- package/dist/base.js +67 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +279 -0
- package/dist/internal.d.ts +47 -0
- package/dist/lib/element.d.ts +125 -0
- package/dist/lib/element.js +364 -0
- package/dist/lib/node.d.ts +173 -0
- package/dist/lib/node.js +478 -0
- package/dist/lib/range.d.ts +105 -0
- package/dist/lib/range.js +406 -0
- package/dist/lib/ranges.d.ts +28 -0
- package/dist/lib/ranges.js +126 -0
- package/dist/lib/rect.d.ts +18 -0
- package/dist/lib/rect.js +36 -0
- package/dist/lib/text.d.ts +58 -0
- package/dist/lib/text.js +414 -0
- package/dist/lib/title.d.ts +49 -0
- package/dist/lib/title.js +251 -0
- package/dist/mixin/attributesParent.d.ts +49 -0
- package/dist/mixin/attributesParent.js +80 -0
- package/dist/mixin/fixed.d.ts +5 -0
- package/dist/mixin/fixed.js +32 -0
- package/dist/mixin/flagsParent.d.ts +43 -0
- package/dist/mixin/flagsParent.js +64 -0
- package/dist/mixin/hidden.d.ts +7 -0
- package/dist/mixin/hidden.js +39 -0
- package/dist/mixin/magicLinkParent.d.ts +19 -0
- package/dist/mixin/magicLinkParent.js +43 -0
- package/dist/mixin/singleLine.d.ts +5 -0
- package/dist/mixin/singleLine.js +25 -0
- package/dist/mixin/sol.d.ts +6 -0
- package/dist/mixin/sol.js +45 -0
- package/dist/mixin/syntax.d.ts +8 -0
- package/dist/mixin/syntax.js +46 -0
- package/dist/parser/braces.js +152 -0
- package/dist/parser/commentAndExt.js +84 -0
- package/dist/parser/converter.js +41 -0
- package/dist/parser/externalLinks.js +39 -0
- package/dist/parser/hrAndDoubleUnderscore.js +44 -0
- package/dist/parser/html.js +40 -0
- package/dist/parser/links.js +103 -0
- package/dist/parser/list.js +116 -0
- package/dist/parser/magicLinks.js +55 -0
- package/dist/parser/quotes.js +69 -0
- package/dist/parser/redirect.js +28 -0
- package/dist/parser/selector.js +443 -0
- package/dist/parser/table.js +125 -0
- package/dist/src/arg.d.ts +49 -0
- package/dist/src/arg.js +220 -0
- package/dist/src/atom.d.ts +14 -0
- package/dist/src/atom.js +54 -0
- package/dist/src/attribute.d.ts +64 -0
- package/dist/src/attribute.js +482 -0
- package/dist/src/attributes.d.ts +103 -0
- package/dist/src/attributes.js +383 -0
- package/dist/src/converter.d.ts +28 -0
- package/dist/src/converter.js +153 -0
- package/dist/src/converterFlags.d.ts +80 -0
- package/dist/src/converterFlags.js +241 -0
- package/dist/src/converterRule.d.ts +71 -0
- package/dist/src/converterRule.js +218 -0
- package/dist/src/extLink.d.ts +36 -0
- package/dist/src/extLink.js +223 -0
- package/dist/src/gallery.d.ts +51 -0
- package/dist/src/gallery.js +166 -0
- package/dist/src/heading.d.ts +44 -0
- package/dist/src/heading.js +222 -0
- package/dist/src/hidden.d.ts +9 -0
- package/dist/src/hidden.js +82 -0
- package/dist/src/html.d.ts +61 -0
- package/dist/src/html.js +344 -0
- package/dist/src/imageParameter.d.ts +60 -0
- package/dist/src/imageParameter.js +262 -0
- package/dist/src/imagemap.d.ts +47 -0
- package/dist/src/imagemap.js +148 -0
- package/dist/src/imagemapLink.d.ts +35 -0
- package/dist/src/imagemapLink.js +99 -0
- package/dist/src/index.d.ts +136 -0
- package/dist/src/index.js +790 -0
- package/dist/src/link/base.d.ts +52 -0
- package/dist/src/link/base.js +258 -0
- package/dist/src/link/category.d.ts +22 -0
- package/dist/src/link/category.js +36 -0
- package/dist/src/link/file.d.ts +102 -0
- package/dist/src/link/file.js +345 -0
- package/dist/src/link/galleryImage.d.ts +29 -0
- package/dist/src/link/galleryImage.js +133 -0
- package/dist/src/link/index.d.ts +39 -0
- package/dist/src/link/index.js +100 -0
- package/dist/src/link/redirectTarget.d.ts +27 -0
- package/dist/src/link/redirectTarget.js +71 -0
- package/dist/src/magicLink.d.ts +57 -0
- package/dist/src/magicLink.js +261 -0
- package/dist/src/nested.d.ts +40 -0
- package/dist/src/nested.js +108 -0
- package/dist/src/nowiki/base.d.ts +28 -0
- package/dist/src/nowiki/base.js +90 -0
- package/dist/src/nowiki/comment.d.ts +14 -0
- package/dist/src/nowiki/comment.js +123 -0
- package/dist/src/nowiki/dd.d.ts +8 -0
- package/dist/src/nowiki/dd.js +74 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
- package/dist/src/nowiki/doubleUnderscore.js +101 -0
- package/dist/src/nowiki/hr.d.ts +5 -0
- package/dist/src/nowiki/hr.js +72 -0
- package/dist/src/nowiki/index.d.ts +14 -0
- package/dist/src/nowiki/index.js +30 -0
- package/dist/src/nowiki/list.d.ts +5 -0
- package/dist/src/nowiki/list.js +67 -0
- package/dist/src/nowiki/listBase.d.ts +23 -0
- package/dist/src/nowiki/listBase.js +100 -0
- package/dist/src/nowiki/noinclude.d.ts +6 -0
- package/dist/src/nowiki/noinclude.js +77 -0
- package/dist/src/nowiki/quote.d.ts +14 -0
- package/dist/src/nowiki/quote.js +149 -0
- package/dist/src/onlyinclude.d.ts +13 -0
- package/dist/src/onlyinclude.js +60 -0
- package/dist/src/paramTag/index.d.ts +28 -0
- package/dist/src/paramTag/index.js +80 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -0
- package/dist/src/paramTag/inputbox.js +38 -0
- package/dist/src/parameter.d.ts +60 -0
- package/dist/src/parameter.js +267 -0
- package/dist/src/pre.d.ts +28 -0
- package/dist/src/pre.js +70 -0
- package/dist/src/redirect.d.ts +30 -0
- package/dist/src/redirect.js +128 -0
- package/dist/src/syntax.d.ts +15 -0
- package/dist/src/syntax.js +87 -0
- package/dist/src/table/base.d.ts +28 -0
- package/dist/src/table/base.js +81 -0
- package/dist/src/table/index.d.ts +230 -0
- package/dist/src/table/index.js +506 -0
- package/dist/src/table/td.d.ts +72 -0
- package/dist/src/table/td.js +375 -0
- package/dist/src/table/tr.d.ts +30 -0
- package/dist/src/table/tr.js +61 -0
- package/dist/src/table/trBase.d.ts +49 -0
- package/dist/src/table/trBase.js +165 -0
- package/dist/src/tagPair/ext.d.ts +29 -0
- package/dist/src/tagPair/ext.js +229 -0
- package/dist/src/tagPair/include.d.ts +33 -0
- package/dist/src/tagPair/include.js +145 -0
- package/dist/src/tagPair/index.d.ts +23 -0
- package/dist/src/tagPair/index.js +130 -0
- package/dist/src/transclude.d.ts +159 -0
- package/dist/src/transclude.js +598 -0
- package/dist/util/constants.js +26 -0
- package/dist/util/debug.js +95 -0
- package/dist/util/diff.js +83 -0
- package/dist/util/html.js +146 -0
- package/dist/util/lint.js +32 -0
- package/dist/util/string.js +107 -0
- package/errors/README +3 -0
- package/package.json +21 -28
- package/printed/README +3 -0
- package/bundle/bundle.min.js +0 -37
- package/extensions/dist/base.js +0 -163
- package/extensions/dist/codejar.js +0 -53
- package/extensions/dist/editor.js +0 -159
- package/extensions/dist/highlight.js +0 -30
- package/extensions/dist/lint.js +0 -72
- package/extensions/editor.css +0 -59
- package/extensions/ui.css +0 -162
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const constants_1 = require("../util/constants");
|
|
6
|
+
const debug_1 = require("../util/debug");
|
|
7
|
+
const string_1 = require("../util/string");
|
|
8
|
+
const index_1 = require("../index");
|
|
9
|
+
const index_2 = require("../src/index");
|
|
10
|
+
const comment_1 = require("../src/nowiki/comment");
|
|
11
|
+
const include_1 = require("../src/tagPair/include");
|
|
12
|
+
const ext_1 = require("../src/tagPair/ext");
|
|
13
|
+
const html_1 = require("../src/html");
|
|
14
|
+
const attributes_1 = require("../src/attributes");
|
|
15
|
+
index_2.Token.prototype.createComment = /** @implements */ function (data = '') {
|
|
16
|
+
const config = this.getAttribute('config');
|
|
17
|
+
// @ts-expect-error abstract class
|
|
18
|
+
return debug_1.Shadow.run(() => new comment_1.CommentToken(data.replaceAll('-->', '-->'), true, config));
|
|
19
|
+
};
|
|
20
|
+
index_2.Token.prototype.createElement = /** @implements */ function (tagName, { selfClosing, closing } = {}) {
|
|
21
|
+
const config = this.getAttribute('config'), include = this.getAttribute('include');
|
|
22
|
+
if (tagName === (include ? 'noinclude' : 'includeonly')) {
|
|
23
|
+
return debug_1.Shadow.run(
|
|
24
|
+
// @ts-expect-error abstract class
|
|
25
|
+
() => new include_1.IncludeToken(tagName, '', undefined, selfClosing ? undefined : tagName, config));
|
|
26
|
+
}
|
|
27
|
+
else if (config.ext.includes(tagName)) {
|
|
28
|
+
// @ts-expect-error abstract class
|
|
29
|
+
return debug_1.Shadow.run(() => new ext_1.ExtToken(tagName, '', undefined, selfClosing ? undefined : '', config));
|
|
30
|
+
}
|
|
31
|
+
else if (config.html.some(tags => tags.includes(tagName))) {
|
|
32
|
+
return debug_1.Shadow.run(() => {
|
|
33
|
+
// @ts-expect-error abstract class
|
|
34
|
+
const attr = new attributes_1.AttributesToken(undefined, 'html-attrs', tagName, config);
|
|
35
|
+
attr.afterBuild();
|
|
36
|
+
// @ts-expect-error abstract class
|
|
37
|
+
return new html_1.HtmlToken(tagName, attr, Boolean(closing), Boolean(selfClosing), config);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
throw new RangeError(`Invalid tag name: ${tagName}`);
|
|
41
|
+
};
|
|
42
|
+
index_2.Token.prototype.caretPositionFromIndex = /** @implements */ function (index) {
|
|
43
|
+
if (index === undefined) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const { length } = this.toString();
|
|
47
|
+
if (index >= length || index < -length) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
index += index < 0 ? length : 0;
|
|
51
|
+
let self = this, acc = 0, start = 0;
|
|
52
|
+
while (self.type !== 'text') {
|
|
53
|
+
const { childNodes } = self;
|
|
54
|
+
acc += self.getAttribute('padding');
|
|
55
|
+
for (let i = 0; acc <= index && i < childNodes.length; i++) {
|
|
56
|
+
const cur = childNodes[i], l = cur.toString().length;
|
|
57
|
+
acc += l;
|
|
58
|
+
if (acc > index) {
|
|
59
|
+
self = cur;
|
|
60
|
+
acc -= l;
|
|
61
|
+
start = acc;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
acc += self.getGaps(i);
|
|
65
|
+
}
|
|
66
|
+
if (self.childNodes === childNodes) {
|
|
67
|
+
return { offsetNode: self, offset: index - start };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { offsetNode: self, offset: index - start };
|
|
71
|
+
};
|
|
72
|
+
index_2.Token.prototype.sections = /** @implements */ function () {
|
|
73
|
+
if (this.type !== 'root') {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const { childNodes, length } = this, headings = [...childNodes.entries()]
|
|
77
|
+
.filter((entry) => entry[1].type === 'heading')
|
|
78
|
+
.map(([i, { level }]) => [i, level]), lastHeading = [-1, -1, -1, -1, -1, -1], sections = headings.map(([i]) => {
|
|
79
|
+
const range = this.createRange();
|
|
80
|
+
range.setStart(this, i);
|
|
81
|
+
return range;
|
|
82
|
+
});
|
|
83
|
+
for (const [i, [index, level]] of headings.entries()) {
|
|
84
|
+
for (let j = level; j < 6; j++) {
|
|
85
|
+
const last = lastHeading[j];
|
|
86
|
+
if (last >= 0) {
|
|
87
|
+
sections[last].setEnd(this, index);
|
|
88
|
+
}
|
|
89
|
+
lastHeading[j] = j === level ? i : -1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const last of lastHeading) {
|
|
93
|
+
if (last >= 0) {
|
|
94
|
+
sections[last].setEnd(this, length);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const range = this.createRange();
|
|
98
|
+
range.setStart(this, 0);
|
|
99
|
+
range.setEnd(this, headings[0]?.[0] ?? length);
|
|
100
|
+
sections.unshift(range);
|
|
101
|
+
return sections;
|
|
102
|
+
};
|
|
103
|
+
index_2.Token.prototype.findEnclosingHtml = /** @implements */ function (tag) {
|
|
104
|
+
tag = tag?.toLowerCase();
|
|
105
|
+
const { html } = this.getAttribute('config'), normalTags = new Set(html[0]), voidTags = new Set(html[2]);
|
|
106
|
+
if (html[2].includes(tag)) {
|
|
107
|
+
throw new RangeError(`Void tag: ${tag}`);
|
|
108
|
+
}
|
|
109
|
+
else if (tag !== undefined && !html.slice(0, 2).some(tags => tags.includes(tag))) {
|
|
110
|
+
throw new RangeError(`Invalid tag name: ${tag}`);
|
|
111
|
+
}
|
|
112
|
+
const { parentNode } = this;
|
|
113
|
+
if (!parentNode) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 检查是否为指定的 HTML 标签
|
|
118
|
+
* @param node 节点
|
|
119
|
+
* @param name 标签名
|
|
120
|
+
* @param closing 是否为闭合标签
|
|
121
|
+
*/
|
|
122
|
+
const checkHtml = (node, name, closing) => node.is('html')
|
|
123
|
+
&& (!name && !voidTags.has(node.name) || node.name === name)
|
|
124
|
+
&& (normalTags.has(node.name) || !node.selfClosing)
|
|
125
|
+
&& node.closing === closing;
|
|
126
|
+
const { childNodes, length } = parentNode, index = childNodes.indexOf(this);
|
|
127
|
+
let i = index - 1, j = length;
|
|
128
|
+
for (; i >= 0; i--) {
|
|
129
|
+
const open = childNodes[i];
|
|
130
|
+
if (checkHtml(open, tag, false)) {
|
|
131
|
+
for (j = index + 1; j < length; j++) {
|
|
132
|
+
const close = childNodes[j];
|
|
133
|
+
if (checkHtml(close, open.name, true)) {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (j < length) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (i === -1) {
|
|
143
|
+
return parentNode.findEnclosingHtml(tag);
|
|
144
|
+
}
|
|
145
|
+
const range = this.createRange();
|
|
146
|
+
range.setStart(parentNode, i);
|
|
147
|
+
range.setEnd(parentNode, j + 1);
|
|
148
|
+
return range;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* 隐式换行
|
|
152
|
+
* @param str 字符串
|
|
153
|
+
* @param prev 前一个字符
|
|
154
|
+
*/
|
|
155
|
+
const implicitNewLine = (str, prev) => prev + (prev !== '\n' && /^(?:\{\||[:;#*])/u.test(str) ? `\n${str}` : str);
|
|
156
|
+
/**
|
|
157
|
+
* 比较两个字符串是否相等
|
|
158
|
+
* @param a
|
|
159
|
+
* @param b
|
|
160
|
+
*/
|
|
161
|
+
const cmp = (a, b) => a === b || Boolean(a && b) && Number(a) === Number(b);
|
|
162
|
+
/**
|
|
163
|
+
* 展开模板
|
|
164
|
+
* @param wikitext
|
|
165
|
+
* @param config
|
|
166
|
+
* @param include
|
|
167
|
+
* @param context 模板调用环境
|
|
168
|
+
* @param accum
|
|
169
|
+
* @param stack 模板调用栈
|
|
170
|
+
*/
|
|
171
|
+
const expand = (wikitext, config, include, context, accum = [], stack = []) => {
|
|
172
|
+
const magicWords = new Set(['if', 'ifeq', 'ifexist', 'switch']), n = accum.length, token = new index_2.Token(wikitext, config, accum);
|
|
173
|
+
token.type = 'root';
|
|
174
|
+
token.parseOnce(0, include);
|
|
175
|
+
if (context !== false) {
|
|
176
|
+
token.setText((0, string_1.removeCommentLine)(token.firstChild.toString(), true));
|
|
177
|
+
}
|
|
178
|
+
token.parseOnce();
|
|
179
|
+
for (const plain of [...accum.slice(n), token]) {
|
|
180
|
+
if (plain.length !== 1 || plain.firstChild.type !== 'text') {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const { data } = plain.firstChild;
|
|
184
|
+
if (!/\0\d+t\x7F/u.test(data)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const expanded = data.replace(/([^\x7F]?)\0(\d+)t\x7F/gu, (m, prev, i) => {
|
|
188
|
+
const target = accum[i], { type, name, length, firstChild: f } = target;
|
|
189
|
+
if (type === 'arg') {
|
|
190
|
+
const arg = (0, string_1.removeCommentLine)(f.toString()).trim();
|
|
191
|
+
if (/\0\d+t\x7F/u.test(arg)) {
|
|
192
|
+
return m;
|
|
193
|
+
}
|
|
194
|
+
else if (!context || !context.hasArg(arg)) {
|
|
195
|
+
const effective = target.childNodes[1] ?? target;
|
|
196
|
+
// @ts-expect-error sparse array
|
|
197
|
+
accum[accum.indexOf(length === 1 ? f : effective)] = undefined;
|
|
198
|
+
return prev + effective.toString();
|
|
199
|
+
}
|
|
200
|
+
// @ts-expect-error sparse array
|
|
201
|
+
accum[accum.indexOf(context.getArg(arg).lastChild)] = undefined;
|
|
202
|
+
return prev + context.getValue(arg);
|
|
203
|
+
}
|
|
204
|
+
else if (type === 'template') {
|
|
205
|
+
if (context === false) {
|
|
206
|
+
return m;
|
|
207
|
+
}
|
|
208
|
+
const c = target.getAttribute('config'), t = index_1.default.normalizeTitle((0, string_1.removeComment)(f.toString()), 10, include, c, true), { title, valid } = t;
|
|
209
|
+
if (!valid) {
|
|
210
|
+
// @ts-expect-error sparse array
|
|
211
|
+
accum[accum.indexOf(target)] = undefined;
|
|
212
|
+
// @ts-expect-error sparse array
|
|
213
|
+
accum[accum.indexOf(f)] = undefined;
|
|
214
|
+
return prev + target.toString();
|
|
215
|
+
}
|
|
216
|
+
else if (!index_1.default.templates.has(title)) {
|
|
217
|
+
if (index_1.default.templateDir === undefined) {
|
|
218
|
+
return m;
|
|
219
|
+
}
|
|
220
|
+
else if (!path.isAbsolute(index_1.default.templateDir)) {
|
|
221
|
+
index_1.default.templateDir = path.join(__dirname, '..', '..', index_1.default.templateDir);
|
|
222
|
+
}
|
|
223
|
+
const titles = [title, title.replaceAll('_', ' ')].flatMap(tt => [tt, tt.replaceAll(':', '꞉')]), file = ['.wiki', '.txt', '']
|
|
224
|
+
.flatMap(ext => titles.map(tt => path.join(index_1.default.templateDir, tt + ext)))
|
|
225
|
+
.find(fs.existsSync);
|
|
226
|
+
if (!file) {
|
|
227
|
+
return m;
|
|
228
|
+
}
|
|
229
|
+
index_1.default.templates.set(title, fs.readFileSync(file, 'utf8'));
|
|
230
|
+
}
|
|
231
|
+
else if (stack.includes(title)) {
|
|
232
|
+
return `${prev}<span class="error">Template loop detected: [[${title}]]</span>`;
|
|
233
|
+
}
|
|
234
|
+
return implicitNewLine(expand(index_1.default.templates.get(title), config, true, target, accum, [...stack, title]).toString(), prev);
|
|
235
|
+
}
|
|
236
|
+
else if (!magicWords.has(name)) {
|
|
237
|
+
return m;
|
|
238
|
+
}
|
|
239
|
+
else if (length < 3 || name === 'ifeq' && length === 3) {
|
|
240
|
+
return prev;
|
|
241
|
+
}
|
|
242
|
+
const c = target.childNodes, var1 = (0, string_1.decodeHtml)(c[1].value), var2 = (0, string_1.decodeHtml)(c[2].value), known = !/\0\d+t\x7F/u.test(var1);
|
|
243
|
+
if (known && (name === 'if' || name === 'ifexist')) {
|
|
244
|
+
let bool = Boolean(var1);
|
|
245
|
+
if (name === 'ifexist') {
|
|
246
|
+
const title = index_1.default.normalizeTitle(var1, 0, include, config, true);
|
|
247
|
+
bool = title.valid && !title.interwiki;
|
|
248
|
+
}
|
|
249
|
+
const effective = c[bool ? 2 : 3];
|
|
250
|
+
if (effective) {
|
|
251
|
+
// @ts-expect-error sparse array
|
|
252
|
+
accum[accum.indexOf(effective.lastChild)] = undefined;
|
|
253
|
+
return implicitNewLine(effective.value, prev);
|
|
254
|
+
}
|
|
255
|
+
return prev;
|
|
256
|
+
}
|
|
257
|
+
else if (known && name === 'ifeq' && !/\0\d+t\x7F/u.test(var2)) {
|
|
258
|
+
const effective = c[cmp(var1, var2) ? 3 : 4];
|
|
259
|
+
if (effective) {
|
|
260
|
+
// @ts-expect-error sparse array
|
|
261
|
+
accum[accum.indexOf(effective.lastChild)] = undefined;
|
|
262
|
+
return implicitNewLine(effective.value, prev);
|
|
263
|
+
}
|
|
264
|
+
return prev;
|
|
265
|
+
}
|
|
266
|
+
else if (known && name === 'switch') {
|
|
267
|
+
let defaultVal = '', found = false, transclusion = false, defaultParam;
|
|
268
|
+
for (let j = 2; j < length; j++) {
|
|
269
|
+
const { anon, value, lastChild, name: option } = c[j];
|
|
270
|
+
transclusion = /\0\d+t\x7F/u.test(anon ? value : option);
|
|
271
|
+
if (anon) {
|
|
272
|
+
if (j === length - 1) {
|
|
273
|
+
// @ts-expect-error sparse array
|
|
274
|
+
accum[accum.indexOf(lastChild)] = undefined;
|
|
275
|
+
return implicitNewLine(value, prev);
|
|
276
|
+
}
|
|
277
|
+
else if (transclusion) {
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
found ||= cmp(var1, (0, string_1.decodeHtml)(value)) || value === '#default';
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else if (transclusion) {
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
else if (found || cmp(var1, (0, string_1.decodeHtml)(option))) {
|
|
288
|
+
// @ts-expect-error sparse array
|
|
289
|
+
accum[accum.indexOf(lastChild)] = undefined;
|
|
290
|
+
return implicitNewLine(value, prev);
|
|
291
|
+
}
|
|
292
|
+
else if (option.toLowerCase() === '#default') {
|
|
293
|
+
defaultVal = value;
|
|
294
|
+
defaultParam = lastChild;
|
|
295
|
+
}
|
|
296
|
+
if (j === length - 1) {
|
|
297
|
+
if (defaultParam) {
|
|
298
|
+
// @ts-expect-error sparse array
|
|
299
|
+
accum[accum.indexOf(defaultParam)] = undefined;
|
|
300
|
+
}
|
|
301
|
+
return implicitNewLine(defaultVal, prev);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return m;
|
|
306
|
+
});
|
|
307
|
+
plain.setText(expanded);
|
|
308
|
+
if (plain.type === 'parameter-key') {
|
|
309
|
+
plain.parentNode.trimName((0, string_1.removeCommentLine)(expanded));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return token;
|
|
313
|
+
};
|
|
314
|
+
index_2.Token.prototype.expand = /** @implements */ function () {
|
|
315
|
+
return debug_1.Shadow.run(() => expand(this.toString(), this.getAttribute('config'), this.getAttribute('include')).parse());
|
|
316
|
+
};
|
|
317
|
+
index_2.Token.prototype.solveConst = /** @implements */ function () {
|
|
318
|
+
return debug_1.Shadow.run(() => expand(this.toString(), this.getAttribute('config'), this.getAttribute('include'), false).parse());
|
|
319
|
+
};
|
|
320
|
+
index_2.Token.prototype.toHtml = /** @implements */ function () {
|
|
321
|
+
if (this.type !== 'root') {
|
|
322
|
+
return this.cloneNode().toHtmlInternal();
|
|
323
|
+
}
|
|
324
|
+
const expanded = this.expand();
|
|
325
|
+
constants_1.states.set(expanded, { headings: new Set() });
|
|
326
|
+
const lines = expanded.toHtmlInternal().split('\n'), blockElems = 'table|h1|h2|h3|h4|h5|h6|pre|p|ul|ol|dl', antiBlockElems = 'td|th', openRegex = new RegExp(String.raw `<(?:${blockElems}|\/(?:${antiBlockElems})|\/?(?:tr|caption|dt|dd|li))\b`, 'iu'), closeRegex = new RegExp(String.raw `<(?:\/(?:${blockElems})|${antiBlockElems}|\/?(?:center|blockquote|div|hr|figure))\b`, 'iu');
|
|
327
|
+
let output = '', inBlockElem = false, pendingPTag = false, inBlockquote = false, lastParagraph = '';
|
|
328
|
+
const /** @ignore */ closeParagraph = () => {
|
|
329
|
+
if (lastParagraph) {
|
|
330
|
+
const result = `</${lastParagraph}>\n`;
|
|
331
|
+
lastParagraph = '';
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
return '';
|
|
335
|
+
};
|
|
336
|
+
for (let line of lines) {
|
|
337
|
+
const openMatch = openRegex.test(line), closeMatch = closeRegex.test(line);
|
|
338
|
+
if (openMatch || closeMatch) {
|
|
339
|
+
const blockquote = /<(\/?)blockquote[\s>](?!.*<\/?blockquote[\s>])/iu.exec(line)?.[1];
|
|
340
|
+
inBlockquote = blockquote === undefined ? inBlockquote : blockquote === '';
|
|
341
|
+
pendingPTag = false;
|
|
342
|
+
output += closeParagraph();
|
|
343
|
+
inBlockElem = !closeMatch;
|
|
344
|
+
}
|
|
345
|
+
else if (!inBlockElem) {
|
|
346
|
+
if (line.startsWith(' ') && (lastParagraph === 'pre' || line.trim()) && !inBlockquote) {
|
|
347
|
+
if (lastParagraph !== 'pre') {
|
|
348
|
+
pendingPTag = false;
|
|
349
|
+
output += `${closeParagraph()}<pre>`;
|
|
350
|
+
lastParagraph = 'pre';
|
|
351
|
+
}
|
|
352
|
+
line = line.slice(1);
|
|
353
|
+
}
|
|
354
|
+
else if (/^(?:<link\b[^>]*>\s*)+$/iu.test(line)) {
|
|
355
|
+
if (pendingPTag) {
|
|
356
|
+
output += closeParagraph();
|
|
357
|
+
pendingPTag = false;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else if (!line.trim()) {
|
|
361
|
+
if (pendingPTag) {
|
|
362
|
+
output += `${pendingPTag}<br>`;
|
|
363
|
+
pendingPTag = false;
|
|
364
|
+
lastParagraph = 'p';
|
|
365
|
+
}
|
|
366
|
+
else if (lastParagraph === 'p') {
|
|
367
|
+
pendingPTag = '</p><p>';
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
output += closeParagraph();
|
|
371
|
+
pendingPTag = '<p>';
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else if (pendingPTag) {
|
|
375
|
+
output += pendingPTag;
|
|
376
|
+
pendingPTag = false;
|
|
377
|
+
lastParagraph = 'p';
|
|
378
|
+
}
|
|
379
|
+
else if (lastParagraph !== 'p') {
|
|
380
|
+
output += `${closeParagraph()}<p>`;
|
|
381
|
+
lastParagraph = 'p';
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (!pendingPTag) {
|
|
385
|
+
output += `${line}\n`;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
output += closeParagraph();
|
|
389
|
+
constants_1.states.delete(expanded);
|
|
390
|
+
return output.trimEnd();
|
|
391
|
+
};
|
|
392
|
+
constants_1.classes['ExtendedToken'] = __filename;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint @stylistic/operator-linebreak: [2, "before", {overrides: {"=": "after"}}] */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const constants_1 = require("../util/constants");
|
|
5
|
+
const debug_1 = require("../util/debug");
|
|
6
|
+
const string_1 = require("../util/string");
|
|
7
|
+
const index_1 = require("../index");
|
|
8
|
+
const index_2 = require("../src/index");
|
|
9
|
+
const transclude_1 = require("../src/transclude");
|
|
10
|
+
const parameter_1 = require("../src/parameter");
|
|
11
|
+
const atom_1 = require("../src/atom");
|
|
12
|
+
transclude_1.TranscludeToken.prototype.newAnonArg =
|
|
13
|
+
/** @implements */
|
|
14
|
+
function (val) {
|
|
15
|
+
const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(val, this.getAttribute('include'), undefined, config),
|
|
16
|
+
// @ts-expect-error abstract class
|
|
17
|
+
token = debug_1.Shadow.run(() => new parameter_1.ParameterToken(undefined, undefined, config));
|
|
18
|
+
token.lastChild.append(...childNodes);
|
|
19
|
+
token.afterBuild();
|
|
20
|
+
return this.insertAt(token);
|
|
21
|
+
};
|
|
22
|
+
transclude_1.TranscludeToken.prototype.setValue =
|
|
23
|
+
/** @implements */
|
|
24
|
+
function (key, value) {
|
|
25
|
+
if (!this.isTemplate()) {
|
|
26
|
+
throw new Error('TranscludeToken.setValue method is only for templates!');
|
|
27
|
+
}
|
|
28
|
+
const arg = this.getArg(key);
|
|
29
|
+
if (arg) {
|
|
30
|
+
arg.setValue(value);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const include = this.getAttribute('include'), config = this.getAttribute('config'), k = index_1.default.parse(key, include, undefined, config), v = index_1.default.parse(value, include, undefined, config),
|
|
34
|
+
// @ts-expect-error abstract class
|
|
35
|
+
token = debug_1.Shadow.run(() => new parameter_1.ParameterToken(undefined, undefined, config));
|
|
36
|
+
token.firstChild.append(...k.childNodes);
|
|
37
|
+
token.lastChild.append(...v.childNodes);
|
|
38
|
+
token.afterBuild();
|
|
39
|
+
this.insertAt(token);
|
|
40
|
+
};
|
|
41
|
+
transclude_1.TranscludeToken.prototype.replaceTemplate =
|
|
42
|
+
/** @implements */
|
|
43
|
+
function (title) {
|
|
44
|
+
if (this.type === 'magic-word') {
|
|
45
|
+
throw new Error('TranscludeToken.replaceTemplate method is only for templates!');
|
|
46
|
+
}
|
|
47
|
+
const { childNodes } = index_1.default.parse(title, this.getAttribute('include'), 2, this.getAttribute('config'));
|
|
48
|
+
this.firstChild.replaceChildren(...childNodes);
|
|
49
|
+
};
|
|
50
|
+
transclude_1.TranscludeToken.prototype.replaceModule =
|
|
51
|
+
/** @implements */
|
|
52
|
+
function (title) {
|
|
53
|
+
if (this.type !== 'magic-word' || this.name !== 'invoke') {
|
|
54
|
+
throw new Error('TranscludeToken.replaceModule method is only for modules!');
|
|
55
|
+
}
|
|
56
|
+
const config = this.getAttribute('config');
|
|
57
|
+
if (this.length === 1) {
|
|
58
|
+
index_2.Token.prototype.insertAt.call(this, debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'invoke-module', config, [], {
|
|
59
|
+
'Stage-1': ':', '!ExtToken': '',
|
|
60
|
+
})));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const { childNodes } = index_1.default.parse(title, this.getAttribute('include'), 2, config);
|
|
64
|
+
this.childNodes[1].replaceChildren(...childNodes);
|
|
65
|
+
};
|
|
66
|
+
transclude_1.TranscludeToken.prototype.replaceFunction =
|
|
67
|
+
/** @implements */
|
|
68
|
+
function (func) {
|
|
69
|
+
if (this.type !== 'magic-word' || this.name !== 'invoke') {
|
|
70
|
+
throw new Error('TranscludeToken.replaceModule method is only for modules!');
|
|
71
|
+
}
|
|
72
|
+
else if (this.length < 2) {
|
|
73
|
+
throw new Error('No module name specified!');
|
|
74
|
+
}
|
|
75
|
+
const config = this.getAttribute('config');
|
|
76
|
+
if (this.length === 2) {
|
|
77
|
+
index_2.Token.prototype.insertAt.call(this, debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'invoke-function', config, [], {
|
|
78
|
+
'Stage-1': ':', '!ExtToken': '',
|
|
79
|
+
})));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const { childNodes } = index_1.default.parse(func, this.getAttribute('include'), 2, config);
|
|
83
|
+
this.childNodes[2].replaceChildren(...childNodes);
|
|
84
|
+
};
|
|
85
|
+
transclude_1.TranscludeToken.prototype.fixDuplication =
|
|
86
|
+
/** @implements */
|
|
87
|
+
function (aggressive) {
|
|
88
|
+
if (!this.hasDuplicatedArgs()) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const duplicatedKeys = [];
|
|
92
|
+
let anonCount = this.getAnonArgs().length;
|
|
93
|
+
for (const [key, args] of this.getDuplicatedArgs()) {
|
|
94
|
+
if (args.length <= 1) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const values = new Map();
|
|
98
|
+
for (const arg of args) {
|
|
99
|
+
const val = arg.getValue().trim();
|
|
100
|
+
if (values.has(val)) {
|
|
101
|
+
values.get(val).push(arg);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
values.set(val, [arg]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let noMoreAnon = anonCount === 0 || !key.trim() || isNaN(key);
|
|
108
|
+
const emptyArgs = values.get('') ?? [], duplicatedArgs = [...values].filter(([val, { length }]) => val && length > 1).flatMap(([, curArgs]) => {
|
|
109
|
+
const anonIndex = noMoreAnon ? -1 : curArgs.findIndex(({ anon }) => anon);
|
|
110
|
+
if (anonIndex !== -1) {
|
|
111
|
+
noMoreAnon = true;
|
|
112
|
+
}
|
|
113
|
+
curArgs.splice(anonIndex, 1);
|
|
114
|
+
return curArgs;
|
|
115
|
+
}), badArgs = [...emptyArgs, ...duplicatedArgs], index = noMoreAnon ? -1 : emptyArgs.findIndex(({ anon }) => anon);
|
|
116
|
+
if (badArgs.length === args.length) {
|
|
117
|
+
badArgs.splice(index, 1);
|
|
118
|
+
}
|
|
119
|
+
else if (index !== -1) {
|
|
120
|
+
this.anonToNamed();
|
|
121
|
+
anonCount = 0;
|
|
122
|
+
}
|
|
123
|
+
for (const arg of badArgs) {
|
|
124
|
+
arg.remove();
|
|
125
|
+
}
|
|
126
|
+
let remaining = args.length - badArgs.length;
|
|
127
|
+
if (remaining === 1) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
else if (aggressive && (anonCount ? /\D\d+$/u : /(?:^|\D)\d+$/u).test(key)) {
|
|
131
|
+
let last;
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
133
|
+
/^a\d+$/u;
|
|
134
|
+
const str = key.slice(0, -/(?<!\d)\d+$/u.exec(key)[0].length), regex = new RegExp(String.raw `^${(0, string_1.escapeRegExp)(str)}\d+$`, 'u'), series = this.getAllArgs().filter(({ name }) => regex.test(name)), ordered = series.every(({ name }, i) => {
|
|
135
|
+
const j = Number(name.slice(str.length)), cmp = j <= i + 1 && (i === 0 || j >= last || name === key);
|
|
136
|
+
last = j;
|
|
137
|
+
return cmp;
|
|
138
|
+
});
|
|
139
|
+
if (ordered) {
|
|
140
|
+
for (const [i, arg] of series.entries()) {
|
|
141
|
+
const name = `${str}${i + 1}`;
|
|
142
|
+
if (arg.name !== name) {
|
|
143
|
+
if (arg.name === key) {
|
|
144
|
+
remaining--;
|
|
145
|
+
}
|
|
146
|
+
arg.rename(name, true);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (remaining > 1) {
|
|
152
|
+
index_1.default.error(`${this.type === 'template'
|
|
153
|
+
? this.name
|
|
154
|
+
: this.normalizeTitle(this.childNodes[1].toString(true), 828)
|
|
155
|
+
.title} still has ${remaining} duplicated ${key} parameters:\n${[...this.getArgs(key)].map(arg => {
|
|
156
|
+
const { top, left } = arg.getBoundingClientRect();
|
|
157
|
+
return `Line ${String(top)} Column ${String(left)}`;
|
|
158
|
+
}).join('\n')}`);
|
|
159
|
+
duplicatedKeys.push(key);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return duplicatedKeys;
|
|
164
|
+
};
|
|
165
|
+
transclude_1.TranscludeToken.prototype.escapeTables =
|
|
166
|
+
/** @implements */
|
|
167
|
+
function () {
|
|
168
|
+
if (!/\n[^\S\n]*(?::+[^\S\n]*)?\{\|/u.test(this.text())) {
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
const stripped = this.toString().slice(2, -2), include = this.getAttribute('include'), config = this.getAttribute('config'), parsed = index_1.default.parse(stripped, include, 4, config);
|
|
172
|
+
for (const table of parsed.childNodes) {
|
|
173
|
+
if (table.is('table')) {
|
|
174
|
+
table.escape();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const { firstChild, length } = index_1.default.parse(`{{${parsed.toString()}}}`, include, undefined, config);
|
|
178
|
+
if (length !== 1 || !(firstChild instanceof transclude_1.TranscludeToken)) {
|
|
179
|
+
throw new Error('Failed to escape tables!');
|
|
180
|
+
}
|
|
181
|
+
this.safeReplaceWith(firstChild);
|
|
182
|
+
return firstChild;
|
|
183
|
+
};
|
|
184
|
+
constants_1.classes['ExtendedTranscludeToken'] = __filename;
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
ext: string[];
|
|
3
|
+
readonly html: [string[], string[], string[]];
|
|
4
|
+
readonly namespaces: Record<string, string>;
|
|
5
|
+
readonly nsid: Record<string, number>;
|
|
6
|
+
readonly parserFunction: [Record<string, string>, string[], string[], string[]];
|
|
7
|
+
readonly doubleUnderscore: [string[], string[], Record<string, string>?];
|
|
8
|
+
readonly protocol: string;
|
|
9
|
+
readonly img: Record<string, string>;
|
|
10
|
+
readonly redirection: string[];
|
|
11
|
+
readonly variants: string[];
|
|
12
|
+
readonly excludes?: string[];
|
|
13
|
+
readonly interwiki: string[];
|
|
14
|
+
readonly conversionTable?: [string, string][];
|
|
15
|
+
readonly redirects?: [string, string][];
|
|
16
|
+
readonly articlePath?: string;
|
|
17
|
+
}
|
|
18
|
+
export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'list-range' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
|
|
19
|
+
export declare const stages: {
|
|
20
|
+
redirect: number;
|
|
21
|
+
onlyinclude: number;
|
|
22
|
+
noinclude: number;
|
|
23
|
+
include: number;
|
|
24
|
+
comment: number;
|
|
25
|
+
ext: number;
|
|
26
|
+
arg: number;
|
|
27
|
+
'magic-word': number;
|
|
28
|
+
template: number;
|
|
29
|
+
heading: number;
|
|
30
|
+
html: number;
|
|
31
|
+
table: number;
|
|
32
|
+
hr: number;
|
|
33
|
+
'double-underscore': number;
|
|
34
|
+
link: number;
|
|
35
|
+
category: number;
|
|
36
|
+
file: number;
|
|
37
|
+
quote: number;
|
|
38
|
+
'ext-link': number;
|
|
39
|
+
'free-ext-link': number;
|
|
40
|
+
'magic-link': number;
|
|
41
|
+
list: number;
|
|
42
|
+
dd: number;
|
|
43
|
+
converter: number;
|
|
44
|
+
};
|
|
45
|
+
export type Stage = keyof typeof stages;
|
|
46
|
+
export declare const rules: readonly ["bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext"];
|
|
47
|
+
export declare namespace LintError {
|
|
48
|
+
type Severity = 'error' | 'warning';
|
|
49
|
+
type Rule = typeof rules[number];
|
|
50
|
+
interface Fix {
|
|
51
|
+
readonly range: [number, number];
|
|
52
|
+
text: string;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export interface LintError {
|
|
56
|
+
rule: LintError.Rule;
|
|
57
|
+
message: string;
|
|
58
|
+
severity: LintError.Severity;
|
|
59
|
+
startIndex: number;
|
|
60
|
+
endIndex: number;
|
|
61
|
+
startLine: number;
|
|
62
|
+
startCol: number;
|
|
63
|
+
endLine: number;
|
|
64
|
+
endCol: number;
|
|
65
|
+
fix?: LintError.Fix;
|
|
66
|
+
suggestions?: (LintError.Fix & {
|
|
67
|
+
desc: string;
|
|
68
|
+
})[];
|
|
69
|
+
}
|
|
70
|
+
export type AST = Record<string, string | number | boolean> & {
|
|
71
|
+
range: [number, number];
|
|
72
|
+
type?: TokenTypes;
|
|
73
|
+
name?: string;
|
|
74
|
+
childNodes?: AST[];
|
|
75
|
+
data?: string;
|
|
76
|
+
};
|
|
77
|
+
/** 类似Node */
|
|
78
|
+
export interface AstNode {
|
|
79
|
+
readonly childNodes: readonly AstNode[];
|
|
80
|
+
/** 节点类型 */
|
|
81
|
+
type: string;
|
|
82
|
+
/** Linter */
|
|
83
|
+
lint(): LintError[];
|
|
84
|
+
/** 以HTML格式打印 */
|
|
85
|
+
print(): string;
|
|
86
|
+
}
|
|
87
|
+
/** 所有节点的基类 */
|
|
88
|
+
interface Token extends AstNode {
|
|
89
|
+
readonly name?: string;
|
|
90
|
+
/**
|
|
91
|
+
* 符合选择器的所有后代节点
|
|
92
|
+
* @param selector 选择器
|
|
93
|
+
*/
|
|
94
|
+
querySelectorAll<T = Token>(selector: string): T[];
|
|
95
|
+
/** 保存为JSON */
|
|
96
|
+
json(): AST;
|
|
97
|
+
}
|
|
98
|
+
export interface Parser {
|
|
99
|
+
config: Config | string;
|
|
100
|
+
i18n: Record<string, string> | string | undefined;
|
|
101
|
+
/** 获取当前的解析设置 */
|
|
102
|
+
getConfig(): Config;
|
|
103
|
+
/**
|
|
104
|
+
* 解析wikitext
|
|
105
|
+
* @param include 是否嵌入
|
|
106
|
+
* @param maxStage 最大解析层级
|
|
107
|
+
*/
|
|
108
|
+
parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token;
|
|
109
|
+
}
|
|
110
|
+
export {};
|