wikiparser-node 1.3.1 → 1.3.2-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.
- package/bundle/bundle.min.js +36 -0
- package/config/llwiki.json +1 -35
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +68 -0
- package/extensions/dist/editor.js +159 -0
- package/extensions/dist/highlight.js +30 -0
- package/extensions/dist/lint.js +48 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +117 -0
- package/i18n/zh-hans.json +4 -3
- package/i18n/zh-hant.json +4 -3
- package/package.json +32 -12
- package/config/.schema.json +0 -172
- package/dist/addon/table.d.ts +0 -6
- package/dist/addon/table.js +0 -564
- package/dist/base.d.ts +0 -45
- package/dist/bin/toc.js +0 -18
- package/dist/index.d.ts +0 -31
- package/dist/index.js +0 -209
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -155
- package/dist/lib/element.js +0 -654
- package/dist/lib/node.d.ts +0 -146
- package/dist/lib/node.js +0 -419
- package/dist/lib/range.d.ts +0 -104
- package/dist/lib/range.js +0 -385
- package/dist/lib/ranges.d.ts +0 -26
- package/dist/lib/ranges.js +0 -117
- package/dist/lib/text.d.ts +0 -62
- package/dist/lib/text.js +0 -235
- package/dist/lib/title.d.ts +0 -38
- package/dist/lib/title.js +0 -162
- package/dist/mixin/attributesParent.js +0 -94
- package/dist/mixin/fixed.js +0 -32
- package/dist/mixin/flagsParent.js +0 -70
- package/dist/mixin/hidden.js +0 -22
- package/dist/mixin/magicLinkParent.js +0 -41
- package/dist/mixin/singleLine.js +0 -25
- package/dist/mixin/sol.js +0 -43
- package/dist/mixin/syntax.js +0 -56
- package/dist/parser/braces.js +0 -122
- package/dist/parser/commentAndExt.js +0 -69
- package/dist/parser/converter.js +0 -40
- package/dist/parser/externalLinks.js +0 -28
- package/dist/parser/hrAndDoubleUnderscore.js +0 -38
- package/dist/parser/html.js +0 -36
- package/dist/parser/links.js +0 -94
- package/dist/parser/list.js +0 -59
- package/dist/parser/magicLinks.js +0 -40
- package/dist/parser/quotes.js +0 -67
- package/dist/parser/selector.js +0 -162
- package/dist/parser/table.js +0 -112
- package/dist/src/arg.d.ts +0 -58
- package/dist/src/arg.js +0 -189
- package/dist/src/atom.d.ts +0 -12
- package/dist/src/atom.js +0 -27
- package/dist/src/attribute.d.ts +0 -86
- package/dist/src/attribute.js +0 -391
- package/dist/src/attributes.d.ts +0 -107
- package/dist/src/attributes.js +0 -341
- package/dist/src/converter.d.ts +0 -51
- package/dist/src/converter.js +0 -79
- package/dist/src/converterFlags.d.ts +0 -87
- package/dist/src/converterFlags.js +0 -222
- package/dist/src/converterRule.d.ts +0 -81
- package/dist/src/converterRule.js +0 -212
- package/dist/src/extLink.d.ts +0 -53
- package/dist/src/extLink.js +0 -121
- package/dist/src/gallery.d.ts +0 -55
- package/dist/src/gallery.js +0 -122
- package/dist/src/heading.d.ts +0 -72
- package/dist/src/heading.js +0 -127
- package/dist/src/hidden.d.ts +0 -21
- package/dist/src/hidden.js +0 -23
- package/dist/src/html.d.ts +0 -103
- package/dist/src/html.js +0 -222
- package/dist/src/imageParameter.d.ts +0 -66
- package/dist/src/imageParameter.js +0 -247
- package/dist/src/imagemap.d.ts +0 -57
- package/dist/src/imagemap.js +0 -148
- package/dist/src/imagemapLink.d.ts +0 -57
- package/dist/src/imagemapLink.js +0 -40
- package/dist/src/index.d.ts +0 -146
- package/dist/src/index.js +0 -777
- package/dist/src/link/base.d.ts +0 -52
- package/dist/src/link/base.js +0 -207
- package/dist/src/link/category.d.ts +0 -13
- package/dist/src/link/category.js +0 -29
- package/dist/src/link/file.d.ts +0 -96
- package/dist/src/link/file.js +0 -253
- package/dist/src/link/galleryImage.d.ts +0 -43
- package/dist/src/link/galleryImage.js +0 -106
- package/dist/src/link/index.d.ts +0 -53
- package/dist/src/link/index.js +0 -123
- package/dist/src/magicLink.d.ts +0 -69
- package/dist/src/magicLink.js +0 -147
- package/dist/src/nested.d.ts +0 -44
- package/dist/src/nested.js +0 -87
- package/dist/src/nowiki/base.d.ts +0 -46
- package/dist/src/nowiki/base.js +0 -42
- package/dist/src/nowiki/comment.d.ts +0 -39
- package/dist/src/nowiki/comment.js +0 -67
- package/dist/src/nowiki/dd.d.ts +0 -8
- package/dist/src/nowiki/dd.js +0 -25
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -43
- package/dist/src/nowiki/doubleUnderscore.js +0 -50
- package/dist/src/nowiki/hr.d.ts +0 -29
- package/dist/src/nowiki/hr.js +0 -14
- package/dist/src/nowiki/index.d.ts +0 -16
- package/dist/src/nowiki/index.js +0 -21
- package/dist/src/nowiki/list.d.ts +0 -29
- package/dist/src/nowiki/list.js +0 -48
- package/dist/src/nowiki/listBase.d.ts +0 -18
- package/dist/src/nowiki/listBase.js +0 -12
- package/dist/src/nowiki/noinclude.d.ts +0 -25
- package/dist/src/nowiki/noinclude.js +0 -25
- package/dist/src/nowiki/quote.d.ts +0 -22
- package/dist/src/nowiki/quote.js +0 -45
- package/dist/src/onlyinclude.d.ts +0 -16
- package/dist/src/onlyinclude.js +0 -57
- package/dist/src/paramTag/index.d.ts +0 -37
- package/dist/src/paramTag/index.js +0 -68
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/paramTag/inputbox.js +0 -23
- package/dist/src/parameter.d.ts +0 -84
- package/dist/src/parameter.js +0 -205
- package/dist/src/pre.d.ts +0 -28
- package/dist/src/pre.js +0 -51
- package/dist/src/syntax.d.ts +0 -24
- package/dist/src/syntax.js +0 -30
- package/dist/src/table/base.d.ts +0 -52
- package/dist/src/table/base.js +0 -78
- package/dist/src/table/index.d.ts +0 -229
- package/dist/src/table/index.js +0 -379
- package/dist/src/table/td.d.ts +0 -103
- package/dist/src/table/td.js +0 -261
- package/dist/src/table/tr.d.ts +0 -32
- package/dist/src/table/tr.js +0 -56
- package/dist/src/table/trBase.d.ts +0 -54
- package/dist/src/table/trBase.js +0 -158
- package/dist/src/tagPair/ext.d.ts +0 -58
- package/dist/src/tagPair/ext.js +0 -142
- package/dist/src/tagPair/include.d.ts +0 -52
- package/dist/src/tagPair/include.js +0 -58
- package/dist/src/tagPair/index.d.ts +0 -47
- package/dist/src/tagPair/index.js +0 -93
- package/dist/src/transclude.d.ts +0 -167
- package/dist/src/transclude.js +0 -689
- package/dist/util/constants.js +0 -108
- package/dist/util/debug.js +0 -64
- package/dist/util/diff.js +0 -72
- package/dist/util/lint.js +0 -46
- package/dist/util/string.js +0 -61
- package/errors/README +0 -1
- package/printed/README +0 -1
package/dist/index.js
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint n/exports-style: 0 */
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const diff_1 = require("./util/diff");
|
|
6
|
-
const debug_1 = require("./util/debug");
|
|
7
|
-
const constants_1 = require("./util/constants");
|
|
8
|
-
/**
|
|
9
|
-
* 从根路径require
|
|
10
|
-
* @param file 文件名
|
|
11
|
-
* @param dir 子路径
|
|
12
|
-
*/
|
|
13
|
-
const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
|
|
14
|
-
/**
|
|
15
|
-
* 清理解析专用的不可见字符
|
|
16
|
-
* @param text 源文本
|
|
17
|
-
*/
|
|
18
|
-
const tidy = (text) => text.replace(/[\0\x7F]/gu, '');
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
20
|
-
const Parser = {
|
|
21
|
-
config: 'default',
|
|
22
|
-
i18n: undefined,
|
|
23
|
-
/* NOT FOR BROWSER */
|
|
24
|
-
Shadow: debug_1.Shadow,
|
|
25
|
-
conversionTable: new Map(),
|
|
26
|
-
redirects: new Map(),
|
|
27
|
-
warning: true,
|
|
28
|
-
debugging: false,
|
|
29
|
-
/* NOT FOR BROWSER END */
|
|
30
|
-
/** @implements */
|
|
31
|
-
getConfig() {
|
|
32
|
-
if (typeof this.config === 'string') {
|
|
33
|
-
this.config = rootRequire(this.config, 'config/');
|
|
34
|
-
const { config: { conversionTable, redirects } } = this;
|
|
35
|
-
if (conversionTable) {
|
|
36
|
-
this.conversionTable = new Map(conversionTable);
|
|
37
|
-
}
|
|
38
|
-
if (redirects) {
|
|
39
|
-
this.redirects = new Map(redirects);
|
|
40
|
-
}
|
|
41
|
-
return this.getConfig();
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
...this.config,
|
|
45
|
-
excludes: [],
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
/** @implements */
|
|
49
|
-
msg(msg, arg = '') {
|
|
50
|
-
if (typeof this.i18n === 'string') {
|
|
51
|
-
this.i18n = rootRequire(this.i18n, 'i18n/');
|
|
52
|
-
return this.msg(msg, arg);
|
|
53
|
-
}
|
|
54
|
-
return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
|
|
55
|
-
},
|
|
56
|
-
/** @implements */
|
|
57
|
-
normalizeTitle(title, defaultNs = 0, include = false, config = Parser.getConfig(), halfParsed = false, decode = false, selfLink = false) {
|
|
58
|
-
const { Title } = require('./lib/title');
|
|
59
|
-
if (halfParsed) {
|
|
60
|
-
return new Title(title, defaultNs, config, decode, selfLink);
|
|
61
|
-
}
|
|
62
|
-
const { Token } = require('./src/index');
|
|
63
|
-
const token = debug_1.Shadow.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
|
|
64
|
-
debug_1.Shadow.run(() => {
|
|
65
|
-
for (const key of ['main', 'fragment']) {
|
|
66
|
-
if (titleObj[key]?.includes('\0')) {
|
|
67
|
-
titleObj[key] = token.buildFromStr(titleObj[key], 'text');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
titleObj.conversionTable = this.conversionTable;
|
|
72
|
-
titleObj.redirects = this.redirects;
|
|
73
|
-
return titleObj;
|
|
74
|
-
},
|
|
75
|
-
/** @implements */
|
|
76
|
-
parse(wikitext, include, maxStage = constants_1.MAX_STAGE, config = Parser.getConfig()) {
|
|
77
|
-
const { Token } = require('./src/index');
|
|
78
|
-
const root = debug_1.Shadow.run(() => {
|
|
79
|
-
const token = new Token(tidy(wikitext), config);
|
|
80
|
-
try {
|
|
81
|
-
return token.parse(maxStage, include);
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
if (e instanceof Error) {
|
|
85
|
-
const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
|
|
86
|
-
fs.writeFileSync(file, stage === constants_1.MAX_STAGE ? wikitext : String(token));
|
|
87
|
-
fs.writeFileSync(`${file}.err`, e.stack);
|
|
88
|
-
fs.writeFileSync(`${file}.json`, JSON.stringify({
|
|
89
|
-
stage, include: token.getAttribute('include'), config: this.config,
|
|
90
|
-
}, null, '\t'));
|
|
91
|
-
}
|
|
92
|
-
throw e;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
if (this.debugging) {
|
|
96
|
-
let restored = String(root), process = '解析';
|
|
97
|
-
if (restored === wikitext) {
|
|
98
|
-
const entities = { lt: '<', gt: '>', amp: '&' };
|
|
99
|
-
restored = root.print().replace(/<[^<]+?>|&([lg]t|amp);/gu, (_, s) => s ? entities[s] : '');
|
|
100
|
-
process = '渲染HTML';
|
|
101
|
-
}
|
|
102
|
-
if (restored !== wikitext) {
|
|
103
|
-
const { diff } = require('./util/diff');
|
|
104
|
-
const { 0: cur, length } = constants_1.promises;
|
|
105
|
-
constants_1.promises.unshift((async () => {
|
|
106
|
-
await cur;
|
|
107
|
-
this.error(`${process}过程中不可逆地修改了原始文本!`);
|
|
108
|
-
return diff(wikitext, restored, length);
|
|
109
|
-
})());
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return root;
|
|
113
|
-
},
|
|
114
|
-
/* NOT FOR BROWSER */
|
|
115
|
-
/** @implements */
|
|
116
|
-
warn(msg, ...args) {
|
|
117
|
-
if (this.warning) {
|
|
118
|
-
console.warn('\x1B[33m%s\x1B[0m', msg, ...args);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
/** @implements */
|
|
122
|
-
debug(msg, ...args) {
|
|
123
|
-
if (this.debugging) {
|
|
124
|
-
console.debug('\x1B[34m%s\x1B[0m', msg, ...args);
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
/** @implements */
|
|
128
|
-
error(msg, ...args) {
|
|
129
|
-
console.error('\x1B[31m%s\x1B[0m', msg, ...args);
|
|
130
|
-
},
|
|
131
|
-
/** @implements */
|
|
132
|
-
info(msg, ...args) {
|
|
133
|
-
console.info('\x1B[32m%s\x1B[0m', msg, ...args);
|
|
134
|
-
},
|
|
135
|
-
/** @implements */
|
|
136
|
-
log(f) {
|
|
137
|
-
if (typeof f === 'function') {
|
|
138
|
-
console.log(String(f));
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
/** @implements */
|
|
142
|
-
async clearCache() {
|
|
143
|
-
const promise = (0, diff_1.cmd)('npm', ['run', 'build']), entries = [
|
|
144
|
-
...Object.entries(constants_1.classes),
|
|
145
|
-
...Object.entries(constants_1.mixins),
|
|
146
|
-
...Object.entries(constants_1.parsers),
|
|
147
|
-
];
|
|
148
|
-
for (const [, filePath] of entries) {
|
|
149
|
-
try {
|
|
150
|
-
delete require.cache[require.resolve(filePath)];
|
|
151
|
-
}
|
|
152
|
-
catch { }
|
|
153
|
-
}
|
|
154
|
-
await promise;
|
|
155
|
-
for (const [name, filePath] of entries) {
|
|
156
|
-
if (name in global) {
|
|
157
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
158
|
-
Object.assign(global, { [name]: require(filePath)[name] });
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
this.info('已重新加载Parser');
|
|
162
|
-
},
|
|
163
|
-
/** @implements */
|
|
164
|
-
isInterwiki(title, { interwiki } = Parser.getConfig()) {
|
|
165
|
-
return new RegExp(`^(${interwiki.join('|')})\\s*:`, 'diu')
|
|
166
|
-
.exec(title.replaceAll('_', ' ').replace(/^\s*:?\s*/u, ''));
|
|
167
|
-
},
|
|
168
|
-
/** @implements */
|
|
169
|
-
reparse(date) {
|
|
170
|
-
const main = fs.readdirSync(path.join(__dirname, '..', 'errors'))
|
|
171
|
-
.find(name => name.startsWith(date) && name.endsWith('Z'));
|
|
172
|
-
if (!main) {
|
|
173
|
-
throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
|
|
174
|
-
}
|
|
175
|
-
const file = path.join(__dirname, '..', 'errors', main), wikitext = fs.readFileSync(file, 'utf8');
|
|
176
|
-
const { stage, include, config } = require(`${file}.json`), { Token } = require('./src');
|
|
177
|
-
this.config = config;
|
|
178
|
-
return debug_1.Shadow.run(() => {
|
|
179
|
-
const halfParsed = stage < constants_1.MAX_STAGE, token = new Token(halfParsed ? wikitext : tidy(wikitext), this.getConfig());
|
|
180
|
-
if (halfParsed) {
|
|
181
|
-
token.setAttribute('stage', stage);
|
|
182
|
-
token.parseOnce(stage, include);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
token.parse(undefined, include);
|
|
186
|
-
}
|
|
187
|
-
fs.unlinkSync(file);
|
|
188
|
-
fs.unlinkSync(`${file}.err`);
|
|
189
|
-
fs.unlinkSync(`${file}.json`);
|
|
190
|
-
return token;
|
|
191
|
-
});
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
const def = {}, enumerable = new Set([
|
|
195
|
-
'conversionTable',
|
|
196
|
-
'redirects',
|
|
197
|
-
'warning',
|
|
198
|
-
'debugging',
|
|
199
|
-
'normalizeTitle',
|
|
200
|
-
'parse',
|
|
201
|
-
'isInterwiki',
|
|
202
|
-
]);
|
|
203
|
-
for (const key in Parser) {
|
|
204
|
-
if (!enumerable.has(key)) {
|
|
205
|
-
def[key] = { enumerable: false };
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
Object.defineProperties(Parser, def);
|
|
209
|
-
module.exports = Parser;
|
package/dist/internal.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export type { AstNodes, } from './lib/node';
|
|
2
|
-
export type * from './lib/text';
|
|
3
|
-
export type * from './src/index';
|
|
4
|
-
export type * from './src/onlyinclude';
|
|
5
|
-
export type * from './src/nowiki/noinclude';
|
|
6
|
-
export type * from './src/tagPair/include';
|
|
7
|
-
export type * from './src/nowiki/comment';
|
|
8
|
-
export type * from './src/atom';
|
|
9
|
-
export type { AttributeToken } from './src/attribute';
|
|
10
|
-
export type * from './src/attributes';
|
|
11
|
-
export type * from './src/tagPair/ext';
|
|
12
|
-
export type * from './src/hidden';
|
|
13
|
-
export type * from './src/arg';
|
|
14
|
-
export type * from './src/syntax';
|
|
15
|
-
export type * from './src/parameter';
|
|
16
|
-
export type * from './src/transclude';
|
|
17
|
-
export type * from './src/heading';
|
|
18
|
-
export type * from './src/html';
|
|
19
|
-
export type { TdToken } from './src/table/td';
|
|
20
|
-
export type * from './src/table/tr';
|
|
21
|
-
export type { TableToken } from './src/table/index';
|
|
22
|
-
export type * from './src/nowiki/hr';
|
|
23
|
-
export type * from './src/nowiki/doubleUnderscore';
|
|
24
|
-
export type * from './src/link/index';
|
|
25
|
-
export type * from './src/link/category';
|
|
26
|
-
export type { ImageParameterToken } from './src/imageParameter';
|
|
27
|
-
export type * from './src/link/file';
|
|
28
|
-
export type * from './src/link/galleryImage';
|
|
29
|
-
export type * from './src/nowiki/quote';
|
|
30
|
-
export type * from './src/magicLink';
|
|
31
|
-
export type * from './src/extLink';
|
|
32
|
-
export type * from './src/nowiki/dd';
|
|
33
|
-
export type * from './src/nowiki/list';
|
|
34
|
-
export type * from './src/converterFlags';
|
|
35
|
-
export type * from './src/converterRule';
|
|
36
|
-
export type * from './src/converter';
|
|
37
|
-
export type * from './src/nowiki/index';
|
|
38
|
-
export type * from './src/pre';
|
|
39
|
-
export type * from './src/paramTag/index';
|
|
40
|
-
export type * from './src/paramTag/inputbox';
|
|
41
|
-
export type * from './src/nested';
|
|
42
|
-
export type * from './src/gallery';
|
|
43
|
-
export type * from './src/imagemapLink';
|
|
44
|
-
export type * from './src/imagemap';
|
package/dist/lib/element.d.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { AstNode } from './node';
|
|
2
|
-
import type { LintError } from '../base';
|
|
3
|
-
import type { AstNodes, AstText, Token, HtmlToken, ExtToken } from '../internal';
|
|
4
|
-
/** 类似HTMLElement */
|
|
5
|
-
export declare abstract class AstElement extends AstNode {
|
|
6
|
-
#private;
|
|
7
|
-
readonly name?: string;
|
|
8
|
-
readonly data: undefined;
|
|
9
|
-
/** 子节点总数 */
|
|
10
|
-
get length(): number;
|
|
11
|
-
/** 全部非文本子节点 */
|
|
12
|
-
get children(): readonly Token[];
|
|
13
|
-
/** 首位非文本子节点 */
|
|
14
|
-
get firstElementChild(): Token | undefined;
|
|
15
|
-
/** 末位非文本子节点 */
|
|
16
|
-
get lastElementChild(): Token | undefined;
|
|
17
|
-
/** 非文本子节点总数 */
|
|
18
|
-
get childElementCount(): number;
|
|
19
|
-
/** 父节点 */
|
|
20
|
-
get parentElement(): Token | undefined;
|
|
21
|
-
/** AstElement.prototype.text()的getter写法 */
|
|
22
|
-
get outerText(): string;
|
|
23
|
-
/** 不可见 */
|
|
24
|
-
get hidden(): boolean;
|
|
25
|
-
/** 后一个可见的兄弟节点 */
|
|
26
|
-
get nextVisibleSibling(): AstNodes | undefined;
|
|
27
|
-
/** 前一个可见的兄弟节点 */
|
|
28
|
-
get previousVisibleSibling(): AstNodes | undefined;
|
|
29
|
-
/** 内部高度 */
|
|
30
|
-
get clientHeight(): number | undefined;
|
|
31
|
-
/** 内部宽度 */
|
|
32
|
-
get clientWidth(): number | undefined;
|
|
33
|
-
constructor();
|
|
34
|
-
/**
|
|
35
|
-
* 可见部分
|
|
36
|
-
* @param separator 子节点间的连接符
|
|
37
|
-
*/
|
|
38
|
-
text(separator?: string): string;
|
|
39
|
-
/** 合并相邻的文本子节点 */
|
|
40
|
-
normalize(): void;
|
|
41
|
-
/**
|
|
42
|
-
* 移除子节点
|
|
43
|
-
* @param i 移除位置
|
|
44
|
-
*/
|
|
45
|
-
removeAt(i: number): AstNodes;
|
|
46
|
-
/**
|
|
47
|
-
* 插入子节点
|
|
48
|
-
* @param node 待插入的子节点
|
|
49
|
-
* @param i 插入位置
|
|
50
|
-
* @throws `RangeError` 不能插入祖先或子节点
|
|
51
|
-
*/
|
|
52
|
-
insertAt<T extends AstNodes>(node: T, i?: number): T;
|
|
53
|
-
/**
|
|
54
|
-
* 最近的祖先节点
|
|
55
|
-
* @param selector 选择器
|
|
56
|
-
*/
|
|
57
|
-
closest<T extends Token>(selector: string): T | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* 在末尾批量插入子节点
|
|
60
|
-
* @param elements 插入节点
|
|
61
|
-
*/
|
|
62
|
-
append(...elements: (AstNodes | string)[]): void;
|
|
63
|
-
/**
|
|
64
|
-
* 批量替换子节点
|
|
65
|
-
* @param elements 新的子节点
|
|
66
|
-
*/
|
|
67
|
-
replaceChildren(...elements: (AstNodes | string)[]): void;
|
|
68
|
-
/**
|
|
69
|
-
* 修改文本子节点
|
|
70
|
-
* @param str 新文本
|
|
71
|
-
* @param i 子节点位置
|
|
72
|
-
* @throws `RangeError` 对应位置的子节点不是文本节点
|
|
73
|
-
*/
|
|
74
|
-
setText(str: string, i?: number): string;
|
|
75
|
-
/**
|
|
76
|
-
* @override
|
|
77
|
-
* @param start
|
|
78
|
-
*/
|
|
79
|
-
lint(start?: number): LintError[];
|
|
80
|
-
/**
|
|
81
|
-
* @override
|
|
82
|
-
* @param opt 选项
|
|
83
|
-
*/
|
|
84
|
-
print(opt?: PrintOpt): string;
|
|
85
|
-
/**
|
|
86
|
-
* 保存为JSON
|
|
87
|
-
* @param file 文件名
|
|
88
|
-
*/
|
|
89
|
-
json(file?: string): unknown;
|
|
90
|
-
/** 销毁 */
|
|
91
|
-
destroy(): void;
|
|
92
|
-
/**
|
|
93
|
-
* 检查是否符合选择器
|
|
94
|
-
* @param selector 选择器
|
|
95
|
-
*/
|
|
96
|
-
matches(selector?: string): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* 符合选择器的第一个后代节点
|
|
99
|
-
* @param selector 选择器
|
|
100
|
-
*/
|
|
101
|
-
querySelector<T extends Token>(selector: string): T | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* 类型选择器
|
|
104
|
-
* @param types
|
|
105
|
-
*/
|
|
106
|
-
getElementByTypes<T extends Token>(types: string): T | undefined;
|
|
107
|
-
/**
|
|
108
|
-
* id选择器
|
|
109
|
-
* @param id id名
|
|
110
|
-
*/
|
|
111
|
-
getElementById(id: string): Token | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* 符合选择器的所有后代节点
|
|
114
|
-
* @param selector 选择器
|
|
115
|
-
*/
|
|
116
|
-
querySelectorAll<T extends Token>(selector: string): readonly T[];
|
|
117
|
-
/**
|
|
118
|
-
* 类选择器
|
|
119
|
-
* @param className 类名之一
|
|
120
|
-
*/
|
|
121
|
-
getElementsByClassName(className: string): readonly Token[];
|
|
122
|
-
/**
|
|
123
|
-
* 标签名选择器
|
|
124
|
-
* @param tag 标签名
|
|
125
|
-
*/
|
|
126
|
-
getElementsByTagName(tag: string): readonly (HtmlToken | ExtToken)[];
|
|
127
|
-
/**
|
|
128
|
-
* 获取某一行的wikitext
|
|
129
|
-
* @param n 行号
|
|
130
|
-
*/
|
|
131
|
-
getLine(n: number): string | undefined;
|
|
132
|
-
/**
|
|
133
|
-
* 在开头批量插入子节点
|
|
134
|
-
* @param elements 插入节点
|
|
135
|
-
*/
|
|
136
|
-
prepend(...elements: (AstNodes | string)[]): void;
|
|
137
|
-
/**
|
|
138
|
-
* 移除子节点
|
|
139
|
-
* @param node 子节点
|
|
140
|
-
*/
|
|
141
|
-
removeChild<T extends AstNodes>(node: T): T;
|
|
142
|
-
/**
|
|
143
|
-
* 在指定位置前插入子节点
|
|
144
|
-
* @param child 插入节点
|
|
145
|
-
* @param reference 指定位置处的子节点
|
|
146
|
-
*/
|
|
147
|
-
insertBefore(child: string, reference?: AstNodes): AstText;
|
|
148
|
-
/** @ignore */
|
|
149
|
-
insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
|
|
150
|
-
/**
|
|
151
|
-
* 输出AST
|
|
152
|
-
* @param depth 当前深度
|
|
153
|
-
*/
|
|
154
|
-
echo(depth?: number): void;
|
|
155
|
-
}
|