wikiparser-node 0.11.0 → 1.0.0-beta.1
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 +61 -113
- package/dist/index.js +314 -0
- package/dist/lib/element.d.ts +122 -108
- package/dist/lib/element.js +656 -0
- package/dist/lib/node.d.ts +115 -221
- package/dist/lib/node.js +473 -0
- package/dist/lib/ranges.d.ts +27 -26
- package/dist/lib/ranges.js +130 -0
- package/dist/lib/text.d.ts +36 -28
- package/dist/lib/text.js +215 -0
- package/dist/lib/title.d.ts +26 -12
- package/dist/lib/title.js +108 -0
- package/dist/mixin/attributesParent.js +90 -0
- package/dist/mixin/fixed.js +29 -0
- package/dist/mixin/hidden.js +19 -0
- package/dist/mixin/singleLine.js +23 -0
- package/dist/mixin/sol.js +41 -0
- package/dist/parser/brackets.js +118 -0
- package/dist/parser/commentAndExt.js +48 -0
- package/dist/parser/converter.js +31 -0
- package/dist/parser/externalLinks.js +22 -0
- package/dist/parser/hrAndDoubleUnderscore.js +35 -0
- package/dist/parser/html.js +29 -0
- package/dist/parser/links.js +86 -0
- package/dist/parser/list.js +51 -0
- package/dist/parser/magicLinks.js +32 -0
- package/dist/parser/quotes.js +57 -0
- package/dist/parser/selector.js +158 -0
- package/dist/parser/table.js +108 -0
- package/dist/src/arg.d.ts +47 -23
- package/dist/src/arg.js +196 -0
- package/dist/src/atom.d.ts +12 -0
- package/dist/src/atom.js +22 -0
- package/dist/src/attribute.d.ts +74 -33
- package/dist/src/attribute.js +433 -0
- package/dist/src/attributes.d.ts +61 -55
- package/dist/src/attributes.js +371 -0
- package/dist/src/converter.d.ts +45 -71
- package/dist/src/converter.js +135 -0
- package/dist/src/converterFlags.d.ts +64 -39
- package/dist/src/converterFlags.js +235 -0
- package/dist/src/converterRule.d.ts +49 -27
- package/dist/src/converterRule.js +255 -0
- package/dist/src/extLink.d.ts +41 -38
- package/dist/src/extLink.js +154 -0
- package/dist/src/gallery.d.ts +59 -18
- package/dist/src/gallery.js +132 -0
- package/dist/src/heading.d.ts +60 -22
- package/dist/src/heading.js +135 -0
- package/dist/src/hidden.d.ts +20 -0
- package/dist/src/hidden.js +24 -0
- package/dist/src/html.d.ts +83 -29
- package/dist/src/html.js +242 -0
- package/dist/src/imageParameter.d.ts +59 -40
- package/dist/src/imageParameter.js +251 -0
- package/dist/src/imagemap.d.ts +65 -21
- package/dist/src/imagemap.js +169 -0
- package/dist/src/imagemapLink.d.ts +46 -14
- package/dist/src/imagemapLink.js +38 -0
- package/dist/src/index.d.ts +71 -105
- package/dist/src/index.js +826 -0
- package/dist/src/link/base.d.ts +71 -0
- package/dist/src/link/base.js +225 -0
- package/dist/src/link/category.d.ts +10 -11
- package/dist/src/link/category.js +26 -0
- package/dist/src/link/file.d.ts +61 -39
- package/dist/src/link/file.js +242 -0
- package/dist/src/link/galleryImage.d.ts +34 -12
- package/dist/src/link/galleryImage.js +98 -0
- package/dist/src/link/index.d.ts +25 -63
- package/dist/src/link/index.js +136 -0
- package/dist/src/magicLink.d.ts +22 -15
- package/dist/src/magicLink.js +126 -0
- package/dist/src/nested.d.ts +47 -0
- package/dist/src/nested.js +84 -0
- package/dist/src/nowiki/base.d.ts +39 -0
- package/dist/src/nowiki/base.js +29 -0
- package/dist/src/nowiki/comment.d.ts +31 -20
- package/dist/src/nowiki/comment.js +61 -0
- package/dist/src/nowiki/dd.d.ts +17 -11
- package/dist/src/nowiki/dd.js +50 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +28 -13
- package/dist/src/nowiki/doubleUnderscore.js +45 -0
- package/dist/src/nowiki/hr.d.ts +28 -10
- package/dist/src/nowiki/hr.js +33 -0
- package/dist/src/nowiki/index.d.ts +17 -23
- package/dist/src/nowiki/index.js +21 -0
- package/dist/src/nowiki/list.d.ts +15 -7
- package/dist/src/nowiki/list.js +11 -0
- package/dist/src/nowiki/noinclude.d.ts +20 -7
- package/dist/src/nowiki/noinclude.js +22 -0
- package/dist/src/nowiki/quote.d.ts +25 -10
- package/dist/src/nowiki/quote.js +55 -0
- package/dist/src/onlyinclude.d.ts +28 -12
- package/dist/src/onlyinclude.js +64 -0
- package/dist/src/paramTag/index.d.ts +40 -17
- package/dist/src/paramTag/index.js +76 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -7
- package/dist/src/paramTag/inputbox.js +19 -0
- package/dist/src/parameter.d.ts +62 -41
- package/dist/src/parameter.js +201 -0
- package/dist/src/pre.d.ts +32 -0
- package/dist/src/pre.js +39 -0
- package/dist/src/syntax.d.ts +17 -14
- package/dist/src/syntax.js +65 -0
- package/dist/src/table/base.d.ts +55 -0
- package/dist/src/table/base.js +77 -0
- package/dist/src/table/index.d.ts +123 -156
- package/dist/src/table/index.js +811 -0
- package/dist/src/table/td.d.ts +90 -67
- package/dist/src/table/td.js +276 -0
- package/dist/src/table/tr.d.ts +30 -85
- package/dist/src/table/tr.js +48 -0
- package/dist/src/table/trBase.d.ts +72 -0
- package/dist/src/table/trBase.js +153 -0
- package/dist/src/tagPair/ext.d.ts +47 -11
- package/dist/src/tagPair/ext.js +127 -0
- package/dist/src/tagPair/include.d.ts +32 -13
- package/dist/src/tagPair/include.js +40 -0
- package/dist/src/tagPair/index.d.ts +44 -29
- package/dist/src/tagPair/index.js +111 -0
- package/dist/src/transclude.d.ts +88 -85
- package/dist/src/transclude.js +739 -0
- package/dist/util/base.js +26 -0
- package/dist/util/debug.js +52 -0
- package/dist/util/diff.js +69 -0
- package/dist/util/lint.js +38 -0
- package/dist/util/string.js +103 -0
- package/errors/README +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +21 -24
- package/printed/README +1 -0
- package/dist/mixin/attributeParent.d.ts +0 -9
- package/dist/mixin/fixedToken.d.ts +0 -8
- package/dist/mixin/hidden.d.ts +0 -8
- package/dist/mixin/singleLine.d.ts +0 -8
- package/dist/mixin/sol.d.ts +0 -8
- package/dist/parser/brackets.d.ts +0 -12
- package/dist/parser/commentAndExt.d.ts +0 -8
- package/dist/parser/converter.d.ts +0 -7
- package/dist/parser/externalLinks.d.ts +0 -7
- package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
- package/dist/parser/html.d.ts +0 -7
- package/dist/parser/links.d.ts +0 -7
- package/dist/parser/list.d.ts +0 -7
- package/dist/parser/magicLinks.d.ts +0 -7
- package/dist/parser/quotes.d.ts +0 -7
- package/dist/parser/selector.d.ts +0 -12
- package/dist/parser/table.d.ts +0 -11
- package/dist/src/atom/hidden.d.ts +0 -5
- package/dist/src/atom/index.d.ts +0 -15
- package/dist/src/charinsert.d.ts +0 -32
- package/dist/src/hasNowiki/index.d.ts +0 -14
- package/dist/src/hasNowiki/pre.d.ts +0 -13
- package/dist/src/nested/choose.d.ts +0 -13
- package/dist/src/nested/combobox.d.ts +0 -13
- package/dist/src/nested/index.d.ts +0 -18
- package/dist/src/nested/references.d.ts +0 -13
- package/dist/tool/index.d.ts +0 -420
- package/dist/util/base.d.ts +0 -10
- package/dist/util/debug.d.ts +0 -20
- package/dist/util/diff.d.ts +0 -8
- package/dist/util/lint.d.ts +0 -28
- package/dist/util/string.d.ts +0 -55
- package/index.js +0 -333
- package/lib/element.js +0 -618
- package/lib/node.js +0 -730
- package/lib/ranges.js +0 -130
- package/lib/text.js +0 -265
- package/lib/title.js +0 -83
- package/mixin/attributeParent.js +0 -117
- package/mixin/fixedToken.js +0 -40
- package/mixin/hidden.js +0 -21
- package/mixin/singleLine.js +0 -31
- package/mixin/sol.js +0 -54
- package/parser/brackets.js +0 -128
- package/parser/commentAndExt.js +0 -62
- package/parser/converter.js +0 -46
- package/parser/externalLinks.js +0 -33
- package/parser/hrAndDoubleUnderscore.js +0 -49
- package/parser/html.js +0 -42
- package/parser/links.js +0 -94
- package/parser/list.js +0 -59
- package/parser/magicLinks.js +0 -41
- package/parser/quotes.js +0 -64
- package/parser/selector.js +0 -180
- package/parser/table.js +0 -114
- package/src/arg.js +0 -207
- package/src/atom/hidden.js +0 -13
- package/src/atom/index.js +0 -43
- package/src/attribute.js +0 -472
- package/src/attributes.js +0 -453
- package/src/charinsert.js +0 -97
- package/src/converter.js +0 -176
- package/src/converterFlags.js +0 -284
- package/src/converterRule.js +0 -256
- package/src/extLink.js +0 -180
- package/src/gallery.js +0 -149
- package/src/hasNowiki/index.js +0 -44
- package/src/hasNowiki/pre.js +0 -40
- package/src/heading.js +0 -134
- package/src/html.js +0 -254
- package/src/imageParameter.js +0 -303
- package/src/imagemap.js +0 -199
- package/src/imagemapLink.js +0 -41
- package/src/index.js +0 -938
- package/src/link/category.js +0 -44
- package/src/link/file.js +0 -287
- package/src/link/galleryImage.js +0 -120
- package/src/link/index.js +0 -388
- package/src/magicLink.js +0 -151
- package/src/nested/choose.js +0 -24
- package/src/nested/combobox.js +0 -23
- package/src/nested/index.js +0 -96
- package/src/nested/references.js +0 -23
- package/src/nowiki/comment.js +0 -71
- package/src/nowiki/dd.js +0 -59
- package/src/nowiki/doubleUnderscore.js +0 -56
- package/src/nowiki/hr.js +0 -41
- package/src/nowiki/index.js +0 -56
- package/src/nowiki/list.js +0 -16
- package/src/nowiki/noinclude.js +0 -28
- package/src/nowiki/quote.js +0 -69
- package/src/onlyinclude.js +0 -64
- package/src/paramTag/index.js +0 -89
- package/src/paramTag/inputbox.js +0 -35
- package/src/parameter.js +0 -239
- package/src/syntax.js +0 -91
- package/src/table/index.js +0 -985
- package/src/table/td.js +0 -343
- package/src/table/tr.js +0 -319
- package/src/tagPair/ext.js +0 -146
- package/src/tagPair/include.js +0 -50
- package/src/tagPair/index.js +0 -131
- package/src/transclude.js +0 -843
- package/tool/index.js +0 -1209
- package/typings/api.d.ts +0 -9
- package/typings/array.d.ts +0 -29
- package/typings/event.d.ts +0 -22
- package/typings/index.d.ts +0 -118
- package/typings/node.d.ts +0 -35
- package/typings/parser.d.ts +0 -12
- package/typings/table.d.ts +0 -10
- package/typings/token.d.ts +0 -31
- package/typings/tool.d.ts +0 -6
- package/util/base.js +0 -17
- package/util/debug.js +0 -73
- package/util/diff.js +0 -76
- package/util/lint.js +0 -57
- package/util/string.js +0 -126
package/typings/api.d.ts
DELETED
package/typings/array.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface Array<T> {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
6
|
-
* otherwise.
|
|
7
|
-
* @param predicate find calls predicate once for each element of the array, in descending
|
|
8
|
-
* order, until it finds one where predicate returns true. If such an element is found, findLast
|
|
9
|
-
* immediately returns that element value. Otherwise, findLast returns undefined.
|
|
10
|
-
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
11
|
-
* predicate. If it is not provided, undefined is used instead.
|
|
12
|
-
*/
|
|
13
|
-
findLast<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: unknown): S | undefined;
|
|
14
|
-
findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: unknown): T | undefined;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns the index of the last element in the array where predicate is true, and -1
|
|
18
|
-
* otherwise.
|
|
19
|
-
* @param predicate find calls predicate once for each element of the array, in descending
|
|
20
|
-
* order, until it finds one where predicate returns true. If such an element is found,
|
|
21
|
-
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
|
|
22
|
-
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
23
|
-
* predicate. If it is not provided, undefined is used instead.
|
|
24
|
-
*/
|
|
25
|
-
findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: unknown): number;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export {};
|
package/typings/event.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Token = require('../src');
|
|
2
|
-
import AstText = require('../lib/text');
|
|
3
|
-
|
|
4
|
-
export interface AstEvent {
|
|
5
|
-
readonly type: string;
|
|
6
|
-
readonly target: Token & AstText;
|
|
7
|
-
currentTarget: Token;
|
|
8
|
-
prevTarget: Token;
|
|
9
|
-
bubbles: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface AstEventData {
|
|
12
|
-
position: number;
|
|
13
|
-
removed: AstText|Token;
|
|
14
|
-
inserted: AstText|Token;
|
|
15
|
-
oldToken: Token;
|
|
16
|
-
newToken: Token;
|
|
17
|
-
oldText: string;
|
|
18
|
-
newText: string;
|
|
19
|
-
oldKey: string;
|
|
20
|
-
newKey: string;
|
|
21
|
-
}
|
|
22
|
-
export type AstListener = (e: AstEvent, data: AstEventData) => unknown;
|
package/typings/index.d.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import Token = require('../src');
|
|
2
|
-
import $ = require('../tool');
|
|
3
|
-
import Title = require('../lib/title');
|
|
4
|
-
import {ParserConfig} from './token';
|
|
5
|
-
|
|
6
|
-
declare interface Parser {
|
|
7
|
-
config: string|ParserConfig;
|
|
8
|
-
i18n: string|Record<string, string>;
|
|
9
|
-
|
|
10
|
-
readonly MAX_STAGE: number;
|
|
11
|
-
|
|
12
|
-
warning: boolean;
|
|
13
|
-
debugging: boolean;
|
|
14
|
-
running: boolean;
|
|
15
|
-
|
|
16
|
-
/** 只储存导出各个Class的文件路径 */
|
|
17
|
-
classes: Record<string, string>;
|
|
18
|
-
mixins: Record<string, string>;
|
|
19
|
-
parsers: Record<string, string>;
|
|
20
|
-
tool: {$: string};
|
|
21
|
-
|
|
22
|
-
readonly aliases: string[][];
|
|
23
|
-
readonly typeAliases: Record<string, string[]>;
|
|
24
|
-
|
|
25
|
-
readonly promises: Promise<void>[];
|
|
26
|
-
|
|
27
|
-
/** 获取设置 */
|
|
28
|
-
getConfig(): ParserConfig;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 生成I18N消息
|
|
32
|
-
* @param msg 消息名
|
|
33
|
-
* @param arg 额外参数
|
|
34
|
-
*/
|
|
35
|
-
msg(msg: string, arg: string): string;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 规范化页面标题
|
|
39
|
-
* @param title 标题(含或不含命名空间前缀)
|
|
40
|
-
* @param defaultNs 命名空间
|
|
41
|
-
* @param include 是否嵌入
|
|
42
|
-
* @param halfParsed 是否是半解析状态
|
|
43
|
-
* @param decode 是否需要解码
|
|
44
|
-
* @param selfLink 是否允许selfLink
|
|
45
|
-
*/
|
|
46
|
-
normalizeTitle(
|
|
47
|
-
title: string,
|
|
48
|
-
defaultNs?: number,
|
|
49
|
-
include?: boolean,
|
|
50
|
-
config?: ParserConfig,
|
|
51
|
-
halfParsed?: boolean,
|
|
52
|
-
decode?: boolean,
|
|
53
|
-
selfLink?: boolean,
|
|
54
|
-
): Title;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 解析wikitext
|
|
58
|
-
* @param wikitext wikitext
|
|
59
|
-
* @param include 是否嵌入
|
|
60
|
-
* @param maxStage 最大解析层级
|
|
61
|
-
*/
|
|
62
|
-
parse(wikitext: string, include?: boolean, maxStage?: number, config?: ParserConfig): Token;
|
|
63
|
-
|
|
64
|
-
run<T>(callback: () => T): T;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 默认输出到console.warn
|
|
68
|
-
* @param msg 消息
|
|
69
|
-
* @param args 更多信息
|
|
70
|
-
*/
|
|
71
|
-
warn(msg: string, ...args: unknown[]): void;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 默认不输出到console.debug
|
|
75
|
-
* @param msg 消息
|
|
76
|
-
* @param args 更多信息
|
|
77
|
-
*/
|
|
78
|
-
debug(msg: string, ...args: unknown[]): void;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 总是输出到console.error
|
|
82
|
-
* @param msg 消息
|
|
83
|
-
* @param args 更多信息
|
|
84
|
-
*/
|
|
85
|
-
error(msg: string, ...args: unknown[]): void;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 总是输出到console.info
|
|
89
|
-
* @param msg 消息
|
|
90
|
-
* @param args 更多信息
|
|
91
|
-
*/
|
|
92
|
-
info(msg: string, ...args: unknown[]): void;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 打印函数定义
|
|
96
|
-
* @param f 待打印的函数
|
|
97
|
-
*/
|
|
98
|
-
log(f: (...args: unknown[]) => unknown): void;
|
|
99
|
-
|
|
100
|
-
/** 清除各模块的缓存 */
|
|
101
|
-
clearCache(): void;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 是否是跨维基链接
|
|
105
|
-
* @param title 链接标题
|
|
106
|
-
*/
|
|
107
|
-
isInterwiki(title: string, config?: ParserConfig): RegExpMatchArray;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 再次解析上次出错的wikitext
|
|
111
|
-
* @param date 错误日期
|
|
112
|
-
*/
|
|
113
|
-
reparse(date: string): Token;
|
|
114
|
-
|
|
115
|
-
getTool(): typeof $;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export = Parser;
|
package/typings/node.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import Ranges = require('../lib/ranges');
|
|
2
|
-
import Token = require('../src');
|
|
3
|
-
import AstText = require('../lib/text');
|
|
4
|
-
import ParameterToken = require('../src/parameter');
|
|
5
|
-
import {ParserConfig, accum} from './token';
|
|
6
|
-
|
|
7
|
-
type buildFromStr = <S extends string>(str: string, type: S) => S extends 'string'|'text' ? string : (AstText|Token)[];
|
|
8
|
-
|
|
9
|
-
export type TokenAttribute<T> =
|
|
10
|
-
T extends 'stage' ? number :
|
|
11
|
-
T extends 'config' ? ParserConfig :
|
|
12
|
-
T extends 'accum' ? accum :
|
|
13
|
-
T extends 'parentNode' ? Token|undefined :
|
|
14
|
-
T extends 'childNodes' ? (AstText|Token)[] :
|
|
15
|
-
T extends 'parseOnce' ? (n: number, include: boolean) => Token :
|
|
16
|
-
T extends 'buildFromStr' ? buildFromStr :
|
|
17
|
-
T extends 'build' ? () => void :
|
|
18
|
-
T extends 'bracket'|'include' ? boolean :
|
|
19
|
-
T extends 'pattern' ? RegExp :
|
|
20
|
-
T extends 'tags'|'flags'|'quotes' ? string[] :
|
|
21
|
-
T extends 'optional'|'keys' ? Set<string> :
|
|
22
|
-
T extends 'acceptable' ? Record<string, Ranges> :
|
|
23
|
-
T extends 'args' ? Record<string, Set<ParameterToken>> :
|
|
24
|
-
T extends 'protectedChildren' ? Ranges :
|
|
25
|
-
T extends 'verifyChild' ? (i: number, addition: number) => void :
|
|
26
|
-
T extends 'matchesAttr' ? (key: string, equal: string, val: string, i: string) => boolean :
|
|
27
|
-
T extends 'protectChildren' ? (...args: (string|number|Range)[]) => void :
|
|
28
|
-
string;
|
|
29
|
-
|
|
30
|
-
export interface printOpt {
|
|
31
|
-
pre?: string;
|
|
32
|
-
post?: string;
|
|
33
|
-
sep?: string;
|
|
34
|
-
class?: string;
|
|
35
|
-
}
|
package/typings/parser.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface BracketExecArray extends RegExpExecArray {
|
|
2
|
-
parts: string[][];
|
|
3
|
-
findEqual: boolean;
|
|
4
|
-
pos: number;
|
|
5
|
-
}
|
|
6
|
-
export interface SelectorArray extends Array<string|RegExpExecArray> {
|
|
7
|
-
relation: string|undefined;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type pseudo = 'root'|'is'|'not'|'nth-child'|'nth-of-type'|'nth-last-child'|'nth-last-of-type'
|
|
11
|
-
|'first-child'|'first-of-type'|'last-child'|'last-of-type'|'only-child'|'only-of-type'|'empty'
|
|
12
|
-
|'contains'|'has'|'header'|'parent'|'hidden'|'visible';
|
package/typings/table.d.ts
DELETED
package/typings/token.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Token = require('../src');
|
|
2
|
-
import Ranges = require('../lib/ranges');
|
|
3
|
-
|
|
4
|
-
export interface ParserConfig {
|
|
5
|
-
ext: string[];
|
|
6
|
-
html: string[][];
|
|
7
|
-
namespaces: Record<string, string>;
|
|
8
|
-
nsid: Record<string, number>;
|
|
9
|
-
parserFunction: [Record<string, string>, string[], string[], string[]];
|
|
10
|
-
doubleUnderscore: string[][];
|
|
11
|
-
protocol: string;
|
|
12
|
-
img: Record<string, string>;
|
|
13
|
-
variants: string[];
|
|
14
|
-
interwiki: string[];
|
|
15
|
-
excludes: string[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type accum = Token[];
|
|
19
|
-
export type acceptable = Record<string, number|string|Ranges|(number|string)[]>;
|
|
20
|
-
|
|
21
|
-
export interface LintError {
|
|
22
|
-
message: string;
|
|
23
|
-
severity: 'error'|'warning';
|
|
24
|
-
startIndex: number;
|
|
25
|
-
endIndex: number;
|
|
26
|
-
startLine: number;
|
|
27
|
-
startCol: number;
|
|
28
|
-
endLine: number;
|
|
29
|
-
endCol: number;
|
|
30
|
-
excerpt: string;
|
|
31
|
-
}
|
package/typings/tool.d.ts
DELETED
package/util/base.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 是否是普通对象
|
|
5
|
-
* @param {*} obj 对象
|
|
6
|
-
*/
|
|
7
|
-
const isPlainObject = obj => Boolean(obj) && Object.getPrototypeOf(obj).constructor === Object;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 延时
|
|
11
|
-
* @param {number} t 秒数
|
|
12
|
-
*/
|
|
13
|
-
const sleep = t => new Promise(resolve => {
|
|
14
|
-
setTimeout(resolve, t * 1000);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
module.exports = {isPlainObject, sleep};
|
package/util/debug.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 定制TypeError消息
|
|
5
|
-
* @param {Function} constructor 类
|
|
6
|
-
* @param {string} method
|
|
7
|
-
* @param {...string} args 可接受的参数类型
|
|
8
|
-
* @throws `TypeError`
|
|
9
|
-
*/
|
|
10
|
-
const typeError = ({name}, method, ...args) => {
|
|
11
|
-
throw new TypeError(`${name}.${method} 方法仅接受 ${args.join('、')} 作为输入参数!`);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 不是被构造器或原型方法调用
|
|
16
|
-
* @param {string} name 方法名称
|
|
17
|
-
*/
|
|
18
|
-
const externalUse = name => {
|
|
19
|
-
const Parser = require('..');
|
|
20
|
-
if (Parser.running) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
const regex = new RegExp(`^new \\w*Token$|^(?:Ast\\w*|\\w*Token)\\.(?!${name}$)`, 'u');
|
|
24
|
-
try {
|
|
25
|
-
throw new Error(); // eslint-disable-line unicorn/error-message
|
|
26
|
-
} catch (e) {
|
|
27
|
-
if (e instanceof Error) {
|
|
28
|
-
const mt = e.stack.match(/(?<=^\s+at )(?:new )?[\w.]+(?= \(\/)/gmu);
|
|
29
|
-
return !mt.slice(2).some(func => regex.test(func));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 撤销最近一次Mutation
|
|
37
|
-
* @param {import('../typings/event').AstEvent} e 事件
|
|
38
|
-
* @param {import('../typings/event').AstEventData} data 事件数据
|
|
39
|
-
* @throws `RangeError` 无法撤销的事件类型
|
|
40
|
-
*/
|
|
41
|
-
const undo = (e, data) => {
|
|
42
|
-
const {target, type} = e;
|
|
43
|
-
switch (type) {
|
|
44
|
-
case 'remove': {
|
|
45
|
-
const childNodes = [...target.childNodes];
|
|
46
|
-
childNodes.splice(data.position, 0, data.removed);
|
|
47
|
-
data.removed.setAttribute('parentNode', target);
|
|
48
|
-
target.setAttribute('childNodes', childNodes);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case 'insert': {
|
|
52
|
-
const childNodes = [...target.childNodes];
|
|
53
|
-
childNodes.splice(data.position, 1);
|
|
54
|
-
target.setAttribute('childNodes', childNodes);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
case 'replace': {
|
|
58
|
-
const {parentNode} = target,
|
|
59
|
-
childNodes = [...parentNode.childNodes];
|
|
60
|
-
childNodes.splice(data.position, 1, data.oldToken);
|
|
61
|
-
data.oldToken.setAttribute('parentNode', parentNode);
|
|
62
|
-
parentNode.setAttribute('childNodes', childNodes);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case 'text':
|
|
66
|
-
target.replaceData(data.oldText);
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
throw new RangeError(`无法撤销未知类型的事件:${type}`);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
module.exports = {typeError, externalUse, undo};
|
package/util/diff.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {spawn} = require('child_process'),
|
|
4
|
-
fs = require('fs/promises');
|
|
5
|
-
|
|
6
|
-
process.on('unhandledRejection', e => {
|
|
7
|
-
console.error(e);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 将shell命令转化为Promise对象
|
|
12
|
-
* @param {string} command shell指令
|
|
13
|
-
* @param {string[]} args shell输入参数
|
|
14
|
-
* @returns {Promise<?string>}
|
|
15
|
-
*/
|
|
16
|
-
const cmd = (command, args) => new Promise(resolve => {
|
|
17
|
-
let timer, shell;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 清除进程并返回
|
|
21
|
-
* @param {*} val 返回值
|
|
22
|
-
*/
|
|
23
|
-
const r = val => {
|
|
24
|
-
clearTimeout(timer);
|
|
25
|
-
shell.kill('SIGINT');
|
|
26
|
-
resolve(val);
|
|
27
|
-
};
|
|
28
|
-
try {
|
|
29
|
-
shell = spawn(command, args);
|
|
30
|
-
timer = setTimeout(() => {
|
|
31
|
-
shell.kill('SIGINT');
|
|
32
|
-
}, 60 * 1000);
|
|
33
|
-
let buf = '';
|
|
34
|
-
shell.stdout.on('data', data => {
|
|
35
|
-
buf += data.toString();
|
|
36
|
-
});
|
|
37
|
-
shell.stdout.on('end', () => {
|
|
38
|
-
r(buf);
|
|
39
|
-
});
|
|
40
|
-
shell.on('exit', () => {
|
|
41
|
-
r(shell.killed ? undefined : '');
|
|
42
|
-
});
|
|
43
|
-
shell.on('error', () => {
|
|
44
|
-
r(undefined);
|
|
45
|
-
});
|
|
46
|
-
} catch {
|
|
47
|
-
r(undefined);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 比较两个文件
|
|
53
|
-
* @param {string} oldStr 旧文本
|
|
54
|
-
* @param {string} newStr 新文本
|
|
55
|
-
* @param {string} uid 唯一标识
|
|
56
|
-
*/
|
|
57
|
-
const diff = async (oldStr, newStr, uid = '') => {
|
|
58
|
-
if (oldStr === newStr) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const oldFile = `diffOld${uid}`,
|
|
62
|
-
newFile = `diffNew${uid}`;
|
|
63
|
-
await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
|
|
64
|
-
const stdout = await cmd('git', [
|
|
65
|
-
'diff',
|
|
66
|
-
'--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
|
|
67
|
-
'-U0',
|
|
68
|
-
'--no-index',
|
|
69
|
-
oldFile,
|
|
70
|
-
newFile,
|
|
71
|
-
]);
|
|
72
|
-
await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
|
|
73
|
-
console.log(stdout?.split('\n')?.slice(4)?.join('\n'));
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
module.exports = diff;
|
package/util/lint.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../typings/token').LintError} LintError */
|
|
4
|
-
|
|
5
|
-
const Parser = require('..'),
|
|
6
|
-
Token = require('../src');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 生成对于子节点的LintError对象
|
|
10
|
-
* @param {Token} child 子节点
|
|
11
|
-
* @param {{top: number, left: number, start: number}} boundingRect 父节点的绝对定位
|
|
12
|
-
* @param {string} msg 错误信息
|
|
13
|
-
* @param {'error'|'warning'} severity 严重程度
|
|
14
|
-
* @returns {LintError}
|
|
15
|
-
*/
|
|
16
|
-
const generateForChild = (child, boundingRect, msg, severity = 'error') => {
|
|
17
|
-
const index = child.getRelativeIndex(),
|
|
18
|
-
{offsetHeight, offsetWidth, parentNode, length} = child,
|
|
19
|
-
{top: offsetTop, left: offsetLeft} = parentNode.posFromIndex(index),
|
|
20
|
-
{start} = boundingRect,
|
|
21
|
-
{top, left} = 'top' in boundingRect ? boundingRect : child.getRootNode().posFromIndex(start),
|
|
22
|
-
excerpt = String(child).slice(0, 50),
|
|
23
|
-
startIndex = start + index,
|
|
24
|
-
endIndex = startIndex + length,
|
|
25
|
-
startLine = top + offsetTop,
|
|
26
|
-
endLine = startLine + offsetHeight - 1,
|
|
27
|
-
startCol = offsetTop ? offsetLeft : left + offsetLeft,
|
|
28
|
-
endCol = offsetHeight > 1 ? offsetWidth : startCol + offsetWidth;
|
|
29
|
-
return {message: Parser.msg(msg), severity, startIndex, endIndex, startLine, endLine, startCol, endCol, excerpt};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 生成对于自己的LintError对象
|
|
34
|
-
* @param {Token} token 节点
|
|
35
|
-
* @param {{top: number, left: number, start: number}} boundingRect 绝对定位
|
|
36
|
-
* @param {string} msg 错误信息
|
|
37
|
-
* @param {'error'|'warning'} severity 严重程度
|
|
38
|
-
* @returns {LintError}
|
|
39
|
-
*/
|
|
40
|
-
const generateForSelf = (token, boundingRect, msg, severity = 'error') => {
|
|
41
|
-
const {start} = boundingRect,
|
|
42
|
-
{offsetHeight, offsetWidth, length} = token,
|
|
43
|
-
{top, left} = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start);
|
|
44
|
-
return {
|
|
45
|
-
message: Parser.msg(msg),
|
|
46
|
-
severity,
|
|
47
|
-
startIndex: start,
|
|
48
|
-
endIndex: start + length,
|
|
49
|
-
startLine: top,
|
|
50
|
-
endLine: top + offsetHeight - 1,
|
|
51
|
-
startCol: left,
|
|
52
|
-
endCol: offsetHeight > 1 ? offsetWidth : left + offsetWidth,
|
|
53
|
-
excerpt: String(token).slice(0, 50),
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
module.exports = {generateForChild, generateForSelf};
|
package/util/string.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])',
|
|
4
|
-
extUrlChar = '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* remove half-parsed comment-like tokens
|
|
8
|
-
* @param {string} str 原字符串
|
|
9
|
-
*/
|
|
10
|
-
const removeComment = str => str.replace(/\0\d+c\x7F/gu, '');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 以HTML格式打印
|
|
14
|
-
* @param {(AstText|AstElement)[]} childNodes 子节点
|
|
15
|
-
* @param {import('../typings/node').printOpt} opt 选项
|
|
16
|
-
*/
|
|
17
|
-
const print = (childNodes, opt = {}) => {
|
|
18
|
-
const AstText = require('../lib/text'),
|
|
19
|
-
AstElement = require('../lib/element');
|
|
20
|
-
const {pre = '', post = '', sep = ''} = opt,
|
|
21
|
-
entities = {'&': 'amp', '<': 'lt', '>': 'gt'};
|
|
22
|
-
return `${pre}${childNodes.map(
|
|
23
|
-
child => child instanceof AstElement
|
|
24
|
-
? child.print()
|
|
25
|
-
: String(child).replace(/[&<>]/gu, p => `&${entities[p]};`),
|
|
26
|
-
).join(sep)}${post}`;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* escape special chars for RegExp constructor
|
|
31
|
-
* @param {string} str RegExp source
|
|
32
|
-
*/
|
|
33
|
-
const escapeRegExp = str => str.replace(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* a more sophisticated string-explode function
|
|
37
|
-
* @param {string} start start syntax of a nested AST node
|
|
38
|
-
* @param {string} end end syntax of a nested AST node
|
|
39
|
-
* @param {string} separator syntax for explosion
|
|
40
|
-
* @param {string} str string to be exploded
|
|
41
|
-
*/
|
|
42
|
-
const explode = (start, end, separator, str) => {
|
|
43
|
-
if (str === undefined) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
const regex = new RegExp(`${[start, end, separator].map(escapeRegExp).join('|')}`, 'gu'),
|
|
47
|
-
/** @type {string[]} */ exploded = [];
|
|
48
|
-
let mt = regex.exec(str),
|
|
49
|
-
depth = 0,
|
|
50
|
-
lastIndex = 0;
|
|
51
|
-
while (mt) {
|
|
52
|
-
const {0: match, index} = mt;
|
|
53
|
-
if (match !== separator) {
|
|
54
|
-
depth += match === start ? 1 : -1;
|
|
55
|
-
} else if (depth === 0) {
|
|
56
|
-
exploded.push(str.slice(lastIndex, index));
|
|
57
|
-
({lastIndex} = regex);
|
|
58
|
-
}
|
|
59
|
-
mt = regex.exec(str);
|
|
60
|
-
}
|
|
61
|
-
exploded.push(str.slice(lastIndex));
|
|
62
|
-
return exploded;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* extract effective wikitext
|
|
67
|
-
* @param {(string|AstNode)[]} childNodes a Token's contents
|
|
68
|
-
* @param {string} separator delimiter between nodes
|
|
69
|
-
*/
|
|
70
|
-
const text = (childNodes, separator = '') => {
|
|
71
|
-
const AstNode = require('../lib/node');
|
|
72
|
-
return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* decode HTML entities
|
|
77
|
-
* @param {string} str 原字符串
|
|
78
|
-
*/
|
|
79
|
-
const decodeHtml = str => str?.replace(
|
|
80
|
-
/&#(\d+|x[\da-f]+);/giu,
|
|
81
|
-
/** @param {string} code */ (_, code) => String.fromCodePoint(`${code[0].toLowerCase() === 'x' ? '0' : ''}${code}`),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* optionally convert to lower cases
|
|
86
|
-
* @param {string} val 属性值
|
|
87
|
-
* @param {string|undefined} i 是否对大小写不敏感
|
|
88
|
-
*/
|
|
89
|
-
const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* escape newlines
|
|
93
|
-
* @param {string} str 原字符串
|
|
94
|
-
*/
|
|
95
|
-
const noWrap = str => str.replaceAll('\n', '\\n');
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* convert newline in text nodes to single whitespace
|
|
99
|
-
* @param {Token & {childNodes: AstText[]}} token 父节点
|
|
100
|
-
*/
|
|
101
|
-
const normalizeSpace = token => {
|
|
102
|
-
if (token === undefined) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const Token = require('../src'),
|
|
106
|
-
AstText = require('../lib/text');
|
|
107
|
-
for (const child of token.childNodes) {
|
|
108
|
-
if (child.type === 'text') {
|
|
109
|
-
child.replaceData(child.data.replaceAll('\n', ' '));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
module.exports = {
|
|
115
|
-
extUrlCharFirst,
|
|
116
|
-
extUrlChar,
|
|
117
|
-
removeComment,
|
|
118
|
-
print,
|
|
119
|
-
escapeRegExp,
|
|
120
|
-
explode,
|
|
121
|
-
text,
|
|
122
|
-
decodeHtml,
|
|
123
|
-
toCase,
|
|
124
|
-
noWrap,
|
|
125
|
-
normalizeSpace,
|
|
126
|
-
};
|