wikiparser-node 1.3.4 → 1.3.6
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/dist/addon/table.js +13 -19
- package/dist/index.d.ts +1 -0
- package/dist/lib/element.d.ts +0 -1
- package/dist/lib/element.js +4 -13
- package/dist/lib/node.js +4 -0
- package/dist/lib/ranges.js +2 -1
- package/dist/lib/text.js +4 -5
- package/dist/mixin/attributesParent.js +2 -7
- package/dist/mixin/fixed.js +3 -10
- package/dist/mixin/syntax.js +1 -3
- package/dist/parser/braces.js +9 -2
- package/dist/parser/commentAndExt.js +18 -10
- package/dist/parser/list.js +11 -4
- package/dist/parser/selector.js +19 -20
- package/dist/parser/table.js +28 -20
- package/dist/src/arg.d.ts +0 -2
- package/dist/src/arg.js +2 -4
- package/dist/src/attribute.d.ts +1 -0
- package/dist/src/attribute.js +3 -3
- package/dist/src/attributes.d.ts +3 -1
- package/dist/src/attributes.js +21 -18
- package/dist/src/converter.d.ts +1 -0
- package/dist/src/converterRule.d.ts +1 -5
- package/dist/src/converterRule.js +3 -7
- package/dist/src/extLink.d.ts +1 -0
- package/dist/src/gallery.d.ts +0 -1
- package/dist/src/gallery.js +1 -2
- package/dist/src/heading.d.ts +3 -1
- package/dist/src/heading.js +2 -2
- package/dist/src/hidden.d.ts +1 -0
- package/dist/src/html.d.ts +3 -0
- package/dist/src/html.js +0 -1
- package/dist/src/imageParameter.d.ts +0 -1
- package/dist/src/imageParameter.js +0 -2
- package/dist/src/imagemap.d.ts +0 -1
- package/dist/src/imagemap.js +2 -3
- package/dist/src/imagemapLink.d.ts +2 -0
- package/dist/src/index.d.ts +1 -8
- package/dist/src/index.js +17 -17
- package/dist/src/link/file.js +2 -1
- package/dist/src/link/galleryImage.d.ts +1 -0
- package/dist/src/link/index.js +1 -1
- package/dist/src/magicLink.d.ts +1 -2
- package/dist/src/magicLink.js +2 -3
- package/dist/src/nested.d.ts +0 -1
- package/dist/src/nested.js +1 -2
- package/dist/src/nowiki/base.d.ts +1 -0
- package/dist/src/nowiki/comment.d.ts +1 -0
- package/dist/src/nowiki/dd.js +1 -1
- package/dist/src/nowiki/doubleUnderscore.d.ts +2 -0
- package/dist/src/nowiki/hr.d.ts +2 -0
- package/dist/src/nowiki/list.d.ts +1 -0
- package/dist/src/nowiki/listBase.d.ts +1 -0
- package/dist/src/nowiki/noinclude.d.ts +1 -1
- package/dist/src/nowiki/noinclude.js +1 -2
- package/dist/src/nowiki/quote.d.ts +1 -0
- package/dist/src/parameter.d.ts +1 -0
- package/dist/src/parameter.js +1 -1
- package/dist/src/syntax.d.ts +2 -0
- package/dist/src/table/base.d.ts +2 -0
- package/dist/src/table/index.d.ts +0 -1
- package/dist/src/table/index.js +0 -1
- package/dist/src/table/td.d.ts +3 -0
- package/dist/src/table/td.js +9 -10
- package/dist/src/table/trBase.d.ts +0 -1
- package/dist/src/table/trBase.js +2 -10
- package/dist/src/tagPair/ext.d.ts +2 -0
- package/dist/src/tagPair/include.d.ts +1 -0
- package/dist/src/tagPair/index.d.ts +1 -0
- package/dist/src/transclude.js +9 -11
- package/dist/util/debug.js +39 -20
- package/dist/util/lint.js +12 -28
- package/dist/util/string.js +12 -22
- package/package.json +1 -1
package/dist/src/attributes.js
CHANGED
|
@@ -11,9 +11,15 @@ const atom_1 = require("./atom");
|
|
|
11
11
|
const attribute_1 = require("./attribute");
|
|
12
12
|
/* NOT FOR BROWSER */
|
|
13
13
|
const stages = { 'ext-attrs': 0, 'html-attrs': 2, 'table-attrs': 3 };
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* 将属性类型转换为单属性类型
|
|
16
|
+
* @param type 属性类型
|
|
17
|
+
*/
|
|
15
18
|
const toAttributeType = (type) => type.slice(0, -1);
|
|
16
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* 将属性类型转换为无效属性类型
|
|
21
|
+
* @param type 属性类型
|
|
22
|
+
*/
|
|
17
23
|
const toDirty = (type) => `${toAttributeType(type)}-dirty`;
|
|
18
24
|
/**
|
|
19
25
|
* 扩展和HTML标签属性
|
|
@@ -27,9 +33,7 @@ class AttributesToken extends index_1.Token {
|
|
|
27
33
|
}
|
|
28
34
|
set attributes(attrs) {
|
|
29
35
|
this.replaceChildren();
|
|
30
|
-
|
|
31
|
-
this.setAttr(key, value);
|
|
32
|
-
}
|
|
36
|
+
this.setAttr(attrs);
|
|
33
37
|
}
|
|
34
38
|
/** 以字符串表示的class属性 */
|
|
35
39
|
get className() {
|
|
@@ -76,7 +80,7 @@ class AttributesToken extends index_1.Token {
|
|
|
76
80
|
this.type = type;
|
|
77
81
|
this.setAttribute('name', name);
|
|
78
82
|
if (attr) {
|
|
79
|
-
const regex = new RegExp(
|
|
83
|
+
const regex = new RegExp('([^\\s/](?:(?!\0\\d+~\x7F)[^\\s/=])*)' // 属性名
|
|
80
84
|
+ '(?:'
|
|
81
85
|
+ '((?:\\s|\0\\d+c\x7F)*' // `=`前的空白字符
|
|
82
86
|
+ '(?:=|\0\\d+~\x7F)' // `=`
|
|
@@ -207,12 +211,12 @@ class AttributesToken extends index_1.Token {
|
|
|
207
211
|
* @override
|
|
208
212
|
* @param token 待插入的子节点
|
|
209
213
|
* @param i 插入位置
|
|
210
|
-
* @throws `RangeError`
|
|
214
|
+
* @throws `RangeError` 标签不匹配
|
|
211
215
|
*/
|
|
212
216
|
insertAt(token, i = this.length) {
|
|
213
217
|
if (!(token instanceof attribute_1.AttributeToken)) {
|
|
214
218
|
if (String(token).trim()) {
|
|
215
|
-
|
|
219
|
+
this.constructorError('只能插入 AttributeToken');
|
|
216
220
|
}
|
|
217
221
|
return super.insertAt(token, i);
|
|
218
222
|
}
|
|
@@ -241,18 +245,17 @@ class AttributesToken extends index_1.Token {
|
|
|
241
245
|
}
|
|
242
246
|
return token;
|
|
243
247
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (this.type === 'ext-attrs' && typeof value === 'string' && value.includes('>')) {
|
|
248
|
+
setAttr(keyOrProp, value) {
|
|
249
|
+
if (typeof keyOrProp !== 'string') {
|
|
250
|
+
for (const [key, val] of Object.entries(keyOrProp)) {
|
|
251
|
+
this.setAttr(key, val);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
else if (this.type === 'ext-attrs' && typeof value === 'string' && value.includes('>')) {
|
|
252
256
|
throw new RangeError('扩展标签属性不能包含 ">"!');
|
|
253
257
|
}
|
|
254
|
-
key =
|
|
255
|
-
const attr = this.getAttrToken(key);
|
|
258
|
+
const key = keyOrProp.toLowerCase().trim(), attr = this.getAttrToken(key);
|
|
256
259
|
if (attr) {
|
|
257
260
|
attr.setValue(value);
|
|
258
261
|
return;
|
package/dist/src/converter.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare const ConverterToken_base: (abstract new (...args: any[]) => {
|
|
|
24
24
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
25
25
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
26
26
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
27
|
+
constructorError(msg: string): never;
|
|
27
28
|
}) & typeof Parser.Token;
|
|
28
29
|
/**
|
|
29
30
|
* 转换
|
|
@@ -45,13 +45,9 @@ export declare class ConverterRuleToken extends Token {
|
|
|
45
45
|
/**
|
|
46
46
|
* @override
|
|
47
47
|
* @param i 移除位置
|
|
48
|
-
* @throws `Error` 至少保留1个子节点
|
|
49
48
|
*/
|
|
50
49
|
removeAt(i: number): AtomToken;
|
|
51
|
-
/**
|
|
52
|
-
* @override
|
|
53
|
-
* @throws `Error` 请勿手动插入子节点
|
|
54
|
-
*/
|
|
50
|
+
/** @override */
|
|
55
51
|
insertAt(): never;
|
|
56
52
|
/** 修改为不转换 */
|
|
57
53
|
noConvert(): void;
|
|
@@ -135,20 +135,16 @@ class ConverterRuleToken extends index_1.Token {
|
|
|
135
135
|
/**
|
|
136
136
|
* @override
|
|
137
137
|
* @param i 移除位置
|
|
138
|
-
* @throws `Error` 至少保留1个子节点
|
|
139
138
|
*/
|
|
140
139
|
removeAt(i) {
|
|
141
140
|
if (this.length === 1) {
|
|
142
|
-
|
|
141
|
+
this.constructorError('需至少保留 1 个子节点');
|
|
143
142
|
}
|
|
144
143
|
return super.removeAt(i);
|
|
145
144
|
}
|
|
146
|
-
/**
|
|
147
|
-
* @override
|
|
148
|
-
* @throws `Error` 请勿手动插入子节点
|
|
149
|
-
*/
|
|
145
|
+
/** @override */
|
|
150
146
|
insertAt() {
|
|
151
|
-
|
|
147
|
+
this.constructorError('语法复杂,请勿尝试手动插入子节点');
|
|
152
148
|
}
|
|
153
149
|
/** 修改为不转换 */
|
|
154
150
|
noConvert() {
|
package/dist/src/extLink.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ declare const ExtLinkToken_base: (abstract new (...args: any[]) => {
|
|
|
18
18
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
19
19
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
20
20
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
21
|
+
constructorError(msg: string): never;
|
|
21
22
|
}) & typeof Parser.Token;
|
|
22
23
|
/**
|
|
23
24
|
* 外链
|
package/dist/src/gallery.d.ts
CHANGED
package/dist/src/gallery.js
CHANGED
|
@@ -16,7 +16,7 @@ class GalleryToken extends index_1.Token {
|
|
|
16
16
|
/* NOT FOR BROWSER */
|
|
17
17
|
/** 所有图片 */
|
|
18
18
|
get images() {
|
|
19
|
-
return this.childNodes.filter((
|
|
19
|
+
return this.childNodes.filter((0, debug_1.isToken)('gallery-image'));
|
|
20
20
|
}
|
|
21
21
|
/* NOT FOR BROWSER END */
|
|
22
22
|
/** @param inner 标签内部wikitext */
|
|
@@ -110,7 +110,6 @@ class GalleryToken extends index_1.Token {
|
|
|
110
110
|
}
|
|
111
111
|
throw new SyntaxError(`非法的文件名:${file}`);
|
|
112
112
|
}
|
|
113
|
-
/** @ignore */
|
|
114
113
|
insertAt(token, i = this.length) {
|
|
115
114
|
if (typeof token === 'string' && token.trim() || token instanceof noinclude_1.NoincludeToken) {
|
|
116
115
|
throw new RangeError('请勿向图库中插入不可见内容!');
|
package/dist/src/heading.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare const HeadingToken_base: (abstract new (...args: any[]) => {
|
|
|
14
14
|
setAttribute<T extends string>(key: T, value: TokenAttributeSetter<T>): void;
|
|
15
15
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
16
16
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
17
|
+
constructorError(msg: string): never;
|
|
17
18
|
}) & ((abstract new (...args: any[]) => {
|
|
18
19
|
removeAt(): never;
|
|
19
20
|
insertAt(token: string, i?: number | undefined): Parser.AstText;
|
|
@@ -27,6 +28,7 @@ declare const HeadingToken_base: (abstract new (...args: any[]) => {
|
|
|
27
28
|
setAttribute<T extends string>(key: T, value: TokenAttributeSetter<T>): void;
|
|
28
29
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
29
30
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
31
|
+
constructorError(msg: string): never;
|
|
30
32
|
}) & {
|
|
31
33
|
readonly fixed: true;
|
|
32
34
|
}) & typeof Parser.Token;
|
|
@@ -48,7 +50,7 @@ export declare class HeadingToken extends HeadingToken_base {
|
|
|
48
50
|
set level(n: number);
|
|
49
51
|
/** 内部wikitext */
|
|
50
52
|
get innerText(): string;
|
|
51
|
-
/** @throws `
|
|
53
|
+
/** @throws `Error` 首尾包含`=` */
|
|
52
54
|
set innerText(text: string);
|
|
53
55
|
/**
|
|
54
56
|
* @param level 标题层级
|
package/dist/src/heading.js
CHANGED
|
@@ -32,10 +32,10 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(index_1.Token)) {
|
|
|
32
32
|
get innerText() {
|
|
33
33
|
return this.firstChild.text();
|
|
34
34
|
}
|
|
35
|
-
/** @throws `
|
|
35
|
+
/** @throws `Error` 首尾包含`=` */
|
|
36
36
|
set innerText(text) {
|
|
37
37
|
if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
|
|
38
|
-
throw new
|
|
38
|
+
throw new Error('修改标题层级请使用 setLevel 方法!');
|
|
39
39
|
}
|
|
40
40
|
const { childNodes } = Parser.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
|
|
41
41
|
this.firstChild.replaceChildren(...childNodes);
|
package/dist/src/hidden.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare const HiddenToken_base: ((abstract new (...args: any[]) => {
|
|
|
10
10
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
11
11
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
12
12
|
replaceChildren(...elements: (string | import("..").AstNodes)[]): void;
|
|
13
|
+
constructorError(msg: string): never;
|
|
13
14
|
}) & {
|
|
14
15
|
readonly hidden: true;
|
|
15
16
|
}) & typeof Token;
|
package/dist/src/html.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare const HtmlToken_base: (abstract new (...args: any[]) => {
|
|
|
14
14
|
getAttrNames(): Set<string>;
|
|
15
15
|
getAttrs(): Record<string, string | true>;
|
|
16
16
|
setAttr(key: string, value: string | boolean): void;
|
|
17
|
+
setAttr(prop: Record<string, string | boolean>): void;
|
|
17
18
|
removeAttr(key: string): void;
|
|
18
19
|
toggleAttr(key: string, force?: boolean | undefined): void;
|
|
19
20
|
readonly length: number;
|
|
@@ -26,6 +27,7 @@ declare const HtmlToken_base: (abstract new (...args: any[]) => {
|
|
|
26
27
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
27
28
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
28
29
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
30
|
+
constructorError(msg: string): never;
|
|
29
31
|
}) & ((abstract new (...args: any[]) => {
|
|
30
32
|
removeAt(): never;
|
|
31
33
|
insertAt(token: string, i?: number | undefined): Parser.AstText;
|
|
@@ -39,6 +41,7 @@ declare const HtmlToken_base: (abstract new (...args: any[]) => {
|
|
|
39
41
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
40
42
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
41
43
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
44
|
+
constructorError(msg: string): never;
|
|
42
45
|
}) & {
|
|
43
46
|
readonly fixed: true;
|
|
44
47
|
}) & typeof Parser.Token;
|
package/dist/src/html.js
CHANGED
|
@@ -218,7 +218,6 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
218
218
|
this.#closing = true;
|
|
219
219
|
}
|
|
220
220
|
else {
|
|
221
|
-
Parser.warn('无法修复无效自封闭标签', (0, string_1.noWrap)(String(this)));
|
|
222
221
|
throw new Error(`无法修复无效自封闭标签:前文共有 ${imbalance} 个未匹配的闭合标签`);
|
|
223
222
|
}
|
|
224
223
|
}
|
|
@@ -53,7 +53,6 @@ export declare class ImageParameterToken extends Token {
|
|
|
53
53
|
* @throws `Error` 不接受自定义输入的图片参数
|
|
54
54
|
*/
|
|
55
55
|
insertAt(token: string, i?: number): AstText;
|
|
56
|
-
/** @ignore */
|
|
57
56
|
insertAt<T extends AstNodes>(token: T, i?: number): T;
|
|
58
57
|
/** 获取参数值 */
|
|
59
58
|
getValue(): string | true;
|
|
@@ -8,7 +8,6 @@ const constants_1 = require("../util/constants");
|
|
|
8
8
|
const Parser = require("../index");
|
|
9
9
|
const index_1 = require("./index");
|
|
10
10
|
exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
|
|
11
|
-
/** @ignore */
|
|
12
11
|
function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
|
|
13
12
|
val = val.trim();
|
|
14
13
|
let value = val.replace(/\0\d+t\x7F/gu, '').trim();
|
|
@@ -208,7 +207,6 @@ class ImageParameterToken extends index_1.Token {
|
|
|
208
207
|
#isVoid() {
|
|
209
208
|
return this.#syntax && !this.#syntax.includes('$1');
|
|
210
209
|
}
|
|
211
|
-
/** @ignore */
|
|
212
210
|
insertAt(token, i) {
|
|
213
211
|
if (!debug_1.Shadow.running && this.#isVoid()) {
|
|
214
212
|
throw new Error(`图片参数 ${this.name} 不接受自定义输入!`);
|
package/dist/src/imagemap.d.ts
CHANGED
package/dist/src/imagemap.js
CHANGED
|
@@ -18,12 +18,12 @@ class ImagemapToken extends index_1.Token {
|
|
|
18
18
|
type = 'ext-inner';
|
|
19
19
|
/** 图片 */
|
|
20
20
|
get image() {
|
|
21
|
-
return this.childNodes.find((
|
|
21
|
+
return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
|
|
22
22
|
}
|
|
23
23
|
/* NOT FOR BROWSER */
|
|
24
24
|
/** 链接 */
|
|
25
25
|
get links() {
|
|
26
|
-
return this.childNodes.filter((
|
|
26
|
+
return this.childNodes.filter((0, debug_1.isToken)('imagemap-link'));
|
|
27
27
|
}
|
|
28
28
|
/* NOT FOR BROWSER END */
|
|
29
29
|
/** @param inner 标签内部wikitext */
|
|
@@ -112,7 +112,6 @@ class ImagemapToken extends index_1.Token {
|
|
|
112
112
|
print() {
|
|
113
113
|
return super.print({ sep: '\n' });
|
|
114
114
|
}
|
|
115
|
-
/** @ignore */
|
|
116
115
|
insertAt(token, i) {
|
|
117
116
|
const { image } = this;
|
|
118
117
|
if (!image && (typeof token === 'string' || token.type === 'imagemap-link' || token.type === 'text')) {
|
|
@@ -18,6 +18,7 @@ declare const ImagemapLinkToken_base: ((abstract new (...args: any[]) => {
|
|
|
18
18
|
setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
|
|
19
19
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
20
20
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
21
|
+
constructorError(msg: string): never;
|
|
21
22
|
}) & {
|
|
22
23
|
readonly fixed: true;
|
|
23
24
|
}) & (abstract new (...args: any[]) => {
|
|
@@ -31,6 +32,7 @@ declare const ImagemapLinkToken_base: ((abstract new (...args: any[]) => {
|
|
|
31
32
|
setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
|
|
32
33
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
33
34
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
35
|
+
constructorError(msg: string): never;
|
|
34
36
|
}) & typeof Parser.Token;
|
|
35
37
|
/**
|
|
36
38
|
* `<imagemap>`内的链接
|
package/dist/src/index.d.ts
CHANGED
|
@@ -27,10 +27,8 @@ export declare class Token extends AstElement {
|
|
|
27
27
|
* @override
|
|
28
28
|
* @param child 待插入的子节点
|
|
29
29
|
* @param i 插入位置
|
|
30
|
-
* @throws `RangeError` 不可插入的子节点
|
|
31
30
|
*/
|
|
32
31
|
insertAt(child: string, i?: number): AstText;
|
|
33
|
-
/** @ignore */
|
|
34
32
|
insertAt<T extends AstNodes>(child: T, i?: number): T;
|
|
35
33
|
/**
|
|
36
34
|
* 规范化页面标题
|
|
@@ -44,14 +42,12 @@ export declare class Token extends AstElement {
|
|
|
44
42
|
/**
|
|
45
43
|
* @override
|
|
46
44
|
* @param i 移除位置
|
|
47
|
-
* @throws `Error` 不可移除的子节点
|
|
48
45
|
*/
|
|
49
46
|
removeAt(i: number): AstNodes;
|
|
50
47
|
/**
|
|
51
48
|
* 替换为同类节点
|
|
52
49
|
* @param token 待替换的节点
|
|
53
50
|
* @throws `Error` 不存在父节点
|
|
54
|
-
* @throws `Error` 待替换的节点具有不同属性
|
|
55
51
|
*/
|
|
56
52
|
safeReplaceWith(token: this): void;
|
|
57
53
|
/**
|
|
@@ -116,10 +112,7 @@ export declare class Token extends AstElement {
|
|
|
116
112
|
* @param title 标题
|
|
117
113
|
*/
|
|
118
114
|
isInterwiki(title: string): RegExpExecArray | null;
|
|
119
|
-
/**
|
|
120
|
-
* 深拷贝节点
|
|
121
|
-
* @throws `Error` 未定义复制方法
|
|
122
|
-
*/
|
|
115
|
+
/** 深拷贝节点 */
|
|
123
116
|
cloneNode(): this;
|
|
124
117
|
/** 获取全部章节 */
|
|
125
118
|
sections(): (AstText | Token)[][] | undefined;
|
package/dist/src/index.js
CHANGED
|
@@ -92,6 +92,12 @@ class Token extends element_1.AstElement {
|
|
|
92
92
|
if (n < this.#stage || !this.getAttribute('plain') || this.length === 0) {
|
|
93
93
|
return this;
|
|
94
94
|
}
|
|
95
|
+
else if (this.#stage >= constants_1.MAX_STAGE) {
|
|
96
|
+
if (this.type === 'root') {
|
|
97
|
+
Parser.error('已完全解析!');
|
|
98
|
+
}
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
95
101
|
switch (n) {
|
|
96
102
|
case 0:
|
|
97
103
|
if (this.type === 'root') {
|
|
@@ -182,6 +188,7 @@ class Token extends element_1.AstElement {
|
|
|
182
188
|
}
|
|
183
189
|
/** @private */
|
|
184
190
|
parse(n = constants_1.MAX_STAGE, include = false) {
|
|
191
|
+
n = Math.min(n, constants_1.MAX_STAGE);
|
|
185
192
|
while (this.#stage < n) {
|
|
186
193
|
this.parseOnce(this.#stage, include);
|
|
187
194
|
}
|
|
@@ -351,22 +358,21 @@ class Token extends element_1.AstElement {
|
|
|
351
358
|
super.setAttribute(key, value);
|
|
352
359
|
}
|
|
353
360
|
}
|
|
354
|
-
/** @ignore */
|
|
355
361
|
insertAt(child, i = this.length) {
|
|
356
362
|
const token = typeof child === 'string' ? new text_1.AstText(child) : child;
|
|
357
363
|
if (!debug_1.Shadow.running && this.#acceptable) {
|
|
358
364
|
const acceptableIndices = Object.fromEntries(Object.entries(this.#acceptable).map(([str, ranges]) => [str, ranges.applyTo(this.length + 1)])), nodesAfter = this.childNodes.slice(i), { constructor: { name: insertedName } } = token;
|
|
359
365
|
i += i < 0 ? this.length : 0;
|
|
360
366
|
if (!acceptableIndices[insertedName]?.includes(i)) {
|
|
361
|
-
|
|
367
|
+
this.constructorError(`的第 ${i} 个子节点不能为 ${insertedName}`);
|
|
362
368
|
}
|
|
363
369
|
else if (nodesAfter.some(({ constructor: { name } }, j) => !acceptableIndices[name]?.includes(i + j + 1))) {
|
|
364
|
-
|
|
370
|
+
this.constructorError(`插入新的第 ${i} 个子节点会破坏规定的顺序`);
|
|
365
371
|
}
|
|
366
372
|
}
|
|
367
373
|
super.insertAt(token, i);
|
|
368
374
|
const e = new Event('insert', { bubbles: true });
|
|
369
|
-
this.dispatchEvent(e, { type: 'insert', position: i < 0 ? i + this.length - 1 : i
|
|
375
|
+
this.dispatchEvent(e, { type: 'insert', position: i < 0 ? i + this.length - 1 : i });
|
|
370
376
|
if (token.constructor === Token && this.getAttribute('plain')) {
|
|
371
377
|
Parser.warn('您正将一个普通节点作为另一个普通节点的子节点,请考虑要不要执行 flatten 方法。');
|
|
372
378
|
}
|
|
@@ -394,19 +400,18 @@ class Token extends element_1.AstElement {
|
|
|
394
400
|
/**
|
|
395
401
|
* @override
|
|
396
402
|
* @param i 移除位置
|
|
397
|
-
* @throws `Error` 不可移除的子节点
|
|
398
403
|
*/
|
|
399
404
|
removeAt(i) {
|
|
400
405
|
i += i < 0 ? this.length : 0;
|
|
401
406
|
if (!debug_1.Shadow.running) {
|
|
402
407
|
const protectedIndices = this.#protectedChildren.applyTo(this.childNodes);
|
|
403
408
|
if (protectedIndices.includes(i)) {
|
|
404
|
-
|
|
409
|
+
this.constructorError(`的第 ${i} 个子节点不可移除`);
|
|
405
410
|
}
|
|
406
411
|
else if (this.#acceptable) {
|
|
407
412
|
const acceptableIndices = Object.fromEntries(Object.entries(this.#acceptable).map(([str, ranges]) => [str, ranges.applyTo(this.length - 1)])), nodesAfter = this.childNodes.slice(i + 1);
|
|
408
413
|
if (nodesAfter.some(({ constructor: { name } }, j) => !acceptableIndices[name]?.includes(i + j))) {
|
|
409
|
-
|
|
414
|
+
this.constructorError(`移除第 ${i} 个子节点会破坏规定的顺序`);
|
|
410
415
|
}
|
|
411
416
|
}
|
|
412
417
|
}
|
|
@@ -419,7 +424,6 @@ class Token extends element_1.AstElement {
|
|
|
419
424
|
* 替换为同类节点
|
|
420
425
|
* @param token 待替换的节点
|
|
421
426
|
* @throws `Error` 不存在父节点
|
|
422
|
-
* @throws `Error` 待替换的节点具有不同属性
|
|
423
427
|
*/
|
|
424
428
|
safeReplaceWith(token) {
|
|
425
429
|
const { parentNode } = this;
|
|
@@ -434,7 +438,7 @@ class Token extends element_1.AstElement {
|
|
|
434
438
|
}
|
|
435
439
|
catch (e) {
|
|
436
440
|
if (e instanceof assert.AssertionError) {
|
|
437
|
-
|
|
441
|
+
this.constructorError('带有不同的 #acceptable 属性');
|
|
438
442
|
}
|
|
439
443
|
throw e;
|
|
440
444
|
}
|
|
@@ -445,7 +449,7 @@ class Token extends element_1.AstElement {
|
|
|
445
449
|
token.type = 'plain';
|
|
446
450
|
}
|
|
447
451
|
const e = new Event('replace', { bubbles: true });
|
|
448
|
-
token.dispatchEvent(e, { type: 'replace', position: i, oldToken: this
|
|
452
|
+
token.dispatchEvent(e, { type: 'replace', position: i, oldToken: this });
|
|
449
453
|
}
|
|
450
454
|
/**
|
|
451
455
|
* 创建HTML注释
|
|
@@ -578,13 +582,10 @@ class Token extends element_1.AstElement {
|
|
|
578
582
|
cloneChildNodes() {
|
|
579
583
|
return this.childNodes.map(child => child.cloneNode());
|
|
580
584
|
}
|
|
581
|
-
/**
|
|
582
|
-
* 深拷贝节点
|
|
583
|
-
* @throws `Error` 未定义复制方法
|
|
584
|
-
*/
|
|
585
|
+
/** 深拷贝节点 */
|
|
585
586
|
cloneNode() {
|
|
586
587
|
if (this.constructor !== Token) {
|
|
587
|
-
|
|
588
|
+
this.constructorError('未定义复制方法');
|
|
588
589
|
}
|
|
589
590
|
const cloned = this.cloneChildNodes();
|
|
590
591
|
return debug_1.Shadow.run(() => {
|
|
@@ -643,8 +644,7 @@ class Token extends element_1.AstElement {
|
|
|
643
644
|
if (!parentNode) {
|
|
644
645
|
return undefined;
|
|
645
646
|
}
|
|
646
|
-
|
|
647
|
-
const isHtml = (node) => node.type === 'html', { childNodes, length } = parentNode, index = childNodes.indexOf(this);
|
|
647
|
+
const isHtml = (0, debug_1.isToken)('html'), { childNodes, length } = parentNode, index = childNodes.indexOf(this);
|
|
648
648
|
let i;
|
|
649
649
|
for (i = index - 1; i >= 0; i--) {
|
|
650
650
|
const child = childNodes[i];
|
package/dist/src/link/file.js
CHANGED
|
@@ -247,8 +247,9 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
247
247
|
* @override
|
|
248
248
|
* @throws `Error` 不适用于图片
|
|
249
249
|
*/
|
|
250
|
+
// eslint-disable-next-line class-methods-use-this
|
|
250
251
|
setLinkText() {
|
|
251
|
-
throw new Error(
|
|
252
|
+
throw new Error('setLinkText 方法不适用于图片!');
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
255
|
exports.FileToken = FileToken;
|
|
@@ -14,6 +14,7 @@ declare const GalleryImageToken_base: (abstract new (...args: any[]) => {
|
|
|
14
14
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
15
15
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
16
16
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
17
|
+
constructorError(msg: string): never;
|
|
17
18
|
}) & typeof Parser.FileToken;
|
|
18
19
|
/** 图库图片 */
|
|
19
20
|
export declare class GalleryImageToken extends GalleryImageToken_base {
|
package/dist/src/link/index.js
CHANGED
|
@@ -87,7 +87,7 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
87
87
|
*/
|
|
88
88
|
asSelfLink(fragment = this.fragment) {
|
|
89
89
|
if (!fragment?.trim()) {
|
|
90
|
-
throw new RangeError(
|
|
90
|
+
throw new RangeError('asSelfLink 方法必须指定非空的 fragment!');
|
|
91
91
|
}
|
|
92
92
|
this.#setFragment(fragment, false);
|
|
93
93
|
}
|
package/dist/src/magicLink.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare const MagicLinkToken_base: (abstract new (...args: any[]) => {
|
|
|
14
14
|
lint(start?: number | undefined): Parser.LintError[];
|
|
15
15
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
16
16
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
17
|
+
constructorError(msg: string): never;
|
|
17
18
|
}) & typeof Parser.Token;
|
|
18
19
|
/**
|
|
19
20
|
* 自由外链
|
|
@@ -47,10 +48,8 @@ export declare class MagicLinkToken extends MagicLinkToken_base {
|
|
|
47
48
|
* @override
|
|
48
49
|
* @param token 待插入的节点
|
|
49
50
|
* @param i 插入位置
|
|
50
|
-
* @throws `RangeError` 插入`{{!}}`或`{{=}}`以外的魔术字或模板
|
|
51
51
|
*/
|
|
52
52
|
insertAt(token: string, i?: number): AstText;
|
|
53
|
-
/** @ignore */
|
|
54
53
|
insertAt<T extends AstNodes>(token: T, i?: number): T;
|
|
55
54
|
/**
|
|
56
55
|
* 获取网址
|
package/dist/src/magicLink.js
CHANGED
|
@@ -90,15 +90,14 @@ class MagicLinkToken extends (0, syntax_1.syntax)(index_1.Token) {
|
|
|
90
90
|
return token;
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
/** @ignore */
|
|
94
93
|
insertAt(token, i) {
|
|
95
94
|
if (typeof token !== 'string') {
|
|
96
95
|
const { type, name } = token;
|
|
97
96
|
if (type === 'template') {
|
|
98
|
-
|
|
97
|
+
this.constructorError('不可插入模板');
|
|
99
98
|
}
|
|
100
99
|
else if (!debug_1.Shadow.running && type === 'magic-word' && name !== '!' && name !== '=') {
|
|
101
|
-
|
|
100
|
+
this.constructorError('不可插入 `{{!}}` 或 `{{=}}` 以外的魔术字');
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
103
|
return super.insertAt(token, i);
|
package/dist/src/nested.d.ts
CHANGED
package/dist/src/nested.js
CHANGED
|
@@ -65,11 +65,10 @@ class NestedToken extends index_1.Token {
|
|
|
65
65
|
* @override
|
|
66
66
|
* @param token 待插入的子节点
|
|
67
67
|
* @param i 插入位置
|
|
68
|
-
* @throws `TypeError` 不是许可的标签
|
|
69
68
|
*/
|
|
70
69
|
insertAt(token, i) {
|
|
71
70
|
if (typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)) {
|
|
72
|
-
|
|
71
|
+
this.constructorError(`只能以 ${this.#tags.join(' 或 ')} 标签作为子节点`);
|
|
73
72
|
}
|
|
74
73
|
return super.insertAt(token, i);
|
|
75
74
|
}
|
|
@@ -15,6 +15,7 @@ declare const NowikiBaseToken_base: ((abstract new (...args: any[]) => {
|
|
|
15
15
|
setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
|
|
16
16
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
17
17
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
18
|
+
constructorError(msg: string): never;
|
|
18
19
|
}) & {
|
|
19
20
|
readonly fixed: true;
|
|
20
21
|
}) & typeof Parser.Token;
|
|
@@ -13,6 +13,7 @@ declare const CommentToken_base: ((abstract new (...args: any[]) => {
|
|
|
13
13
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
14
14
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
15
15
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
16
|
+
constructorError(msg: string): never;
|
|
16
17
|
}) & {
|
|
17
18
|
readonly hidden: true;
|
|
18
19
|
}) & typeof NowikiBaseToken;
|
package/dist/src/nowiki/dd.js
CHANGED
|
@@ -13,6 +13,7 @@ declare const DoubleUnderscoreToken_base: (abstract new (...args: any[]) => {
|
|
|
13
13
|
lint(start?: number | undefined): Parser.LintError[];
|
|
14
14
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
15
15
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
16
|
+
constructorError(msg: string): never;
|
|
16
17
|
}) & ((abstract new (...args: any[]) => {
|
|
17
18
|
text(): string;
|
|
18
19
|
lint(): Parser.LintError[];
|
|
@@ -24,6 +25,7 @@ declare const DoubleUnderscoreToken_base: (abstract new (...args: any[]) => {
|
|
|
24
25
|
setAttribute<T_3 extends string>(key: T_3, value: TokenAttributeSetter<T_3>): void;
|
|
25
26
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
26
27
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
28
|
+
constructorError(msg: string): never;
|
|
27
29
|
}) & {
|
|
28
30
|
readonly hidden: true;
|
|
29
31
|
}) & typeof NowikiBaseToken;
|
package/dist/src/nowiki/hr.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare const HrToken_base: (abstract new (...args: any[]) => {
|
|
|
11
11
|
lint(start?: number | undefined): import("../..").LintError[];
|
|
12
12
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
13
13
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
14
|
+
constructorError(msg: string): never;
|
|
14
15
|
}) & (abstract new (...args: any[]) => {
|
|
15
16
|
prependNewLine(): string;
|
|
16
17
|
toString(omit?: Set<string> | undefined): string;
|
|
@@ -23,6 +24,7 @@ declare const HrToken_base: (abstract new (...args: any[]) => {
|
|
|
23
24
|
setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
|
|
24
25
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
25
26
|
replaceChildren(...elements: (string | import("../..").AstNodes)[]): void;
|
|
27
|
+
constructorError(msg: string): never;
|
|
26
28
|
}) & typeof NowikiBaseToken;
|
|
27
29
|
/** `<hr>` */
|
|
28
30
|
export declare class HrToken extends HrToken_base {
|
|
@@ -12,6 +12,7 @@ declare const ListToken_base: (abstract new (...args: any[]) => {
|
|
|
12
12
|
setAttribute<T extends string>(key: T, value: TokenAttributeSetter<T>): void;
|
|
13
13
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
14
14
|
replaceChildren(...elements: (string | import("../..").AstNodes)[]): void;
|
|
15
|
+
constructorError(msg: string): never;
|
|
15
16
|
}) & typeof ListBaseToken;
|
|
16
17
|
/** 位于行首的`;:*#` */
|
|
17
18
|
export declare class ListToken extends ListToken_base {
|