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
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import ExtLinkToken = require('./extLink');
|
|
1
|
+
import { Token } from '.';
|
|
2
|
+
import { NoincludeToken } from './nowiki/noinclude';
|
|
3
|
+
import { LinkToken } from './link';
|
|
4
|
+
import { ExtLinkToken } from './extLink';
|
|
5
|
+
import type { Title } from '../lib/title';
|
|
6
|
+
import type { AstText, ImagemapToken } from '../internal';
|
|
8
7
|
declare const ImagemapLinkToken_base: ((abstract new (...args: any[]) => {
|
|
9
8
|
removeAt(): never;
|
|
10
9
|
insertAt(token: string, i?: number | undefined): AstText;
|
|
11
|
-
insertAt<T extends import("../
|
|
10
|
+
insertAt<T extends import("../index").AstNodes>(token: T, i?: number | undefined): T;
|
|
12
11
|
length: number;
|
|
13
12
|
toString(selector?: string | undefined, separator?: string | undefined): string;
|
|
14
|
-
/**
|
|
15
|
-
* `<imagemap>`内的链接
|
|
16
|
-
* @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
|
|
17
|
-
*/
|
|
18
13
|
text(separator?: string | undefined): string;
|
|
19
14
|
}) & {
|
|
20
15
|
readonly fixed: true;
|
|
@@ -28,7 +23,7 @@ declare const ImagemapLinkToken_base: ((abstract new (...args: any[]) => {
|
|
|
28
23
|
* `<imagemap>`内的链接
|
|
29
24
|
* @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
|
|
30
25
|
*/
|
|
31
|
-
declare abstract class ImagemapLinkToken extends ImagemapLinkToken_base {
|
|
26
|
+
export declare abstract class ImagemapLinkToken extends ImagemapLinkToken_base {
|
|
32
27
|
/** @browser */
|
|
33
28
|
readonly type = "imagemap-link";
|
|
34
29
|
childNodes: [AstText, LinkToken | ExtLinkToken, NoincludeToken];
|
|
@@ -37,8 +32,8 @@ declare abstract class ImagemapLinkToken extends ImagemapLinkToken_base {
|
|
|
37
32
|
abstract get firstElementChild(): LinkToken | ExtLinkToken;
|
|
38
33
|
abstract get lastChild(): NoincludeToken;
|
|
39
34
|
abstract get lastElementChild(): NoincludeToken;
|
|
40
|
-
abstract get parentNode():
|
|
41
|
-
abstract get parentElement():
|
|
35
|
+
abstract get parentNode(): ImagemapToken | undefined;
|
|
36
|
+
abstract get parentElement(): ImagemapToken | undefined;
|
|
42
37
|
/** 内外链接 */
|
|
43
38
|
get link(): string | Title;
|
|
44
39
|
set link(link: string | Title);
|
|
@@ -48,6 +43,6 @@ declare abstract class ImagemapLinkToken extends ImagemapLinkToken_base {
|
|
|
48
43
|
* @param linkStuff 内外链接
|
|
49
44
|
* @param post 链接后的文本
|
|
50
45
|
*/
|
|
51
|
-
constructor(pre: string, linkStuff: [string, string | undefined, string | Title | undefined] | [string, string | undefined], post: string, config?:
|
|
46
|
+
constructor(pre: string, linkStuff: [string, string | undefined, string | Title | undefined] | [string, string | undefined], post: string, config?: import("../index").Config, accum?: Token[]);
|
|
52
47
|
}
|
|
53
|
-
export
|
|
48
|
+
export {};
|
package/dist/src/imagemapLink.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImagemapLinkToken = void 0;
|
|
4
|
+
const fixed_1 = require("../mixin/fixed");
|
|
5
|
+
const singleLine_1 = require("../mixin/singleLine");
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const noinclude_1 = require("./nowiki/noinclude");
|
|
9
|
+
const link_1 = require("./link");
|
|
10
|
+
const extLink_1 = require("./extLink");
|
|
9
11
|
/**
|
|
10
12
|
* `<imagemap>`内的链接
|
|
11
13
|
* @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
|
|
12
14
|
*/
|
|
13
|
-
class ImagemapLinkToken extends fixed(singleLine(Token)) {
|
|
15
|
+
class ImagemapLinkToken extends (0, fixed_1.fixed)((0, singleLine_1.singleLine)(_1.Token)) {
|
|
14
16
|
/** @browser */
|
|
15
17
|
type = 'imagemap-link';
|
|
16
18
|
/** 内外链接 */
|
|
@@ -26,13 +28,16 @@ class ImagemapLinkToken extends fixed(singleLine(Token)) {
|
|
|
26
28
|
* @param linkStuff 内外链接
|
|
27
29
|
* @param post 链接后的文本
|
|
28
30
|
*/
|
|
29
|
-
constructor(pre, linkStuff, post, config =
|
|
31
|
+
constructor(pre, linkStuff, post, config = index_1.default.getConfig(), accum = []) {
|
|
30
32
|
super(undefined, config, true, accum);
|
|
31
33
|
this.append(pre, linkStuff.length === 2
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
// @ts-expect-error abstract class
|
|
35
|
+
? new link_1.LinkToken(...linkStuff, config, accum)
|
|
36
|
+
// @ts-expect-error abstract class
|
|
37
|
+
: new extLink_1.ExtLinkToken(...linkStuff, config, accum),
|
|
38
|
+
// @ts-expect-error abstract class
|
|
39
|
+
new noinclude_1.NoincludeToken(post, config, accum));
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
exports.ImagemapLinkToken = ImagemapLinkToken;
|
|
43
|
+
index_1.default.classes['ImagemapLinkToken'] = __filename;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { AstRange } from '../lib/range';
|
|
2
|
+
import { AstElement } from '../lib/element';
|
|
3
|
+
import { AstText } from '../lib/text';
|
|
4
|
+
import type { Range } from '../lib/ranges';
|
|
5
|
+
import type { Title } from '../lib/title';
|
|
6
|
+
import type { AstNodes, IncludeToken, HtmlToken, ExtToken, TranscludeToken, CommentToken } from '../internal';
|
|
7
|
+
import type { TokenTypes, CaretPosition } from '../lib/node';
|
|
8
|
+
declare type TagToken = IncludeToken | ExtToken | HtmlToken;
|
|
8
9
|
/**
|
|
9
10
|
* 所有节点的基类
|
|
10
11
|
* @classdesc `{childNodes: ...(AstText|Token)}`
|
|
11
12
|
*/
|
|
12
|
-
declare class Token extends AstElement {
|
|
13
|
+
export declare class Token extends AstElement {
|
|
13
14
|
#private;
|
|
14
15
|
/** @browser */
|
|
15
16
|
type: TokenTypes;
|
|
@@ -18,9 +19,9 @@ declare class Token extends AstElement {
|
|
|
18
19
|
/** 所有内链、外链和自由外链 */
|
|
19
20
|
get links(): Token[];
|
|
20
21
|
/** 所有模板和模块 */
|
|
21
|
-
get embeds():
|
|
22
|
+
get embeds(): TranscludeToken[];
|
|
22
23
|
/** @browser */
|
|
23
|
-
constructor(wikitext?: string, config?:
|
|
24
|
+
constructor(wikitext?: string, config?: import("../index").Config, halfParsed?: boolean, accum?: Token[], acceptable?: Acceptable);
|
|
24
25
|
/**
|
|
25
26
|
* 解析、重构、生成部分Token的`name`属性
|
|
26
27
|
* @browser
|
|
@@ -37,22 +38,23 @@ declare class Token extends AstElement {
|
|
|
37
38
|
*/
|
|
38
39
|
insertAt(child: string, i?: number): AstText;
|
|
39
40
|
/** @ignore */
|
|
40
|
-
insertAt<T extends
|
|
41
|
+
insertAt<T extends AstNodes>(child: T, i?: number): T;
|
|
41
42
|
/**
|
|
42
43
|
* 规范化页面标题
|
|
43
44
|
* @browser
|
|
44
45
|
* @param title 标题(含或不含命名空间前缀)
|
|
45
46
|
* @param defaultNs 命名空间
|
|
47
|
+
* @param halfParsed 仅供内部使用
|
|
46
48
|
* @param decode 是否需要解码
|
|
47
49
|
* @param selfLink 是否允许selfLink
|
|
48
50
|
*/
|
|
49
|
-
normalizeTitle(title: string, defaultNs?: number, halfParsed?: boolean, decode?: boolean, selfLink?: boolean):
|
|
51
|
+
normalizeTitle(title: string, defaultNs?: number, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
|
|
50
52
|
/**
|
|
51
53
|
* @override
|
|
52
54
|
* @param i 移除位置
|
|
53
55
|
* @throws `Error` 不可移除的子节点
|
|
54
56
|
*/
|
|
55
|
-
removeAt(i: number):
|
|
57
|
+
removeAt(i: number): AstNodes;
|
|
56
58
|
/**
|
|
57
59
|
* 替换为同类节点
|
|
58
60
|
* @param token 待替换的节点
|
|
@@ -64,7 +66,7 @@ declare class Token extends AstElement {
|
|
|
64
66
|
* 创建HTML注释
|
|
65
67
|
* @param data 注释内容
|
|
66
68
|
*/
|
|
67
|
-
createComment(data?: string):
|
|
69
|
+
createComment(data?: string): CommentToken;
|
|
68
70
|
/**
|
|
69
71
|
* 创建标签
|
|
70
72
|
* @param tagName 标签名
|
|
@@ -82,6 +84,8 @@ declare class Token extends AstElement {
|
|
|
82
84
|
* @param data 文本内容
|
|
83
85
|
*/
|
|
84
86
|
createTextNode(data?: string): AstText;
|
|
87
|
+
/** 创建AstRange对象 */
|
|
88
|
+
createRange(): AstRange;
|
|
85
89
|
/**
|
|
86
90
|
* 找到给定位置所在的节点
|
|
87
91
|
* @param index 位置
|
|
@@ -98,24 +102,24 @@ declare class Token extends AstElement {
|
|
|
98
102
|
* @param index 位置
|
|
99
103
|
* @throws `Error` 不是根节点
|
|
100
104
|
*/
|
|
101
|
-
elementFromIndex(index?: number):
|
|
105
|
+
elementFromIndex(index?: number): AstNodes | undefined;
|
|
102
106
|
/**
|
|
103
107
|
* 找到给定位置所在的最外层节点
|
|
104
108
|
* @param x 列数
|
|
105
109
|
* @param y 行数
|
|
106
110
|
*/
|
|
107
|
-
elementFromPoint(x: number, y: number):
|
|
111
|
+
elementFromPoint(x: number, y: number): AstNodes | undefined;
|
|
108
112
|
/**
|
|
109
113
|
* 找到给定位置所在的所有节点
|
|
110
114
|
* @param index 位置
|
|
111
115
|
*/
|
|
112
|
-
elementsFromIndex(index?: number):
|
|
116
|
+
elementsFromIndex(index?: number): AstNodes[];
|
|
113
117
|
/**
|
|
114
118
|
* 找到给定位置所在的所有节点
|
|
115
119
|
* @param x 列数
|
|
116
120
|
* @param y 行数
|
|
117
121
|
*/
|
|
118
|
-
elementsFromPoint(x: number, y: number):
|
|
122
|
+
elementsFromPoint(x: number, y: number): AstNodes[];
|
|
119
123
|
/**
|
|
120
124
|
* 判断标题是否是跨维基链接
|
|
121
125
|
* @param title 标题
|
|
@@ -138,7 +142,7 @@ declare class Token extends AstElement {
|
|
|
138
142
|
* @param tag HTML标签名
|
|
139
143
|
* @throws `RangeError` 非法的标签或空标签
|
|
140
144
|
*/
|
|
141
|
-
findEnclosingHtml(tag?: string): [
|
|
145
|
+
findEnclosingHtml(tag?: string): [HtmlToken, HtmlToken] | undefined;
|
|
142
146
|
/** 获取全部分类 */
|
|
143
147
|
getCategories(): [string, string | undefined][];
|
|
144
148
|
/**
|
|
@@ -149,4 +153,4 @@ declare class Token extends AstElement {
|
|
|
149
153
|
/** 解析部分魔术字 */
|
|
150
154
|
solveConst(): void;
|
|
151
155
|
}
|
|
152
|
-
export
|
|
156
|
+
export {};
|
package/dist/src/index.js
CHANGED
|
@@ -37,18 +37,21 @@
|
|
|
37
37
|
// w: ExtLinkToken
|
|
38
38
|
// d: ListToken
|
|
39
39
|
// v: ConverterToken
|
|
40
|
-
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.Token = void 0;
|
|
41
42
|
const assert = require("assert/strict");
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const { MAX_STAGE, aliases } =
|
|
43
|
+
const string_1 = require("../util/string");
|
|
44
|
+
const ranges_1 = require("../lib/ranges");
|
|
45
|
+
const range_1 = require("../lib/range");
|
|
46
|
+
const index_1 = require("../index");
|
|
47
|
+
const { MAX_STAGE, aliases } = index_1.default;
|
|
48
|
+
const element_1 = require("../lib/element");
|
|
49
|
+
const text_1 = require("../lib/text");
|
|
47
50
|
/**
|
|
48
51
|
* 所有节点的基类
|
|
49
52
|
* @classdesc `{childNodes: ...(AstText|Token)}`
|
|
50
53
|
*/
|
|
51
|
-
class Token extends AstElement {
|
|
54
|
+
class Token extends element_1.AstElement {
|
|
52
55
|
/** @browser */
|
|
53
56
|
type = 'root';
|
|
54
57
|
/**
|
|
@@ -66,7 +69,7 @@ class Token extends AstElement {
|
|
|
66
69
|
/** @browser */
|
|
67
70
|
#include;
|
|
68
71
|
#acceptable;
|
|
69
|
-
#protectedChildren = new Ranges();
|
|
72
|
+
#protectedChildren = new ranges_1.Ranges();
|
|
70
73
|
/** 所有图片,包括图库 */
|
|
71
74
|
get images() {
|
|
72
75
|
return this.querySelectorAll('file, gallery-image, imagemap-image');
|
|
@@ -80,7 +83,7 @@ class Token extends AstElement {
|
|
|
80
83
|
return this.querySelectorAll('template, magic-word#invoke');
|
|
81
84
|
}
|
|
82
85
|
/** @browser */
|
|
83
|
-
constructor(wikitext, config =
|
|
86
|
+
constructor(wikitext, config = index_1.default.getConfig(), halfParsed = false, accum = [], acceptable) {
|
|
84
87
|
super();
|
|
85
88
|
if (typeof wikitext === 'string') {
|
|
86
89
|
this.insertAt(halfParsed ? wikitext : wikitext.replace(/[\0\x7F]/gu, ''));
|
|
@@ -104,7 +107,7 @@ class Token extends AstElement {
|
|
|
104
107
|
this.#parseCommentAndExt(include);
|
|
105
108
|
break;
|
|
106
109
|
case 1:
|
|
107
|
-
this.#
|
|
110
|
+
this.#parseBraces();
|
|
108
111
|
break;
|
|
109
112
|
case 2:
|
|
110
113
|
this.#parseHtml();
|
|
@@ -146,7 +149,8 @@ class Token extends AstElement {
|
|
|
146
149
|
buildFromStr(str, type) {
|
|
147
150
|
const nodes = str.split(/[\0\x7F]/u).map((s, i) => {
|
|
148
151
|
if (i % 2 === 0) {
|
|
149
|
-
return new AstText(s);
|
|
152
|
+
return new text_1.AstText(s);
|
|
153
|
+
// @ts-expect-error isNaN
|
|
150
154
|
}
|
|
151
155
|
else if (isNaN(s.at(-1))) {
|
|
152
156
|
return this.#accum[Number(s.slice(0, -1))];
|
|
@@ -193,9 +197,6 @@ class Token extends AstElement {
|
|
|
193
197
|
* @param include 是否嵌入
|
|
194
198
|
*/
|
|
195
199
|
parse(n = MAX_STAGE, include = false) {
|
|
196
|
-
if (!Number.isInteger(n)) {
|
|
197
|
-
this.typeError('parse', 'Number');
|
|
198
|
-
}
|
|
199
200
|
while (this.#stage < n) {
|
|
200
201
|
this.parseOnce(this.#stage, include);
|
|
201
202
|
}
|
|
@@ -211,16 +212,16 @@ class Token extends AstElement {
|
|
|
211
212
|
* @param includeOnly 是否嵌入
|
|
212
213
|
*/
|
|
213
214
|
#parseCommentAndExt(includeOnly) {
|
|
214
|
-
const parseCommentAndExt = require('../parser/commentAndExt');
|
|
215
|
+
const { parseCommentAndExt } = require('../parser/commentAndExt');
|
|
215
216
|
this.setText(parseCommentAndExt(String(this.firstChild), this.#config, this.#accum, includeOnly));
|
|
216
217
|
}
|
|
217
218
|
/**
|
|
218
219
|
* 解析花括号
|
|
219
220
|
* @browser
|
|
220
221
|
*/
|
|
221
|
-
#
|
|
222
|
-
const
|
|
223
|
-
const str = this.type === 'root' ? String(this.firstChild) : `\0${String(this.firstChild)}`, parsed =
|
|
222
|
+
#parseBraces() {
|
|
223
|
+
const { parseBraces } = require('../parser/braces');
|
|
224
|
+
const str = this.type === 'root' ? String(this.firstChild) : `\0${String(this.firstChild)}`, parsed = parseBraces(str, this.#config, this.#accum);
|
|
224
225
|
this.setText(this.type === 'root' ? parsed : parsed.slice(1));
|
|
225
226
|
}
|
|
226
227
|
/**
|
|
@@ -231,7 +232,7 @@ class Token extends AstElement {
|
|
|
231
232
|
if (this.#config.excludes?.includes('html')) {
|
|
232
233
|
return;
|
|
233
234
|
}
|
|
234
|
-
const parseHtml = require('../parser/html');
|
|
235
|
+
const { parseHtml } = require('../parser/html');
|
|
235
236
|
this.setText(parseHtml(String(this.firstChild), this.#config, this.#accum));
|
|
236
237
|
}
|
|
237
238
|
/**
|
|
@@ -242,7 +243,7 @@ class Token extends AstElement {
|
|
|
242
243
|
if (this.#config.excludes?.includes('table')) {
|
|
243
244
|
return;
|
|
244
245
|
}
|
|
245
|
-
const parseTable = require('../parser/table');
|
|
246
|
+
const { parseTable } = require('../parser/table');
|
|
246
247
|
this.setText(parseTable(this, this.#config, this.#accum));
|
|
247
248
|
}
|
|
248
249
|
/**
|
|
@@ -253,7 +254,7 @@ class Token extends AstElement {
|
|
|
253
254
|
if (this.#config.excludes?.includes('hr')) {
|
|
254
255
|
return;
|
|
255
256
|
}
|
|
256
|
-
const parseHrAndDoubleUnderscore = require('../parser/hrAndDoubleUnderscore');
|
|
257
|
+
const { parseHrAndDoubleUnderscore } = require('../parser/hrAndDoubleUnderscore');
|
|
257
258
|
this.setText(parseHrAndDoubleUnderscore(this, this.#config, this.#accum));
|
|
258
259
|
}
|
|
259
260
|
/**
|
|
@@ -261,7 +262,7 @@ class Token extends AstElement {
|
|
|
261
262
|
* @browser
|
|
262
263
|
*/
|
|
263
264
|
#parseLinks() {
|
|
264
|
-
const parseLinks = require('../parser/links');
|
|
265
|
+
const { parseLinks } = require('../parser/links');
|
|
265
266
|
this.setText(parseLinks(String(this.firstChild), this.#config, this.#accum));
|
|
266
267
|
}
|
|
267
268
|
/**
|
|
@@ -272,7 +273,7 @@ class Token extends AstElement {
|
|
|
272
273
|
if (this.#config.excludes?.includes('quote')) {
|
|
273
274
|
return;
|
|
274
275
|
}
|
|
275
|
-
const parseQuotes = require('../parser/quotes');
|
|
276
|
+
const { parseQuotes } = require('../parser/quotes');
|
|
276
277
|
const lines = String(this.firstChild).split('\n');
|
|
277
278
|
for (let i = 0; i < lines.length; i++) {
|
|
278
279
|
lines[i] = parseQuotes(lines[i], this.#config, this.#accum);
|
|
@@ -287,7 +288,7 @@ class Token extends AstElement {
|
|
|
287
288
|
if (this.#config.excludes?.includes('extLink')) {
|
|
288
289
|
return;
|
|
289
290
|
}
|
|
290
|
-
const parseExternalLinks = require('../parser/externalLinks');
|
|
291
|
+
const { parseExternalLinks } = require('../parser/externalLinks');
|
|
291
292
|
this.setText(parseExternalLinks(String(this.firstChild), this.#config, this.#accum));
|
|
292
293
|
}
|
|
293
294
|
/**
|
|
@@ -298,7 +299,7 @@ class Token extends AstElement {
|
|
|
298
299
|
if (this.#config.excludes?.includes('magicLink')) {
|
|
299
300
|
return;
|
|
300
301
|
}
|
|
301
|
-
const parseMagicLinks = require('../parser/magicLinks');
|
|
302
|
+
const { parseMagicLinks } = require('../parser/magicLinks');
|
|
302
303
|
this.setText(parseMagicLinks(String(this.firstChild), this.#config, this.#accum));
|
|
303
304
|
}
|
|
304
305
|
/**
|
|
@@ -309,7 +310,7 @@ class Token extends AstElement {
|
|
|
309
310
|
if (this.#config.excludes?.includes('list')) {
|
|
310
311
|
return;
|
|
311
312
|
}
|
|
312
|
-
const parseList = require('../parser/list');
|
|
313
|
+
const { parseList } = require('../parser/list');
|
|
313
314
|
const lines = String(this.firstChild).split('\n');
|
|
314
315
|
let i = this.type === 'root' || this.type === 'ext-inner' && this.name === 'poem' ? 0 : 1;
|
|
315
316
|
for (; i < lines.length; i++) {
|
|
@@ -323,7 +324,7 @@ class Token extends AstElement {
|
|
|
323
324
|
*/
|
|
324
325
|
#parseConverter() {
|
|
325
326
|
if (this.#config.variants.length > 0) {
|
|
326
|
-
const parseConverter = require('../parser/converter');
|
|
327
|
+
const { parseConverter } = require('../parser/converter');
|
|
327
328
|
this.setText(parseConverter(String(this.firstChild), this.#config, this.#accum));
|
|
328
329
|
}
|
|
329
330
|
}
|
|
@@ -354,7 +355,7 @@ class Token extends AstElement {
|
|
|
354
355
|
case 'acceptable':
|
|
355
356
|
return (this.#acceptable ? { ...this.#acceptable } : undefined);
|
|
356
357
|
case 'protectedChildren':
|
|
357
|
-
return new Ranges(this.#protectedChildren);
|
|
358
|
+
return new ranges_1.Ranges(this.#protectedChildren);
|
|
358
359
|
default:
|
|
359
360
|
return super.getAttribute(key);
|
|
360
361
|
}
|
|
@@ -375,7 +376,7 @@ class Token extends AstElement {
|
|
|
375
376
|
if (k.startsWith('Stage-')) {
|
|
376
377
|
for (let i = 0; i <= Number(k.slice(6)); i++) {
|
|
377
378
|
for (const type of aliases[i]) {
|
|
378
|
-
acceptable[type] = new Ranges(v);
|
|
379
|
+
acceptable[type] = new ranges_1.Ranges(v);
|
|
379
380
|
}
|
|
380
381
|
}
|
|
381
382
|
}
|
|
@@ -383,7 +384,7 @@ class Token extends AstElement {
|
|
|
383
384
|
delete acceptable[k.slice(1)];
|
|
384
385
|
}
|
|
385
386
|
else {
|
|
386
|
-
acceptable[k] = new Ranges(v);
|
|
387
|
+
acceptable[k] = new ranges_1.Ranges(v);
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
}
|
|
@@ -400,8 +401,8 @@ class Token extends AstElement {
|
|
|
400
401
|
}
|
|
401
402
|
/** @ignore */
|
|
402
403
|
insertAt(child, i = this.length) {
|
|
403
|
-
const token = typeof child === 'string' ? new AstText(child) : child;
|
|
404
|
-
if (!
|
|
404
|
+
const token = typeof child === 'string' ? new text_1.AstText(child) : child;
|
|
405
|
+
if (!index_1.default.running && this.#acceptable) {
|
|
405
406
|
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, k = i < 0 ? i + this.length : i;
|
|
406
407
|
if (!acceptableIndices[insertedName]?.includes(k)) {
|
|
407
408
|
throw new RangeError(`${this.constructor.name} 的第 ${k} 个子节点不能为 ${insertedName}!`);
|
|
@@ -421,15 +422,16 @@ class Token extends AstElement {
|
|
|
421
422
|
* @browser
|
|
422
423
|
* @param title 标题(含或不含命名空间前缀)
|
|
423
424
|
* @param defaultNs 命名空间
|
|
425
|
+
* @param halfParsed 仅供内部使用
|
|
424
426
|
* @param decode 是否需要解码
|
|
425
427
|
* @param selfLink 是否允许selfLink
|
|
426
428
|
*/
|
|
427
429
|
normalizeTitle(title, defaultNs = 0, halfParsed = false, decode = false, selfLink = false) {
|
|
428
|
-
return
|
|
430
|
+
return index_1.default.normalizeTitle(title, defaultNs, this.#include, this.#config, halfParsed, decode, selfLink);
|
|
429
431
|
}
|
|
430
432
|
/** @private */
|
|
431
433
|
protectChildren(...args) {
|
|
432
|
-
this.#protectedChildren.push(...new Ranges(args));
|
|
434
|
+
this.#protectedChildren.push(...new ranges_1.Ranges(args));
|
|
433
435
|
}
|
|
434
436
|
/**
|
|
435
437
|
* @override
|
|
@@ -437,11 +439,8 @@ class Token extends AstElement {
|
|
|
437
439
|
* @throws `Error` 不可移除的子节点
|
|
438
440
|
*/
|
|
439
441
|
removeAt(i) {
|
|
440
|
-
if (!Number.isInteger(i)) {
|
|
441
|
-
this.typeError('removeAt', 'Number');
|
|
442
|
-
}
|
|
443
442
|
const iPos = i < 0 ? i + this.length : i;
|
|
444
|
-
if (!
|
|
443
|
+
if (!index_1.default.running) {
|
|
445
444
|
const protectedIndices = this.#protectedChildren.applyTo(this.childNodes);
|
|
446
445
|
if (protectedIndices.includes(iPos)) {
|
|
447
446
|
throw new Error(`${this.constructor.name} 的第 ${i} 个子节点不可移除!`);
|
|
@@ -492,12 +491,10 @@ class Token extends AstElement {
|
|
|
492
491
|
* @param data 注释内容
|
|
493
492
|
*/
|
|
494
493
|
createComment(data = '') {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
return this.typeError('createComment', 'String');
|
|
494
|
+
const { CommentToken } = require('./nowiki/comment');
|
|
495
|
+
const config = this.getAttribute('config');
|
|
496
|
+
// @ts-expect-error abstract class
|
|
497
|
+
return index_1.default.run(() => new CommentToken(data.replaceAll('-->', '-->'), true, config));
|
|
501
498
|
}
|
|
502
499
|
/**
|
|
503
500
|
* 创建标签
|
|
@@ -508,22 +505,22 @@ class Token extends AstElement {
|
|
|
508
505
|
* @throws `RangeError` 非法的标签名
|
|
509
506
|
*/
|
|
510
507
|
createElement(tagName, { selfClosing, closing } = {}) {
|
|
511
|
-
if (typeof tagName !== 'string') {
|
|
512
|
-
this.typeError('createElement', 'String');
|
|
513
|
-
}
|
|
514
508
|
const config = this.getAttribute('config'), include = this.getAttribute('include');
|
|
515
509
|
if (tagName === (include ? 'noinclude' : 'includeonly')) {
|
|
516
|
-
const IncludeToken = require('./tagPair/include');
|
|
517
|
-
return
|
|
510
|
+
const { IncludeToken } = require('./tagPair/include');
|
|
511
|
+
return index_1.default.run(
|
|
512
|
+
// @ts-expect-error abstract class
|
|
518
513
|
() => new IncludeToken(tagName, '', undefined, selfClosing ? undefined : tagName, config));
|
|
519
514
|
}
|
|
520
515
|
else if (config.ext.includes(tagName)) {
|
|
521
|
-
const ExtToken = require('./tagPair/ext');
|
|
522
|
-
|
|
516
|
+
const { ExtToken } = require('./tagPair/ext');
|
|
517
|
+
// @ts-expect-error abstract class
|
|
518
|
+
return index_1.default.run(() => new ExtToken(tagName, '', '', selfClosing ? undefined : '', config));
|
|
523
519
|
}
|
|
524
520
|
else if (config.html.flat().includes(tagName)) {
|
|
525
|
-
const HtmlToken = require('./html');
|
|
526
|
-
|
|
521
|
+
const { HtmlToken } = require('./html');
|
|
522
|
+
// @ts-expect-error abstract class
|
|
523
|
+
return index_1.default.run(() => new HtmlToken(tagName, '', closing, selfClosing, config));
|
|
527
524
|
}
|
|
528
525
|
throw new RangeError(`非法的标签名:${tagName}`);
|
|
529
526
|
}
|
|
@@ -532,7 +529,11 @@ class Token extends AstElement {
|
|
|
532
529
|
* @param data 文本内容
|
|
533
530
|
*/
|
|
534
531
|
createTextNode(data = '') {
|
|
535
|
-
return
|
|
532
|
+
return new text_1.AstText(data);
|
|
533
|
+
}
|
|
534
|
+
/** 创建AstRange对象 */
|
|
535
|
+
createRange() {
|
|
536
|
+
return new range_1.AstRange();
|
|
536
537
|
}
|
|
537
538
|
/**
|
|
538
539
|
* 找到给定位置所在的节点
|
|
@@ -542,9 +543,6 @@ class Token extends AstElement {
|
|
|
542
543
|
if (index === undefined) {
|
|
543
544
|
return undefined;
|
|
544
545
|
}
|
|
545
|
-
else if (!Number.isInteger(index)) {
|
|
546
|
-
this.typeError('caretPositionFromIndex', 'Number');
|
|
547
|
-
}
|
|
548
546
|
const { length } = String(this);
|
|
549
547
|
if (index > length || index < -length) {
|
|
550
548
|
return undefined;
|
|
@@ -588,9 +586,6 @@ class Token extends AstElement {
|
|
|
588
586
|
if (index === undefined) {
|
|
589
587
|
return undefined;
|
|
590
588
|
}
|
|
591
|
-
else if (!Number.isInteger(index)) {
|
|
592
|
-
this.typeError('elementFromIndex', 'Number');
|
|
593
|
-
}
|
|
594
589
|
else if (this.type !== 'root') {
|
|
595
590
|
throw new Error('elementFromIndex方法只可用于根节点!');
|
|
596
591
|
}
|
|
@@ -635,7 +630,7 @@ class Token extends AstElement {
|
|
|
635
630
|
* @param title 标题
|
|
636
631
|
*/
|
|
637
632
|
isInterwiki(title) {
|
|
638
|
-
return
|
|
633
|
+
return index_1.default.isInterwiki(title, this.#config);
|
|
639
634
|
}
|
|
640
635
|
/** @private */
|
|
641
636
|
cloneChildNodes() {
|
|
@@ -650,7 +645,7 @@ class Token extends AstElement {
|
|
|
650
645
|
throw new Error(`未定义 ${this.constructor.name} 的复制方法!`);
|
|
651
646
|
}
|
|
652
647
|
const cloned = this.cloneChildNodes();
|
|
653
|
-
return
|
|
648
|
+
return index_1.default.run(() => {
|
|
654
649
|
const token = new Token(undefined, this.#config, false, [], this.#acceptable);
|
|
655
650
|
token.type = this.type;
|
|
656
651
|
token.append(...cloned);
|
|
@@ -689,7 +684,7 @@ class Token extends AstElement {
|
|
|
689
684
|
* @param n 章节序号
|
|
690
685
|
*/
|
|
691
686
|
section(n) {
|
|
692
|
-
return
|
|
687
|
+
return this.sections()?.[n];
|
|
693
688
|
}
|
|
694
689
|
/**
|
|
695
690
|
* 获取指定的外层HTML标签
|
|
@@ -697,9 +692,6 @@ class Token extends AstElement {
|
|
|
697
692
|
* @throws `RangeError` 非法的标签或空标签
|
|
698
693
|
*/
|
|
699
694
|
findEnclosingHtml(tag) {
|
|
700
|
-
if (tag !== undefined && typeof tag !== 'string') {
|
|
701
|
-
this.typeError('findEnclosingHtml', 'String');
|
|
702
|
-
}
|
|
703
695
|
const lcTag = tag?.toLowerCase();
|
|
704
696
|
if (lcTag !== undefined && !this.#config.html.slice(0, 2).flat().includes(lcTag)) {
|
|
705
697
|
throw new RangeError(`非法的标签或空标签:${lcTag}`);
|
|
@@ -708,7 +700,7 @@ class Token extends AstElement {
|
|
|
708
700
|
if (!parentNode) {
|
|
709
701
|
return undefined;
|
|
710
702
|
}
|
|
711
|
-
const { childNodes } = parentNode, index = childNodes.indexOf(this);
|
|
703
|
+
const { childNodes, length } = parentNode, index = childNodes.indexOf(this);
|
|
712
704
|
let i;
|
|
713
705
|
for (i = index - 1; i >= 0; i--) {
|
|
714
706
|
const { type, name, selfClosing, closing, } = childNodes[i];
|
|
@@ -720,15 +712,13 @@ class Token extends AstElement {
|
|
|
720
712
|
return parentNode.findEnclosingHtml(lcTag);
|
|
721
713
|
}
|
|
722
714
|
const opening = childNodes[i];
|
|
723
|
-
for (i = index + 1; i <
|
|
715
|
+
for (i = index + 1; i < length; i++) {
|
|
724
716
|
const { type, name, selfClosing, closing, } = childNodes[i];
|
|
725
717
|
if (type === 'html' && name === opening.name && selfClosing === false && closing === true) {
|
|
726
718
|
break;
|
|
727
719
|
}
|
|
728
720
|
}
|
|
729
|
-
return i === childNodes
|
|
730
|
-
? parentNode.findEnclosingHtml(lcTag)
|
|
731
|
-
: [opening, childNodes[i]];
|
|
721
|
+
return i === length ? parentNode.findEnclosingHtml(lcTag) : [opening, childNodes[i]];
|
|
732
722
|
}
|
|
733
723
|
/** 获取全部分类 */
|
|
734
724
|
getCategories() {
|
|
@@ -751,7 +741,7 @@ class Token extends AstElement {
|
|
|
751
741
|
}
|
|
752
742
|
this.normalize();
|
|
753
743
|
const textNodes = [...this.childNodes.entries()]
|
|
754
|
-
.filter(([, { type }]) => type === 'text'), indices = textNodes.map(([i]) => this.getRelativeIndex(i)), token =
|
|
744
|
+
.filter(([, { type }]) => type === 'text'), indices = textNodes.map(([i]) => this.getRelativeIndex(i)), token = index_1.default.run(() => {
|
|
755
745
|
const root = new Token((0, string_1.text)(textNodes.map(([, str]) => str)), this.getAttribute('config'));
|
|
756
746
|
return root.setAttribute('stage', 6).parse(7);
|
|
757
747
|
});
|
|
@@ -786,7 +776,7 @@ class Token extends AstElement {
|
|
|
786
776
|
const key = String(childNodes[1] ?? '').trim();
|
|
787
777
|
let defaultVal = '', found = false, transclusion = false;
|
|
788
778
|
for (let j = 2; j < length; j++) {
|
|
789
|
-
const { anon, name: option, value, firstChild } = childNodes[j];
|
|
779
|
+
const { anon, name: option, value, firstChild, } = childNodes[j];
|
|
790
780
|
transclusion = Boolean(firstChild.querySelector('magic-word, template'));
|
|
791
781
|
if (anon) {
|
|
792
782
|
if (j === length - 1) {
|
|
@@ -822,5 +812,5 @@ class Token extends AstElement {
|
|
|
822
812
|
}
|
|
823
813
|
}
|
|
824
814
|
}
|
|
825
|
-
|
|
826
|
-
|
|
815
|
+
exports.Token = Token;
|
|
816
|
+
index_1.default.classes['Token'] = __filename;
|