wikiparser-node 0.10.0 → 0.11.0-m
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/README.md +44 -32
- package/config/.schema.json +1 -8
- package/config/default.json +1 -2
- package/config/llwiki.json +1 -36
- package/config/moegirl.json +1 -45
- package/config/zhwiki.json +1 -467
- package/dist/index.d.ts +110 -0
- package/dist/lib/element.d.ts +48 -0
- package/dist/lib/node.d.ts +108 -0
- package/dist/lib/text.d.ts +30 -0
- package/dist/lib/title.d.ts +15 -0
- package/dist/mixin/hidden.d.ts +8 -0
- package/dist/parser/brackets.d.ts +12 -0
- package/dist/parser/commentAndExt.d.ts +8 -0
- package/dist/parser/converter.d.ts +7 -0
- package/dist/parser/externalLinks.d.ts +7 -0
- package/dist/parser/hrAndDoubleUnderscore.d.ts +11 -0
- package/dist/parser/html.d.ts +7 -0
- package/dist/parser/links.d.ts +7 -0
- package/dist/parser/list.d.ts +7 -0
- package/dist/parser/magicLinks.d.ts +7 -0
- package/dist/parser/quotes.d.ts +7 -0
- package/dist/parser/table.d.ts +11 -0
- package/dist/src/arg.d.ts +25 -0
- package/dist/src/atom/hidden.d.ts +5 -0
- package/dist/src/atom/index.d.ts +14 -0
- package/dist/src/attribute.d.ts +42 -0
- package/dist/src/attributes.d.ts +33 -0
- package/dist/src/converter.d.ts +29 -0
- package/dist/src/converterFlags.d.ts +27 -0
- package/dist/src/converterRule.d.ts +29 -0
- package/dist/src/extLink.d.ts +22 -0
- package/dist/src/gallery.d.ts +19 -0
- package/dist/src/hasNowiki/index.d.ts +14 -0
- package/dist/src/hasNowiki/pre.d.ts +13 -0
- package/dist/src/heading.d.ts +24 -0
- package/dist/src/html.d.ts +33 -0
- package/dist/src/imageParameter.d.ts +23 -0
- package/dist/src/imagemap.d.ts +26 -0
- package/dist/src/imagemapLink.d.ts +16 -0
- package/dist/src/index.d.ts +53 -0
- package/dist/src/link/category.d.ts +8 -0
- package/dist/src/link/file.d.ts +27 -0
- package/dist/src/link/galleryImage.d.ts +15 -0
- package/dist/src/link/index.d.ts +29 -0
- package/dist/src/magicLink.d.ts +14 -0
- package/dist/src/nested/choose.d.ts +13 -0
- package/dist/src/nested/combobox.d.ts +13 -0
- package/dist/src/nested/index.d.ts +20 -0
- package/dist/src/nested/references.d.ts +13 -0
- package/dist/src/nowiki/comment.d.ts +19 -0
- package/dist/src/nowiki/dd.d.ts +8 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +12 -0
- package/dist/src/nowiki/hr.d.ts +13 -0
- package/dist/src/nowiki/index.d.ts +18 -0
- package/dist/src/nowiki/list.d.ts +8 -0
- package/dist/src/nowiki/noinclude.d.ts +8 -0
- package/dist/src/nowiki/quote.d.ts +20 -0
- package/dist/src/onlyinclude.d.ts +17 -0
- package/dist/src/paramTag/index.d.ts +24 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -0
- package/dist/src/parameter.d.ts +28 -0
- package/dist/src/syntax.d.ts +15 -0
- package/dist/src/table/index.d.ts +16 -0
- package/dist/src/table/td.d.ts +39 -0
- package/dist/src/table/tr.d.ts +17 -0
- package/dist/src/tagPair/ext.d.ts +17 -0
- package/dist/src/tagPair/include.d.ts +16 -0
- package/dist/src/tagPair/index.d.ts +28 -0
- package/dist/src/transclude.d.ts +75 -0
- package/dist/util/lint.d.ts +28 -0
- package/dist/util/string.d.ts +31 -0
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/index.js +5 -257
- package/lib/element.js +7 -482
- package/lib/node.js +11 -540
- package/lib/text.js +3 -96
- package/lib/title.js +1 -28
- package/mixin/hidden.js +0 -3
- package/package.json +11 -5
- package/parser/brackets.js +3 -2
- package/parser/commentAndExt.js +8 -6
- package/parser/converter.js +1 -2
- package/parser/externalLinks.js +1 -2
- package/parser/hrAndDoubleUnderscore.js +1 -2
- package/parser/html.js +1 -2
- package/parser/links.js +5 -6
- package/parser/list.js +1 -2
- package/parser/magicLinks.js +1 -2
- package/parser/quotes.js +1 -2
- package/parser/table.js +1 -2
- package/src/arg.js +4 -118
- package/src/atom/hidden.js +0 -2
- package/src/atom/index.js +1 -18
- package/src/attribute.js +6 -190
- package/src/attributes.js +5 -308
- package/src/converter.js +3 -109
- package/src/converterFlags.js +1 -188
- package/src/converterRule.js +2 -184
- package/src/extLink.js +2 -122
- package/src/gallery.js +2 -56
- package/src/hasNowiki/index.js +1 -13
- package/src/hasNowiki/pre.js +1 -13
- package/src/heading.js +4 -55
- package/src/html.js +5 -120
- package/src/imageParameter.js +3 -165
- package/src/imagemap.js +3 -62
- package/src/imagemapLink.js +2 -14
- package/src/index.js +9 -530
- package/src/link/category.js +1 -32
- package/src/link/file.js +3 -158
- package/src/link/galleryImage.js +3 -61
- package/src/link/index.js +4 -273
- package/src/magicLink.js +6 -87
- package/src/nested/choose.js +1 -2
- package/src/nested/combobox.js +1 -2
- package/src/nested/index.js +8 -32
- package/src/nested/references.js +1 -2
- package/src/nowiki/comment.js +2 -26
- package/src/nowiki/dd.js +1 -47
- package/src/nowiki/doubleUnderscore.js +1 -31
- package/src/nowiki/hr.js +2 -21
- package/src/nowiki/index.js +2 -24
- package/src/nowiki/list.js +2 -5
- package/src/nowiki/noinclude.js +0 -14
- package/src/nowiki/quote.js +2 -16
- package/src/onlyinclude.js +2 -27
- package/src/paramTag/index.js +2 -25
- package/src/paramTag/inputbox.js +2 -5
- package/src/parameter.js +6 -148
- package/src/syntax.js +1 -69
- package/src/table/index.js +2 -939
- package/src/table/td.js +6 -226
- package/src/table/tr.js +3 -248
- package/src/tagPair/ext.js +4 -23
- package/src/tagPair/include.js +1 -25
- package/src/tagPair/index.js +3 -52
- package/src/transclude.js +6 -513
- package/typings/api.d.ts +9 -0
- package/typings/index.d.ts +51 -0
- package/typings/node.d.ts +16 -0
- package/typings/parser.d.ts +5 -0
- package/typings/token.d.ts +28 -0
- package/util/lint.js +2 -0
- package/util/string.js +0 -51
- package/lib/ranges.js +0 -130
- package/mixin/attributeParent.js +0 -117
- package/mixin/fixedToken.js +0 -40
- package/mixin/singleLine.js +0 -31
- package/mixin/sol.js +0 -54
- package/parser/selector.js +0 -177
- package/src/charinsert.js +0 -97
- package/tool/index.js +0 -1202
- package/util/debug.js +0 -73
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export = TdToken;
|
|
2
|
+
/**
|
|
3
|
+
* `<td>`、`<th>`和`<caption>`
|
|
4
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
|
|
5
|
+
*/
|
|
6
|
+
declare class TdToken extends TrToken {
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} syntax 单元格语法
|
|
9
|
+
* @param {string} inner 内部wikitext
|
|
10
|
+
* @param {import('../../../typings/token').accum} accum
|
|
11
|
+
*/
|
|
12
|
+
constructor(syntax: string, inner: string, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
|
|
13
|
+
/**
|
|
14
|
+
* 单元格类型
|
|
15
|
+
* @complexity `n`
|
|
16
|
+
*/
|
|
17
|
+
get subtype(): "caption" | "td" | "th";
|
|
18
|
+
/**
|
|
19
|
+
* 获取单元格语法信息
|
|
20
|
+
* @returns {{subtype: 'td'|'th'|'caption'}}
|
|
21
|
+
* @complexity `n`
|
|
22
|
+
*/
|
|
23
|
+
getSyntax(): {
|
|
24
|
+
subtype: 'td' | 'th' | 'caption';
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @override
|
|
28
|
+
* @returns {string}
|
|
29
|
+
* @complexity `n`
|
|
30
|
+
*/
|
|
31
|
+
override toString(selector: any): string;
|
|
32
|
+
/**
|
|
33
|
+
* @override
|
|
34
|
+
* @param {number} i 子节点位置
|
|
35
|
+
*/
|
|
36
|
+
override getGaps(i?: number): number;
|
|
37
|
+
#private;
|
|
38
|
+
}
|
|
39
|
+
import TrToken = require("./tr");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export = TrToken;
|
|
2
|
+
/**
|
|
3
|
+
* 表格行,含开头的换行,不含结尾的换行
|
|
4
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
|
|
5
|
+
*/
|
|
6
|
+
declare class TrToken extends Token {
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} syntax 表格语法
|
|
9
|
+
* @param {string} attr 表格属性
|
|
10
|
+
* @param {import('../../../typings/token').accum} accum
|
|
11
|
+
* @param {RegExp} pattern 表格语法正则
|
|
12
|
+
*/
|
|
13
|
+
constructor(syntax: string, attr?: string, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum, pattern?: RegExp);
|
|
14
|
+
/** @override */
|
|
15
|
+
override text(): string;
|
|
16
|
+
}
|
|
17
|
+
import Token = require("..");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export = ExtToken;
|
|
2
|
+
/**
|
|
3
|
+
* 扩展标签
|
|
4
|
+
* @classdesc `{childNodes: [AttributesToken, NowikiToken|Token]}`
|
|
5
|
+
*/
|
|
6
|
+
declare class ExtToken extends TagPairToken {
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} name 标签名
|
|
9
|
+
* @param {string} attr 标签属性
|
|
10
|
+
* @param {string} inner 内部wikitext
|
|
11
|
+
* @param {string|undefined} closed 是否封闭
|
|
12
|
+
* @param {import('../../../typings/token').accum} accum
|
|
13
|
+
*/
|
|
14
|
+
constructor(name: string, attr?: string, inner?: string, closed?: string | undefined, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
|
|
15
|
+
closed: boolean;
|
|
16
|
+
}
|
|
17
|
+
import TagPairToken = require(".");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export = IncludeToken;
|
|
2
|
+
/**
|
|
3
|
+
* `<includeonly>`或`<noinclude>`
|
|
4
|
+
* @classdesc `{childNodes: [AstText, AstText]}`
|
|
5
|
+
*/
|
|
6
|
+
declare class IncludeToken extends TagPairToken {
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} name 标签名
|
|
9
|
+
* @param {string} attr 标签属性
|
|
10
|
+
* @param {string|undefined} inner 内部wikitext
|
|
11
|
+
* @param {string|undefined} closed 是否封闭
|
|
12
|
+
* @param {import('../../../typings/token').accum} accum
|
|
13
|
+
*/
|
|
14
|
+
constructor(name: string, attr?: string, inner?: string | undefined, closed?: string | undefined, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
|
|
15
|
+
}
|
|
16
|
+
import TagPairToken = require(".");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export = TagPairToken;
|
|
2
|
+
/**
|
|
3
|
+
* 成对标签
|
|
4
|
+
* @classdesc `{childNodes: [AstText|AttributesToken, AstText|Token]}`
|
|
5
|
+
*/
|
|
6
|
+
declare class TagPairToken extends Token {
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} name 标签名
|
|
9
|
+
* @param {string|Token} attr 标签属性
|
|
10
|
+
* @param {string|Token} inner 内部wikitext
|
|
11
|
+
* @param {string|undefined} closed 是否封闭;约定`undefined`表示自闭合,`''`表示未闭合
|
|
12
|
+
* @param {import('../../../typings/token').accum} accum
|
|
13
|
+
*/
|
|
14
|
+
constructor(name: string, attr: string | Token, inner: string | Token, closed: string | undefined, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
|
|
15
|
+
/** getter */
|
|
16
|
+
get closed(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* @override
|
|
19
|
+
*/
|
|
20
|
+
override toString(selector: any): string;
|
|
21
|
+
/**
|
|
22
|
+
* @override
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
override text(): string;
|
|
26
|
+
#private;
|
|
27
|
+
}
|
|
28
|
+
import Token = require("..");
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export = TranscludeToken;
|
|
2
|
+
/**
|
|
3
|
+
* 模板或魔术字
|
|
4
|
+
* @classdesc `{childNodes: [AtomToken|SyntaxToken, ...ParameterToken]}`
|
|
5
|
+
*/
|
|
6
|
+
declare class TranscludeToken extends Token {
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} title 模板标题或魔术字
|
|
9
|
+
* @param {[string, string|undefined][]} parts 参数各部分
|
|
10
|
+
* @param {import('../../typings/token').accum} accum
|
|
11
|
+
* @complexity `n`
|
|
12
|
+
* @throws `SyntaxError` 非法的模板名称
|
|
13
|
+
*/
|
|
14
|
+
constructor(title: string, parts: [string, string | undefined][], config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum);
|
|
15
|
+
modifier: string;
|
|
16
|
+
/**
|
|
17
|
+
* 设置引用修饰符
|
|
18
|
+
* @param {string} modifier 引用修饰符
|
|
19
|
+
* @complexity `n`
|
|
20
|
+
*/
|
|
21
|
+
setModifier(modifier?: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @override
|
|
24
|
+
*/
|
|
25
|
+
override toString(selector: any): string;
|
|
26
|
+
/**
|
|
27
|
+
* @override
|
|
28
|
+
* @returns {string}
|
|
29
|
+
* @complexity `n`
|
|
30
|
+
*/
|
|
31
|
+
override text(): string;
|
|
32
|
+
/** 是否是模板 */
|
|
33
|
+
isTemplate(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @override
|
|
36
|
+
* @param {ParameterToken} token 待插入的子节点
|
|
37
|
+
* @param {number} i 插入位置
|
|
38
|
+
* @complexity `n`
|
|
39
|
+
*/
|
|
40
|
+
override insertAt(token: ParameterToken, i?: number): ParameterToken;
|
|
41
|
+
/**
|
|
42
|
+
* 获取所有参数
|
|
43
|
+
* @returns {ParameterToken[]}
|
|
44
|
+
* @complexity `n`
|
|
45
|
+
*/
|
|
46
|
+
getAllArgs(): ParameterToken[];
|
|
47
|
+
/**
|
|
48
|
+
* 获取匿名参数
|
|
49
|
+
* @complexity `n`
|
|
50
|
+
*/
|
|
51
|
+
getAnonArgs(): ParameterToken[];
|
|
52
|
+
/**
|
|
53
|
+
* 获取指定参数
|
|
54
|
+
* @param {string|number} key 参数名
|
|
55
|
+
* @param {boolean} exact 是否匹配匿名性
|
|
56
|
+
* @param {boolean} copy 是否返回一个备份
|
|
57
|
+
* @complexity `n`
|
|
58
|
+
*/
|
|
59
|
+
getArgs(key: string | number, exact: boolean, copy?: boolean): Set<ParameterToken>;
|
|
60
|
+
/**
|
|
61
|
+
* 获取重名参数
|
|
62
|
+
* @complexity `n`
|
|
63
|
+
* @returns {[string, ParameterToken[]][]}
|
|
64
|
+
*/
|
|
65
|
+
getDuplicatedArgs(): [string, ParameterToken[]][];
|
|
66
|
+
/**
|
|
67
|
+
* 对特定魔术字获取可能的取值
|
|
68
|
+
* @this {ParameterToken}}
|
|
69
|
+
* @throws `Error` 不是可接受的魔术字
|
|
70
|
+
*/
|
|
71
|
+
getPossibleValues(this: ParameterToken): Token[];
|
|
72
|
+
#private;
|
|
73
|
+
}
|
|
74
|
+
import Token = require(".");
|
|
75
|
+
import ParameterToken = require("./parameter");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type LintError = import('../../typings/token').LintError;
|
|
2
|
+
/**
|
|
3
|
+
* 生成对于子节点的LintError对象
|
|
4
|
+
* @param {Token} child 子节点
|
|
5
|
+
* @param {{top: number, left: number, start: number}} boundingRect 父节点的绝对定位
|
|
6
|
+
* @param {string} msg 错误信息
|
|
7
|
+
* @param {'error'|'warning'} severity 严重程度
|
|
8
|
+
* @returns {LintError}
|
|
9
|
+
*/
|
|
10
|
+
export function generateForChild(child: Token, boundingRect: {
|
|
11
|
+
top: number;
|
|
12
|
+
left: number;
|
|
13
|
+
start: number;
|
|
14
|
+
}, msg: string, severity?: 'error' | 'warning'): LintError;
|
|
15
|
+
/**
|
|
16
|
+
* 生成对于自己的LintError对象
|
|
17
|
+
* @param {Token} token 节点
|
|
18
|
+
* @param {{top: number, left: number, start: number}} boundingRect 绝对定位
|
|
19
|
+
* @param {string} msg 错误信息
|
|
20
|
+
* @param {'error'|'warning'} severity 严重程度
|
|
21
|
+
* @returns {LintError}
|
|
22
|
+
*/
|
|
23
|
+
export function generateForSelf(token: Token, boundingRect: {
|
|
24
|
+
top: number;
|
|
25
|
+
left: number;
|
|
26
|
+
start: number;
|
|
27
|
+
}, msg: string, severity?: 'error' | 'warning'): LintError;
|
|
28
|
+
import Token = require("../src");
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const extUrlCharFirst: "(?:\\[[\\da-f:.]+\\]|[^[\\]<>\"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])";
|
|
2
|
+
export const extUrlChar: "(?:[^[\\]<>\"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*";
|
|
3
|
+
/**
|
|
4
|
+
* remove half-parsed comment-like tokens
|
|
5
|
+
* @param {string} str 原字符串
|
|
6
|
+
*/
|
|
7
|
+
export function removeComment(str: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* escape special chars for RegExp constructor
|
|
10
|
+
* @param {string} str RegExp source
|
|
11
|
+
*/
|
|
12
|
+
export function escapeRegExp(str: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* a more sophisticated string-explode function
|
|
15
|
+
* @param {string} start start syntax of a nested AST node
|
|
16
|
+
* @param {string} end end syntax of a nested AST node
|
|
17
|
+
* @param {string} separator syntax for explosion
|
|
18
|
+
* @param {string} str string to be exploded
|
|
19
|
+
*/
|
|
20
|
+
export function explode(start: string, end: string, separator: string, str: string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* extract effective wikitext
|
|
23
|
+
* @param {(string|AstNode)[]} childNodes a Token's contents
|
|
24
|
+
* @param {string} separator delimiter between nodes
|
|
25
|
+
*/
|
|
26
|
+
export function text(childNodes: (string | import("../lib/node"))[], separator?: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* decode HTML entities
|
|
29
|
+
* @param {string} str 原字符串
|
|
30
|
+
*/
|
|
31
|
+
export function decodeHtml(str: string): string;
|
package/i18n/zh-hans.json
CHANGED
package/i18n/zh-hant.json
CHANGED
package/index.js
CHANGED
|
@@ -1,127 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
path = require('path');
|
|
5
|
-
|
|
6
|
-
const /** @type {Parser} */ Parser = {
|
|
3
|
+
const /** @type {import('./typings')} */ Parser = {
|
|
7
4
|
config: './config/default',
|
|
8
5
|
i18n: undefined,
|
|
9
6
|
|
|
10
7
|
MAX_STAGE: 11,
|
|
11
8
|
|
|
12
|
-
warning: true,
|
|
13
|
-
debugging: false,
|
|
14
|
-
running: false,
|
|
15
|
-
|
|
16
|
-
classes: {},
|
|
17
|
-
mixins: {},
|
|
18
|
-
parsers: {},
|
|
19
|
-
tool: {},
|
|
20
|
-
|
|
21
|
-
aliases: [
|
|
22
|
-
['AstText'],
|
|
23
|
-
['CommentToken', 'ExtToken', 'IncludeToken', 'NoincludeToken'],
|
|
24
|
-
['ArgToken', 'TranscludeToken', 'HeadingToken'],
|
|
25
|
-
['HtmlToken'],
|
|
26
|
-
['TableToken'],
|
|
27
|
-
['HrToken', 'DoubleUnderscoreToken'],
|
|
28
|
-
['LinkToken', 'FileToken', 'CategoryToken'],
|
|
29
|
-
['QuoteToken'],
|
|
30
|
-
['ExtLinkToken'],
|
|
31
|
-
['MagicLinkToken'],
|
|
32
|
-
['ListToken', 'DdToken'],
|
|
33
|
-
['ConverterToken'],
|
|
34
|
-
],
|
|
35
|
-
typeAliases: {
|
|
36
|
-
text: ['string', 'str'],
|
|
37
|
-
plain: ['regular', 'normal'],
|
|
38
|
-
// comment and extension
|
|
39
|
-
onlyinclude: ['only-include'],
|
|
40
|
-
noinclude: ['no-include'],
|
|
41
|
-
include: ['includeonly', 'include-only'],
|
|
42
|
-
comment: undefined,
|
|
43
|
-
ext: ['extension'],
|
|
44
|
-
'ext-attrs': ['extension-attrs', 'ext-attributes', 'extension-attributes'],
|
|
45
|
-
'ext-attr-dirty': ['extension-attr-dirty', 'ext-attribute-dirty', 'extension-attribute-dirty'],
|
|
46
|
-
'ext-attr': ['extension-attr', 'ext-attribute', 'extension-attribute'],
|
|
47
|
-
'attr-key': ['attribute-key'],
|
|
48
|
-
'attr-value': ['attribute-value', 'attr-val', 'attribute-val'],
|
|
49
|
-
'ext-inner': ['extension-inner'],
|
|
50
|
-
// triple brackets
|
|
51
|
-
arg: ['argument'],
|
|
52
|
-
'arg-name': ['argument-name'],
|
|
53
|
-
'arg-default': ['argument-default'],
|
|
54
|
-
hidden: ['arg-redundant'],
|
|
55
|
-
// double brackets
|
|
56
|
-
'magic-word': ['parser-function', 'parser-func'],
|
|
57
|
-
'magic-word-name': ['parser-function-name', 'parser-func-name'],
|
|
58
|
-
'invoke-function': ['invoke-func', 'lua-function', 'lua-func', 'module-function', 'module-func'],
|
|
59
|
-
'invoke-module': ['lua-module'],
|
|
60
|
-
template: undefined,
|
|
61
|
-
'template-name': undefined,
|
|
62
|
-
parameter: ['param'],
|
|
63
|
-
'parameter-key': ['param-key'],
|
|
64
|
-
'parameter-value': ['parameter-val', 'param-value', 'param-val'],
|
|
65
|
-
// heading
|
|
66
|
-
heading: ['header'],
|
|
67
|
-
'heading-title': ['header-title'],
|
|
68
|
-
'heading-trail': ['header-trail'],
|
|
69
|
-
// html
|
|
70
|
-
html: undefined,
|
|
71
|
-
'html-attrs': ['html-attributes'],
|
|
72
|
-
'html-attr-dirty': ['html-attribute-dirty'],
|
|
73
|
-
'html-attr': ['html-attribute'],
|
|
74
|
-
// table
|
|
75
|
-
table: undefined,
|
|
76
|
-
tr: ['table-row'],
|
|
77
|
-
td: ['table-cell', 'table-data'],
|
|
78
|
-
'table-syntax': undefined,
|
|
79
|
-
'table-attrs': ['tr-attrs', 'td-attrs', 'table-attributes', 'tr-attributes', 'td-attributes'],
|
|
80
|
-
'table-attr-dirty':
|
|
81
|
-
['tr-attr-dirty', 'td-attr-dirty', 'table-attribute-dirty', 'tr-attribute-dirty', 'td-attribute-dirty'],
|
|
82
|
-
'table-attr': ['tr-attr', 'td-attr', 'table-attribute', 'tr-attribute', 'td-attribute'],
|
|
83
|
-
'table-inter': undefined,
|
|
84
|
-
'td-inner': ['table-cell-inner', 'table-data-inner'],
|
|
85
|
-
// hr and double-underscore
|
|
86
|
-
hr: ['horizontal'],
|
|
87
|
-
'double-underscore': ['underscore', 'behavior-switch', 'behaviour-switch'],
|
|
88
|
-
// link
|
|
89
|
-
link: ['wikilink'],
|
|
90
|
-
'link-target': ['wikilink-target'],
|
|
91
|
-
'link-text': ['wikilink-text'],
|
|
92
|
-
category: ['category-link', 'cat', 'cat-link'],
|
|
93
|
-
file: ['file-link', 'image', 'image-link', 'img', 'img-link'],
|
|
94
|
-
'gallery-image': ['gallery-file', 'gallery-img'],
|
|
95
|
-
'imagemap-image': ['imagemap-file', 'imagemap-img', 'image-map-image', 'image-map-file', 'image-map-img'],
|
|
96
|
-
'image-parameter': ['img-parameter', 'image-param', 'img-param'],
|
|
97
|
-
// quotes
|
|
98
|
-
quote: ['quotes', 'quot', 'apostrophe', 'apostrophes', 'apos'],
|
|
99
|
-
// external link
|
|
100
|
-
'ext-link': ['external-link'],
|
|
101
|
-
'ext-link-text': ['external-link-text'],
|
|
102
|
-
'ext-link-url': ['external-link-url'],
|
|
103
|
-
// magic link
|
|
104
|
-
'free-ext-link': ['free-external-link', 'magic-link'],
|
|
105
|
-
// list
|
|
106
|
-
list: ['ol', 'ordered-list', 'ul', 'unordered-list', 'dl', 'description-list'],
|
|
107
|
-
dd: ['indent', 'indentation'],
|
|
108
|
-
// converter
|
|
109
|
-
converter: ['convert', 'conversion'],
|
|
110
|
-
'converter-flags': ['convert-flags', 'conversion-flags'],
|
|
111
|
-
'converter-flag': ['convert-flag', 'conversion-flag'],
|
|
112
|
-
'converter-rule': ['convert-rule', 'conversion-rule'],
|
|
113
|
-
'converter-rule-noconvert': ['convert-rule-noconvert', 'conversion-rule-noconvert'],
|
|
114
|
-
'converter-rule-variant': ['convert-rule-variant', 'conversion-rule-variant'],
|
|
115
|
-
'converter-rule-to': ['convert-rule-to', 'conversion-rule-to'],
|
|
116
|
-
'converter-rule-from': ['convert-rule-from', 'conversion-rule-from'],
|
|
117
|
-
// specific extensions
|
|
118
|
-
'param-line': ['parameter-line'],
|
|
119
|
-
'charinsert-line': undefined,
|
|
120
|
-
'imagemap-link': ['image-map-link'],
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
promises: [Promise.resolve()],
|
|
124
|
-
|
|
125
9
|
getConfig() {
|
|
126
10
|
if (typeof this.config === 'string') {
|
|
127
11
|
this.config = require(this.config);
|
|
@@ -159,22 +43,6 @@ const /** @type {Parser} */ Parser = {
|
|
|
159
43
|
}
|
|
160
44
|
const Title = require('./lib/title');
|
|
161
45
|
const titleObj = new Title(String(title), defaultNs, config, decode, selfLink);
|
|
162
|
-
if (token) {
|
|
163
|
-
/**
|
|
164
|
-
* 重建部分属性值
|
|
165
|
-
* @param {string[]} keys 属性键
|
|
166
|
-
*/
|
|
167
|
-
const build = keys => {
|
|
168
|
-
for (const key of keys) {
|
|
169
|
-
if (titleObj[key]?.includes('\0')) {
|
|
170
|
-
titleObj[key] = token.getAttribute('buildFromStr')(titleObj[key], 'text');
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
this.run(() => {
|
|
175
|
-
build(['title', 'main', 'fragment']);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
46
|
return titleObj;
|
|
179
47
|
},
|
|
180
48
|
|
|
@@ -188,139 +56,19 @@ const /** @type {Parser} */ Parser = {
|
|
|
188
56
|
token = new Token(wikitext, config);
|
|
189
57
|
try {
|
|
190
58
|
token.parse(maxStage, include);
|
|
191
|
-
} catch
|
|
192
|
-
if (e instanceof Error) {
|
|
193
|
-
const file = path.join(__dirname, 'errors', new Date().toISOString()),
|
|
194
|
-
stage = token.getAttribute('stage');
|
|
195
|
-
fs.writeFileSync(file, stage === this.MAX_STAGE ? wikitext : String(token));
|
|
196
|
-
fs.writeFileSync(`${file}.err`, e.stack);
|
|
197
|
-
fs.writeFileSync(`${file}.json`, JSON.stringify({
|
|
198
|
-
stage, include: token.getAttribute('include'), config: this.config,
|
|
199
|
-
}, null, '\t'));
|
|
200
|
-
}
|
|
201
|
-
throw e;
|
|
202
|
-
}
|
|
59
|
+
} catch {}
|
|
203
60
|
});
|
|
204
|
-
if (this.debugging) {
|
|
205
|
-
let restored = String(token),
|
|
206
|
-
process = '解析';
|
|
207
|
-
if (restored === wikitext) {
|
|
208
|
-
const entities = {lt: '<', gt: '>', amp: '&'};
|
|
209
|
-
restored = token.print().replace(
|
|
210
|
-
/<[^<]+?>|&([lg]t|amp);/gu,
|
|
211
|
-
/** @param {string} s */ (_, s) => s ? entities[s] : '',
|
|
212
|
-
);
|
|
213
|
-
process = '渲染HTML';
|
|
214
|
-
}
|
|
215
|
-
if (restored !== wikitext) {
|
|
216
|
-
const diff = require('./util/diff');
|
|
217
|
-
const {promises: {0: cur, length}} = this;
|
|
218
|
-
this.promises.unshift((async () => {
|
|
219
|
-
await cur;
|
|
220
|
-
this.error(`${process}过程中不可逆地修改了原始文本!`);
|
|
221
|
-
return diff(wikitext, restored, length);
|
|
222
|
-
})());
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
61
|
return token;
|
|
226
62
|
},
|
|
227
63
|
|
|
228
64
|
run(callback) {
|
|
229
|
-
|
|
230
|
-
this.running = true;
|
|
231
|
-
try {
|
|
232
|
-
const result = callback();
|
|
233
|
-
this.running = running;
|
|
234
|
-
return result;
|
|
235
|
-
} catch (e) {
|
|
236
|
-
this.running = running;
|
|
237
|
-
throw e;
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
warn(msg, ...args) {
|
|
242
|
-
if (this.warning) {
|
|
243
|
-
console.warn('\x1B[33m%s\x1B[0m', msg, ...args);
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
debug(msg, ...args) {
|
|
247
|
-
if (this.debugging) {
|
|
248
|
-
console.debug('\x1B[34m%s\x1B[0m', msg, ...args);
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
error(msg, ...args) {
|
|
252
|
-
console.error('\x1B[31m%s\x1B[0m', msg, ...args);
|
|
253
|
-
},
|
|
254
|
-
info(msg, ...args) {
|
|
255
|
-
console.info('\x1B[32m%s\x1B[0m', msg, ...args);
|
|
256
|
-
},
|
|
257
|
-
|
|
258
|
-
log(f) {
|
|
259
|
-
if (typeof f === 'function') {
|
|
260
|
-
console.log(String(f));
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
|
|
264
|
-
clearCache() {
|
|
265
|
-
const entries = [
|
|
266
|
-
...Object.entries(this.classes),
|
|
267
|
-
...Object.entries(this.mixins),
|
|
268
|
-
...Object.entries(this.parsers),
|
|
269
|
-
...Object.entries(this.tool),
|
|
270
|
-
];
|
|
271
|
-
for (const [, filePath] of entries) {
|
|
272
|
-
try {
|
|
273
|
-
delete require.cache[require.resolve(filePath)];
|
|
274
|
-
} catch {}
|
|
275
|
-
}
|
|
276
|
-
for (const [name, filePath] of entries) {
|
|
277
|
-
if (name in global) {
|
|
278
|
-
global[name] = require(filePath);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
isInterwiki(title, {interwiki} = Parser.getConfig()) {
|
|
284
|
-
title = String(title);
|
|
285
|
-
return new RegExp(`^(${interwiki.join('|')})\\s*:`, 'iu')
|
|
286
|
-
.exec(title.replaceAll('_', ' ').replace(/^\s*:?\s*/u, ''));
|
|
287
|
-
},
|
|
288
|
-
|
|
289
|
-
reparse(date) {
|
|
290
|
-
const main = fs.readdirSync(path.join(__dirname, 'errors'))
|
|
291
|
-
.find(name => name.startsWith(date) && name.endsWith('Z'));
|
|
292
|
-
if (!main) {
|
|
293
|
-
throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
|
|
294
|
-
}
|
|
295
|
-
const file = path.join(__dirname, 'errors', main),
|
|
296
|
-
wikitext = fs.readFileSync(file, 'utf8');
|
|
297
|
-
const {stage, include, config} = require(`${file}.json`),
|
|
298
|
-
Token = require('./src');
|
|
299
|
-
this.config = config;
|
|
300
|
-
return this.run(() => {
|
|
301
|
-
const halfParsed = stage < this.MAX_STAGE,
|
|
302
|
-
token = new Token(wikitext, this.getConfig(), halfParsed);
|
|
303
|
-
if (halfParsed) {
|
|
304
|
-
token.setAttribute('stage', stage).getAttribute('parseOnce')(stage, include);
|
|
305
|
-
} else {
|
|
306
|
-
token.parse(undefined, include);
|
|
307
|
-
}
|
|
308
|
-
fs.unlinkSync(file);
|
|
309
|
-
fs.unlinkSync(`${file}.err`);
|
|
310
|
-
fs.unlinkSync(`${file}.json`);
|
|
311
|
-
return token;
|
|
312
|
-
});
|
|
313
|
-
},
|
|
314
|
-
|
|
315
|
-
getTool() {
|
|
316
|
-
delete require.cache[require.resolve('./tool')];
|
|
317
|
-
return require('./tool');
|
|
65
|
+
return callback();
|
|
318
66
|
},
|
|
319
67
|
};
|
|
320
68
|
|
|
321
69
|
const /** @type {PropertyDescriptorMap} */ def = {},
|
|
322
|
-
immutable = new Set(['MAX_STAGE'
|
|
323
|
-
enumerable = new Set(['config', 'normalizeTitle', 'parse'
|
|
70
|
+
immutable = new Set(['MAX_STAGE']),
|
|
71
|
+
enumerable = new Set(['config', 'normalizeTitle', 'parse']);
|
|
324
72
|
for (const key in Parser) {
|
|
325
73
|
if (immutable.has(key)) {
|
|
326
74
|
def[key] = {enumerable: false, writable: false};
|