wikiparser-node 1.0.0-beta.0 → 1.0.0-beta.2
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 +26 -0
- package/dist/index.d.ts +11 -9
- package/dist/index.js +22 -24
- package/dist/internal.d.ts +44 -0
- package/dist/lib/element.d.ts +42 -32
- package/dist/lib/element.js +59 -56
- package/dist/lib/node.d.ts +29 -36
- package/dist/lib/node.js +33 -48
- package/dist/lib/range.d.ts +132 -0
- package/dist/lib/range.js +387 -0
- package/dist/lib/ranges.d.ts +2 -12
- package/dist/lib/ranges.js +6 -11
- package/dist/lib/text.d.ts +11 -5
- package/dist/lib/text.js +25 -13
- package/dist/lib/title.d.ts +4 -5
- package/dist/lib/title.js +17 -7
- package/dist/mixin/attributesParent.js +6 -3
- package/dist/mixin/fixed.js +8 -5
- package/dist/mixin/hidden.js +7 -3
- package/dist/mixin/singleLine.js +6 -3
- package/dist/mixin/sol.js +6 -3
- package/dist/parser/{brackets.js → braces.js} +34 -26
- package/dist/parser/commentAndExt.js +25 -15
- package/dist/parser/converter.js +16 -9
- package/dist/parser/externalLinks.js +15 -9
- package/dist/parser/hrAndDoubleUnderscore.js +17 -10
- package/dist/parser/html.js +18 -9
- package/dist/parser/links.js +22 -14
- package/dist/parser/list.js +20 -10
- package/dist/parser/magicLinks.js +14 -7
- package/dist/parser/quotes.js +21 -11
- package/dist/parser/selector.js +19 -12
- package/dist/parser/table.js +25 -16
- package/dist/src/arg.d.ts +7 -8
- package/dist/src/arg.js +27 -24
- package/dist/src/atom.d.ts +4 -5
- package/dist/src/atom.js +9 -7
- package/dist/src/attribute.d.ts +13 -13
- package/dist/src/attribute.js +28 -25
- package/dist/src/attributes.d.ts +11 -10
- package/dist/src/attributes.js +40 -45
- package/dist/src/converter.d.ts +5 -7
- package/dist/src/converter.js +22 -16
- package/dist/src/converterFlags.d.ts +11 -12
- package/dist/src/converterFlags.js +17 -14
- package/dist/src/converterRule.d.ts +9 -10
- package/dist/src/converterRule.js +27 -27
- package/dist/src/extLink.d.ts +4 -6
- package/dist/src/extLink.js +25 -22
- package/dist/src/gallery.d.ts +9 -13
- package/dist/src/gallery.js +28 -23
- package/dist/src/heading.d.ts +11 -11
- package/dist/src/heading.js +19 -19
- package/dist/src/hidden.d.ts +4 -5
- package/dist/src/hidden.js +10 -8
- package/dist/src/html.d.ts +15 -12
- package/dist/src/html.js +18 -15
- package/dist/src/imageParameter.d.ts +11 -13
- package/dist/src/imageParameter.js +21 -16
- package/dist/src/imagemap.d.ts +11 -15
- package/dist/src/imagemap.js +26 -21
- package/dist/src/imagemapLink.d.ts +12 -17
- package/dist/src/imagemapLink.js +19 -14
- package/dist/src/index.d.ts +24 -20
- package/dist/src/index.js +65 -75
- package/dist/src/link/base.d.ts +8 -10
- package/dist/src/link/base.js +28 -22
- package/dist/src/link/category.d.ts +2 -3
- package/dist/src/link/category.js +7 -5
- package/dist/src/link/file.d.ts +9 -11
- package/dist/src/link/file.js +53 -26
- package/dist/src/link/galleryImage.d.ts +8 -8
- package/dist/src/link/galleryImage.js +18 -16
- package/dist/src/link/index.d.ts +6 -6
- package/dist/src/link/index.js +14 -16
- package/dist/src/magicLink.d.ts +9 -6
- package/dist/src/magicLink.js +23 -18
- package/dist/src/nested.d.ts +10 -10
- package/dist/src/nested.js +25 -17
- package/dist/src/nowiki/base.d.ts +7 -8
- package/dist/src/nowiki/base.js +10 -8
- package/dist/src/nowiki/comment.d.ts +7 -7
- package/dist/src/nowiki/comment.js +12 -9
- package/dist/src/nowiki/dd.d.ts +2 -3
- package/dist/src/nowiki/dd.js +7 -11
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -7
- package/dist/src/nowiki/doubleUnderscore.js +11 -8
- package/dist/src/nowiki/hr.d.ts +6 -7
- package/dist/src/nowiki/hr.js +11 -8
- package/dist/src/nowiki/index.d.ts +5 -7
- package/dist/src/nowiki/index.js +8 -6
- package/dist/src/nowiki/list.d.ts +4 -4
- package/dist/src/nowiki/list.js +8 -6
- package/dist/src/nowiki/noinclude.d.ts +3 -3
- package/dist/src/nowiki/noinclude.js +8 -6
- package/dist/src/nowiki/quote.d.ts +6 -7
- package/dist/src/nowiki/quote.js +11 -8
- package/dist/src/onlyinclude.d.ts +3 -5
- package/dist/src/onlyinclude.js +9 -7
- package/dist/src/paramTag/index.d.ts +8 -10
- package/dist/src/paramTag/index.js +15 -13
- package/dist/src/paramTag/inputbox.d.ts +4 -6
- package/dist/src/paramTag/inputbox.js +10 -8
- package/dist/src/parameter.d.ts +11 -12
- package/dist/src/parameter.js +25 -22
- package/dist/src/pre.d.ts +5 -10
- package/dist/src/pre.js +16 -11
- package/dist/src/syntax.d.ts +6 -7
- package/dist/src/syntax.js +12 -10
- package/dist/src/table/base.d.ts +14 -9
- package/dist/src/table/base.js +18 -15
- package/dist/src/table/index.d.ts +24 -17
- package/dist/src/table/index.js +39 -67
- package/dist/src/table/td.d.ts +17 -21
- package/dist/src/table/td.js +20 -28
- package/dist/src/table/tr.d.ts +6 -11
- package/dist/src/table/tr.js +8 -6
- package/dist/src/table/trBase.d.ts +12 -22
- package/dist/src/table/trBase.js +23 -19
- package/dist/src/tagPair/ext.d.ts +10 -10
- package/dist/src/tagPair/ext.js +47 -24
- package/dist/src/tagPair/include.d.ts +6 -7
- package/dist/src/tagPair/include.js +11 -8
- package/dist/src/tagPair/index.d.ts +12 -11
- package/dist/src/tagPair/index.js +13 -11
- package/dist/src/transclude.d.ts +8 -10
- package/dist/src/transclude.js +70 -77
- package/dist/util/debug.js +2 -12
- package/dist/util/diff.js +4 -2
- package/dist/util/lint.js +5 -5
- package/dist/util/string.js +2 -31
- package/package.json +13 -13
- package/dist/util/base.js +0 -26
package/config/.schema.json
CHANGED
|
@@ -116,6 +116,32 @@
|
|
|
116
116
|
"type": "string",
|
|
117
117
|
"pattern": "^[-a-z]+$"
|
|
118
118
|
}
|
|
119
|
+
},
|
|
120
|
+
"conversionTable": {
|
|
121
|
+
"description": "table of unidirectional conversions",
|
|
122
|
+
"type": "array",
|
|
123
|
+
"items": {
|
|
124
|
+
"type": "array",
|
|
125
|
+
"items": {
|
|
126
|
+
"type": "string",
|
|
127
|
+
"pattern": "^[^ <>[\\]{}|]+$"
|
|
128
|
+
},
|
|
129
|
+
"minItems": 2,
|
|
130
|
+
"maxItems": 2
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"redirects": {
|
|
134
|
+
"description": "table of redirects",
|
|
135
|
+
"type": "array",
|
|
136
|
+
"items": {
|
|
137
|
+
"type": "array",
|
|
138
|
+
"items": {
|
|
139
|
+
"type": "string",
|
|
140
|
+
"pattern": "^[^ <>[\\]{}|]+$"
|
|
141
|
+
},
|
|
142
|
+
"minItems": 2,
|
|
143
|
+
"maxItems": 2
|
|
144
|
+
}
|
|
119
145
|
}
|
|
120
146
|
},
|
|
121
147
|
"required": [
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Title } from './lib/title';
|
|
2
|
+
import type { Token } from './internal';
|
|
3
|
+
export interface Config {
|
|
2
4
|
ext: string[];
|
|
3
5
|
html: [string[], string[], string[]];
|
|
4
6
|
namespaces: Record<string, string>;
|
|
@@ -10,8 +12,10 @@ declare interface Config {
|
|
|
10
12
|
variants: string[];
|
|
11
13
|
interwiki: string[];
|
|
12
14
|
excludes?: string[];
|
|
15
|
+
conversionTable?: [string, string][];
|
|
16
|
+
redirects?: [string, string][];
|
|
13
17
|
}
|
|
14
|
-
|
|
18
|
+
export interface LintError {
|
|
15
19
|
message: string;
|
|
16
20
|
severity: 'error' | 'warning';
|
|
17
21
|
startIndex: number;
|
|
@@ -26,7 +30,7 @@ declare interface Parser {
|
|
|
26
30
|
/** @browser */
|
|
27
31
|
config: string | Config;
|
|
28
32
|
/** @browser */
|
|
29
|
-
i18n
|
|
33
|
+
i18n?: string | Record<string, string>;
|
|
30
34
|
conversionTable: Map<string, string>;
|
|
31
35
|
redirects: Map<string, string>;
|
|
32
36
|
/**
|
|
@@ -39,14 +43,14 @@ declare interface Parser {
|
|
|
39
43
|
* @param decode 是否需要解码
|
|
40
44
|
* @param selfLink 是否允许selfLink
|
|
41
45
|
*/
|
|
42
|
-
normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean):
|
|
46
|
+
normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
|
|
43
47
|
/**
|
|
44
48
|
* 解析wikitext
|
|
45
49
|
* @browser
|
|
46
50
|
* @param include 是否嵌入
|
|
47
51
|
* @param maxStage 最大解析层级
|
|
48
52
|
*/
|
|
49
|
-
parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config):
|
|
53
|
+
parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
|
|
50
54
|
/**
|
|
51
55
|
* 是否是跨维基链接
|
|
52
56
|
* @param title 链接标题
|
|
@@ -54,7 +58,5 @@ declare interface Parser {
|
|
|
54
58
|
isInterwiki(title: string, config?: Config): [string, string] | null;
|
|
55
59
|
}
|
|
56
60
|
declare const Parser: Parser;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
export = Parser;
|
|
61
|
+
export default Parser;
|
|
62
|
+
export type * from './internal';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
3
|
const fs = require("fs");
|
|
3
4
|
const path = require("path");
|
|
4
5
|
/**
|
|
@@ -6,10 +7,10 @@ const path = require("path");
|
|
|
6
7
|
* @param file 文件名
|
|
7
8
|
* @param dir 子路径
|
|
8
9
|
*/
|
|
9
|
-
const rootRequire = (file, dir = '') => require(
|
|
10
|
+
const rootRequire = (file, dir = '') => require(`../${file.includes('/') ? '' : dir}${file}`);
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
10
12
|
const Parser = {
|
|
11
13
|
config: 'default',
|
|
12
|
-
i18n: undefined,
|
|
13
14
|
conversionTable: new Map(),
|
|
14
15
|
redirects: new Map(),
|
|
15
16
|
MAX_STAGE: 11,
|
|
@@ -48,12 +49,12 @@ const Parser = {
|
|
|
48
49
|
'attr-key': ['attribute-key'],
|
|
49
50
|
'attr-value': ['attribute-value', 'attr-val', 'attribute-val'],
|
|
50
51
|
'ext-inner': ['extension-inner'],
|
|
51
|
-
// triple
|
|
52
|
+
// triple braces
|
|
52
53
|
arg: ['argument'],
|
|
53
54
|
'arg-name': ['argument-name'],
|
|
54
55
|
'arg-default': ['argument-default'],
|
|
55
56
|
hidden: ['arg-redundant'],
|
|
56
|
-
// double
|
|
57
|
+
// double braces
|
|
57
58
|
'magic-word': ['parser-function', 'parser-func'],
|
|
58
59
|
'magic-word-name': ['parser-function-name', 'parser-func-name'],
|
|
59
60
|
'invoke-function': ['invoke-func', 'lua-function', 'lua-func', 'module-function', 'module-func'],
|
|
@@ -116,7 +117,6 @@ const Parser = {
|
|
|
116
117
|
'converter-rule-from': ['convert-rule-from', 'conversion-rule-from'],
|
|
117
118
|
// specific extensions
|
|
118
119
|
'param-line': ['parameter-line'],
|
|
119
|
-
'charinsert-line': undefined,
|
|
120
120
|
'imagemap-link': ['image-map-link'],
|
|
121
121
|
},
|
|
122
122
|
promises: [Promise.resolve()],
|
|
@@ -124,6 +124,13 @@ const Parser = {
|
|
|
124
124
|
getConfig() {
|
|
125
125
|
if (typeof this.config === 'string') {
|
|
126
126
|
this.config = rootRequire(this.config, 'config/');
|
|
127
|
+
const { config: { conversionTable, redirects } } = this;
|
|
128
|
+
if (conversionTable) {
|
|
129
|
+
this.conversionTable = new Map(conversionTable);
|
|
130
|
+
}
|
|
131
|
+
if (redirects) {
|
|
132
|
+
this.redirects = new Map(redirects);
|
|
133
|
+
}
|
|
127
134
|
return this.getConfig();
|
|
128
135
|
}
|
|
129
136
|
return { ...this.config, excludes: [] };
|
|
@@ -138,36 +145,26 @@ const Parser = {
|
|
|
138
145
|
},
|
|
139
146
|
/** @implements */
|
|
140
147
|
normalizeTitle(title, defaultNs = 0, include = false, config = Parser.getConfig(), halfParsed = false, decode = false, selfLink = false) {
|
|
141
|
-
const Title = require('./lib/title');
|
|
148
|
+
const { Title } = require('./lib/title');
|
|
142
149
|
if (halfParsed) {
|
|
143
150
|
return new Title(title, defaultNs, config, decode, selfLink);
|
|
144
151
|
}
|
|
145
|
-
const Token = require('./src');
|
|
152
|
+
const { Token } = require('./src');
|
|
146
153
|
const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token.firstChild), defaultNs, config, decode, selfLink);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
* @param keys 属性键
|
|
150
|
-
*/
|
|
151
|
-
const build = (keys) => {
|
|
152
|
-
for (const key of keys) {
|
|
154
|
+
this.run(() => {
|
|
155
|
+
for (const key of ['main', 'fragment']) {
|
|
153
156
|
if (titleObj[key]?.includes('\0')) {
|
|
154
157
|
titleObj[key] = token.buildFromStr(titleObj[key], 'text');
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
|
-
};
|
|
158
|
-
this.run(() => {
|
|
159
|
-
build(['main', 'fragment']);
|
|
160
160
|
});
|
|
161
|
-
titleObj.
|
|
161
|
+
titleObj.conversionTable = this.conversionTable;
|
|
162
162
|
titleObj.redirects = this.redirects;
|
|
163
163
|
return titleObj;
|
|
164
164
|
},
|
|
165
165
|
/** @implements */
|
|
166
166
|
parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
|
|
167
|
-
|
|
168
|
-
throw new TypeError('待解析的内容应为 String!');
|
|
169
|
-
}
|
|
170
|
-
const Token = require('./src');
|
|
167
|
+
const { Token } = require('./src');
|
|
171
168
|
let token;
|
|
172
169
|
this.run(() => {
|
|
173
170
|
token = new Token(wikitext, config);
|
|
@@ -194,7 +191,7 @@ const Parser = {
|
|
|
194
191
|
process = '渲染HTML';
|
|
195
192
|
}
|
|
196
193
|
if (restored !== wikitext) {
|
|
197
|
-
const diff = require('./util/diff');
|
|
194
|
+
const { diff } = require('./util/diff');
|
|
198
195
|
const { promises: { 0: cur, length } } = this;
|
|
199
196
|
this.promises.unshift((async () => {
|
|
200
197
|
await cur;
|
|
@@ -260,6 +257,7 @@ const Parser = {
|
|
|
260
257
|
}
|
|
261
258
|
for (const [name, filePath] of entries) {
|
|
262
259
|
if (name in global) {
|
|
260
|
+
// @ts-expect-error noImplicitAny
|
|
263
261
|
global[name] = require(filePath);
|
|
264
262
|
}
|
|
265
263
|
}
|
|
@@ -277,7 +275,7 @@ const Parser = {
|
|
|
277
275
|
throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
|
|
278
276
|
}
|
|
279
277
|
const file = path.join(__dirname, '..', 'errors', main), wikitext = fs.readFileSync(file, 'utf8');
|
|
280
|
-
const { stage, include, config } = require(`${file}.json`), Token = require('./src');
|
|
278
|
+
const { stage, include, config } = require(`${file}.json`), { Token } = require('./src');
|
|
281
279
|
this.config = config;
|
|
282
280
|
return this.run(() => {
|
|
283
281
|
const halfParsed = stage < this.MAX_STAGE, token = new Token(wikitext, this.getConfig(), halfParsed);
|
|
@@ -304,4 +302,4 @@ for (const key in Parser) {
|
|
|
304
302
|
}
|
|
305
303
|
}
|
|
306
304
|
Object.defineProperties(Parser, def);
|
|
307
|
-
|
|
305
|
+
exports.default = Parser;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type { AstNodes, } from './lib/node';
|
|
2
|
+
export type * from './lib/text';
|
|
3
|
+
export type * from './src';
|
|
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 * 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 * from './src/table';
|
|
22
|
+
export type * from './src/nowiki/hr';
|
|
23
|
+
export type * from './src/nowiki/doubleUnderscore';
|
|
24
|
+
export type * from './src/link';
|
|
25
|
+
export type * from './src/link/category';
|
|
26
|
+
export type * 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';
|
|
38
|
+
export type * from './src/pre';
|
|
39
|
+
export type * from './src/paramTag';
|
|
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
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import AstText
|
|
4
|
-
import type { AstNodeTypes } from './node';
|
|
1
|
+
import { AstNode } from './node';
|
|
2
|
+
import type { LintError } from '../index';
|
|
3
|
+
import type { AstNodes, AstText, Token } from '../internal';
|
|
5
4
|
/** 类似HTMLElement */
|
|
6
|
-
declare abstract class AstElement extends AstNode {
|
|
5
|
+
export declare abstract class AstElement extends AstNode {
|
|
7
6
|
#private;
|
|
8
7
|
/** @browser */
|
|
9
8
|
name?: string;
|
|
@@ -13,23 +12,23 @@ declare abstract class AstElement extends AstNode {
|
|
|
13
12
|
*/
|
|
14
13
|
get length(): number;
|
|
15
14
|
/** 全部非文本子节点 */
|
|
16
|
-
get children():
|
|
15
|
+
get children(): Token[];
|
|
17
16
|
/** 首位非文本子节点 */
|
|
18
|
-
get firstElementChild():
|
|
17
|
+
get firstElementChild(): Token | undefined;
|
|
19
18
|
/** 末位非文本子节点 */
|
|
20
|
-
get lastElementChild():
|
|
19
|
+
get lastElementChild(): Token | undefined;
|
|
21
20
|
/** 非文本子节点总数 */
|
|
22
21
|
get childElementCount(): number;
|
|
23
22
|
/** 父节点 */
|
|
24
|
-
get parentElement():
|
|
23
|
+
get parentElement(): Token | undefined;
|
|
25
24
|
/** AstElement.prototype.text()的getter写法 */
|
|
26
25
|
get outerText(): string;
|
|
27
26
|
/** 不可见 */
|
|
28
27
|
get hidden(): boolean;
|
|
29
28
|
/** 后一个可见的兄弟节点 */
|
|
30
|
-
get nextVisibleSibling():
|
|
29
|
+
get nextVisibleSibling(): AstNodes | undefined;
|
|
31
30
|
/** 前一个可见的兄弟节点 */
|
|
32
|
-
get previousVisibleSibling():
|
|
31
|
+
get previousVisibleSibling(): AstNodes | undefined;
|
|
33
32
|
/** 内部高度 */
|
|
34
33
|
get clientHeight(): number | undefined;
|
|
35
34
|
/** 内部宽度 */
|
|
@@ -51,7 +50,7 @@ declare abstract class AstElement extends AstNode {
|
|
|
51
50
|
* @browser
|
|
52
51
|
* @param i 移除位置
|
|
53
52
|
*/
|
|
54
|
-
removeAt(i: number):
|
|
53
|
+
removeAt(i: number): AstNodes;
|
|
55
54
|
/**
|
|
56
55
|
* 插入子节点
|
|
57
56
|
* @browser
|
|
@@ -59,24 +58,25 @@ declare abstract class AstElement extends AstNode {
|
|
|
59
58
|
* @param i 插入位置
|
|
60
59
|
* @throws `RangeError` 不能插入祖先节点
|
|
61
60
|
*/
|
|
62
|
-
insertAt<T extends
|
|
61
|
+
insertAt<T extends AstNodes>(node: T, i?: number): T;
|
|
63
62
|
/**
|
|
64
63
|
* 最近的祖先节点
|
|
65
64
|
* @browser
|
|
65
|
+
* @param selector 选择器
|
|
66
66
|
*/
|
|
67
|
-
closest(selector: string):
|
|
67
|
+
closest(selector: string): Token | undefined;
|
|
68
68
|
/**
|
|
69
69
|
* 在末尾批量插入子节点
|
|
70
70
|
* @browser
|
|
71
71
|
* @param elements 插入节点
|
|
72
72
|
*/
|
|
73
|
-
append(...elements: (
|
|
73
|
+
append(...elements: (AstNodes | string)[]): void;
|
|
74
74
|
/**
|
|
75
75
|
* 批量替换子节点
|
|
76
76
|
* @browser
|
|
77
77
|
* @param elements 新的子节点
|
|
78
78
|
*/
|
|
79
|
-
replaceChildren(...elements: (
|
|
79
|
+
replaceChildren(...elements: (AstNodes | string)[]): void;
|
|
80
80
|
/**
|
|
81
81
|
* 修改文本子节点
|
|
82
82
|
* @browser
|
|
@@ -88,14 +88,16 @@ declare abstract class AstElement extends AstNode {
|
|
|
88
88
|
/**
|
|
89
89
|
* 还原为wikitext
|
|
90
90
|
* @browser
|
|
91
|
+
* @param selector
|
|
91
92
|
* @param separator 子节点间的连接符
|
|
92
93
|
*/
|
|
93
94
|
toString(selector?: string, separator?: string): string;
|
|
94
95
|
/**
|
|
95
96
|
* Linter
|
|
96
97
|
* @browser
|
|
98
|
+
* @param start
|
|
97
99
|
*/
|
|
98
|
-
lint(start?: number):
|
|
100
|
+
lint(start?: number): LintError[];
|
|
99
101
|
/**
|
|
100
102
|
* 以HTML格式打印
|
|
101
103
|
* @browser
|
|
@@ -110,27 +112,36 @@ declare abstract class AstElement extends AstNode {
|
|
|
110
112
|
json(file?: string): unknown;
|
|
111
113
|
/** 销毁 */
|
|
112
114
|
destroy(): void;
|
|
113
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* 检查是否符合选择器
|
|
117
|
+
* @param selector 选择器
|
|
118
|
+
*/
|
|
114
119
|
matches(selector?: string): boolean;
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
/**
|
|
121
|
+
* 符合选择器的第一个后代节点
|
|
122
|
+
* @param selector 选择器
|
|
123
|
+
*/
|
|
124
|
+
querySelector(selector: string): Token | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* 符合选择器的所有后代节点
|
|
127
|
+
* @param selector 选择器
|
|
128
|
+
*/
|
|
129
|
+
querySelectorAll(selector: string): Token[];
|
|
119
130
|
/**
|
|
120
131
|
* id选择器
|
|
121
132
|
* @param id id名
|
|
122
133
|
*/
|
|
123
|
-
getElementById(id: string):
|
|
134
|
+
getElementById(id: string): Token | undefined;
|
|
124
135
|
/**
|
|
125
136
|
* 类选择器
|
|
126
137
|
* @param className 类名之一
|
|
127
138
|
*/
|
|
128
|
-
getElementsByClassName(className: string):
|
|
139
|
+
getElementsByClassName(className: string): Token[];
|
|
129
140
|
/**
|
|
130
141
|
* 标签名选择器
|
|
131
142
|
* @param name 标签名
|
|
132
143
|
*/
|
|
133
|
-
getElementsByTagName(name: string):
|
|
144
|
+
getElementsByTagName(name: string): Token[];
|
|
134
145
|
/**
|
|
135
146
|
* 获取某一行的wikitext
|
|
136
147
|
* @param n 行号
|
|
@@ -140,37 +151,36 @@ declare abstract class AstElement extends AstNode {
|
|
|
140
151
|
* 在开头批量插入子节点
|
|
141
152
|
* @param elements 插入节点
|
|
142
153
|
*/
|
|
143
|
-
prepend(...elements: (
|
|
154
|
+
prepend(...elements: (AstNodes | string)[]): void;
|
|
144
155
|
/**
|
|
145
156
|
* 移除子节点
|
|
146
157
|
* @param node 子节点
|
|
147
158
|
*/
|
|
148
|
-
removeChild<T extends
|
|
159
|
+
removeChild<T extends AstNodes>(node: T): T;
|
|
149
160
|
/**
|
|
150
161
|
* 在末尾插入子节点
|
|
151
162
|
* @param node 插入节点
|
|
152
163
|
*/
|
|
153
164
|
appendChild(node: string): AstText;
|
|
154
165
|
/** @ignore */
|
|
155
|
-
appendChild<T extends
|
|
166
|
+
appendChild<T extends AstNodes>(node: T): T;
|
|
156
167
|
/**
|
|
157
168
|
* 在指定位置前插入子节点
|
|
158
169
|
* @param child 插入节点
|
|
159
170
|
* @param reference 指定位置处的子节点
|
|
160
171
|
*/
|
|
161
|
-
insertBefore(child: string, reference?:
|
|
172
|
+
insertBefore(child: string, reference?: AstNodes): AstText;
|
|
162
173
|
/** @ignore */
|
|
163
|
-
insertBefore<T extends
|
|
174
|
+
insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
|
|
164
175
|
/**
|
|
165
176
|
* 替换子节点
|
|
166
177
|
* @param newChild 新子节点
|
|
167
178
|
* @param oldChild 原子节点
|
|
168
179
|
*/
|
|
169
|
-
replaceChild<T extends
|
|
180
|
+
replaceChild<T extends AstNodes>(newChild: AstNodes | string, oldChild: T): T;
|
|
170
181
|
/**
|
|
171
182
|
* 输出AST
|
|
172
183
|
* @param depth 当前深度
|
|
173
184
|
*/
|
|
174
185
|
echo(depth?: number): void;
|
|
175
186
|
}
|
|
176
|
-
export = AstElement;
|