wikiparser-node 1.3.4 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/addon/table.js +13 -19
- package/dist/index.d.ts +1 -0
- package/dist/lib/element.d.ts +0 -1
- package/dist/lib/element.js +4 -13
- package/dist/lib/node.js +4 -0
- package/dist/lib/ranges.js +2 -1
- package/dist/lib/text.js +4 -5
- package/dist/mixin/attributesParent.js +2 -7
- package/dist/mixin/fixed.js +3 -10
- package/dist/mixin/syntax.js +1 -3
- package/dist/parser/braces.js +9 -2
- package/dist/parser/commentAndExt.js +18 -10
- package/dist/parser/list.js +11 -4
- package/dist/parser/selector.js +19 -20
- package/dist/parser/table.js +28 -20
- package/dist/src/arg.d.ts +0 -2
- package/dist/src/arg.js +2 -4
- package/dist/src/attribute.d.ts +1 -0
- package/dist/src/attribute.js +3 -3
- package/dist/src/attributes.d.ts +3 -1
- package/dist/src/attributes.js +21 -18
- package/dist/src/converter.d.ts +1 -0
- package/dist/src/converterRule.d.ts +1 -5
- package/dist/src/converterRule.js +3 -7
- package/dist/src/extLink.d.ts +1 -0
- package/dist/src/gallery.d.ts +0 -1
- package/dist/src/gallery.js +1 -2
- package/dist/src/heading.d.ts +3 -1
- package/dist/src/heading.js +2 -2
- package/dist/src/hidden.d.ts +1 -0
- package/dist/src/html.d.ts +3 -0
- package/dist/src/html.js +0 -1
- package/dist/src/imageParameter.d.ts +0 -1
- package/dist/src/imageParameter.js +0 -2
- package/dist/src/imagemap.d.ts +0 -1
- package/dist/src/imagemap.js +2 -3
- package/dist/src/imagemapLink.d.ts +2 -0
- package/dist/src/index.d.ts +1 -8
- package/dist/src/index.js +17 -17
- package/dist/src/link/file.js +2 -1
- package/dist/src/link/galleryImage.d.ts +1 -0
- package/dist/src/link/index.js +1 -1
- package/dist/src/magicLink.d.ts +1 -2
- package/dist/src/magicLink.js +2 -3
- package/dist/src/nested.d.ts +0 -1
- package/dist/src/nested.js +1 -2
- package/dist/src/nowiki/base.d.ts +1 -0
- package/dist/src/nowiki/comment.d.ts +1 -0
- package/dist/src/nowiki/dd.js +1 -1
- package/dist/src/nowiki/doubleUnderscore.d.ts +2 -0
- package/dist/src/nowiki/hr.d.ts +2 -0
- package/dist/src/nowiki/list.d.ts +1 -0
- package/dist/src/nowiki/listBase.d.ts +1 -0
- package/dist/src/nowiki/noinclude.d.ts +1 -1
- package/dist/src/nowiki/noinclude.js +1 -2
- package/dist/src/nowiki/quote.d.ts +1 -0
- package/dist/src/parameter.d.ts +1 -0
- package/dist/src/parameter.js +1 -1
- package/dist/src/syntax.d.ts +2 -0
- package/dist/src/table/base.d.ts +2 -0
- package/dist/src/table/index.d.ts +0 -1
- package/dist/src/table/index.js +0 -1
- package/dist/src/table/td.d.ts +3 -0
- package/dist/src/table/td.js +9 -10
- package/dist/src/table/trBase.d.ts +0 -1
- package/dist/src/table/trBase.js +2 -10
- package/dist/src/tagPair/ext.d.ts +2 -0
- package/dist/src/tagPair/include.d.ts +1 -0
- package/dist/src/tagPair/index.d.ts +1 -0
- package/dist/src/transclude.js +9 -11
- package/dist/util/debug.js +39 -20
- package/dist/util/lint.js +12 -28
- package/dist/util/string.js +12 -22
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ declare const ListBaseToken_base: (abstract new (...args: any[]) => {
|
|
|
11
11
|
lint(start?: number | undefined): import("../..").LintError[];
|
|
12
12
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
13
13
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
14
|
+
constructorError(msg: string): never;
|
|
14
15
|
}) & typeof NowikiBaseToken;
|
|
15
16
|
/** `;:*#` */
|
|
16
17
|
export declare class ListBaseToken extends ListBaseToken_base {
|
|
@@ -10,6 +10,7 @@ declare const NoincludeToken_base: ((abstract new (...args: any[]) => {
|
|
|
10
10
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
11
11
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
12
12
|
replaceChildren(...elements: (string | import("../..").AstNodes)[]): void;
|
|
13
|
+
constructorError(msg: string): never;
|
|
13
14
|
}) & {
|
|
14
15
|
readonly hidden: true;
|
|
15
16
|
}) & typeof NowikiBaseToken;
|
|
@@ -19,7 +20,6 @@ export declare class NoincludeToken extends NoincludeToken_base {
|
|
|
19
20
|
/**
|
|
20
21
|
* @override
|
|
21
22
|
* @param str 新文本
|
|
22
|
-
* @throws `Error` 不可更改
|
|
23
23
|
*/
|
|
24
24
|
setText(str: string): string;
|
|
25
25
|
}
|
|
@@ -12,11 +12,10 @@ class NoincludeToken extends (0, hidden_1.hidden)(base_1.NowikiBaseToken) {
|
|
|
12
12
|
/**
|
|
13
13
|
* @override
|
|
14
14
|
* @param str 新文本
|
|
15
|
-
* @throws `Error` 不可更改
|
|
16
15
|
*/
|
|
17
16
|
setText(str) {
|
|
18
17
|
if (/^<\/?(?:(?:no|only)include|includeonly)(?:\s[^>]*)?\/?>$/iu.test(this.innerText)) {
|
|
19
|
-
|
|
18
|
+
this.constructorError('不可更改文字内容');
|
|
20
19
|
}
|
|
21
20
|
return super.setText(str);
|
|
22
21
|
}
|
|
@@ -13,6 +13,7 @@ declare const QuoteToken_base: (abstract new (...args: any[]) => {
|
|
|
13
13
|
lint(start?: number | undefined): Parser.LintError[];
|
|
14
14
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
15
15
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
16
|
+
constructorError(msg: string): never;
|
|
16
17
|
}) & typeof NowikiBaseToken;
|
|
17
18
|
/** `''`和`'''` */
|
|
18
19
|
export declare class QuoteToken extends QuoteToken_base {
|
package/dist/src/parameter.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare const ParameterToken_base: ((abstract new (...args: any[]) => {
|
|
|
15
15
|
setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
|
|
16
16
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
17
17
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
18
|
+
constructorError(msg: string): never;
|
|
18
19
|
}) & {
|
|
19
20
|
readonly fixed: true;
|
|
20
21
|
}) & typeof Parser.Token;
|
package/dist/src/parameter.js
CHANGED
|
@@ -173,7 +173,7 @@ class ParameterToken extends (0, fixed_1.fixed)(index_1.Token) {
|
|
|
173
173
|
const { parentNode, anon } = this;
|
|
174
174
|
// 必须检测是否是TranscludeToken
|
|
175
175
|
if (parentNode?.isTemplate() === false) {
|
|
176
|
-
throw new Error(
|
|
176
|
+
throw new Error('rename 方法仅用于模板参数!');
|
|
177
177
|
}
|
|
178
178
|
else if (anon) {
|
|
179
179
|
parentNode?.anonToNamed();
|
package/dist/src/syntax.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ declare const SyntaxToken_base: (abstract new (...args: any[]) => {
|
|
|
14
14
|
lint(start?: number | undefined): Parser.LintError[];
|
|
15
15
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
16
16
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
17
|
+
/** @override */
|
|
18
|
+
constructorError(msg: string): never;
|
|
17
19
|
}) & typeof Parser.Token;
|
|
18
20
|
/** 满足特定语法格式的plain Token */
|
|
19
21
|
export declare class SyntaxToken extends SyntaxToken_base {
|
package/dist/src/table/base.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare const TableBaseToken_base: (abstract new (...args: any[]) => {
|
|
|
14
14
|
getAttrNames(): Set<string>;
|
|
15
15
|
getAttrs(): Record<string, string | true>;
|
|
16
16
|
setAttr(key: string, value: string | boolean): void;
|
|
17
|
+
setAttr(prop: Record<string, string | boolean>): void;
|
|
17
18
|
removeAttr(key: string): void;
|
|
18
19
|
toggleAttr(key: string, force?: boolean | undefined): void;
|
|
19
20
|
readonly length: number;
|
|
@@ -26,6 +27,7 @@ declare const TableBaseToken_base: (abstract new (...args: any[]) => {
|
|
|
26
27
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
27
28
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
28
29
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
30
|
+
constructorError(msg: string): never;
|
|
29
31
|
}) & typeof Parser.Token;
|
|
30
32
|
/**
|
|
31
33
|
* 表格行,含开头的换行,不含结尾的换行
|
|
@@ -57,7 +57,6 @@ export declare class TableToken extends TrBaseToken {
|
|
|
57
57
|
* @throws `RangeError` 不存在该行
|
|
58
58
|
*/
|
|
59
59
|
getNthRow(n: number, force?: boolean, insert?: false): TrToken | this | undefined;
|
|
60
|
-
/** @ignore */
|
|
61
60
|
getNthRow(n: number, force: boolean, insert: true): TrToken | this | SyntaxToken | undefined;
|
|
62
61
|
/** 获取所有行 */
|
|
63
62
|
getAllRows(): readonly (TrToken | this)[];
|
package/dist/src/table/index.js
CHANGED
|
@@ -87,7 +87,6 @@ class TableToken extends trBase_1.TrBaseToken {
|
|
|
87
87
|
getNextRow() {
|
|
88
88
|
return this.getNthRow(super.getRowCount() ? 1 : 0, false, false);
|
|
89
89
|
}
|
|
90
|
-
/** @ignore */
|
|
91
90
|
getNthRow(n, force = false, insert = false) {
|
|
92
91
|
const nRows = this.getRowCount(), isRow = super.getRowCount();
|
|
93
92
|
n += n < 0 ? nRows : 0;
|
package/dist/src/table/td.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare const TdToken_base: ((abstract new (...args: any[]) => {
|
|
|
24
24
|
setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
|
|
25
25
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
26
26
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
27
|
+
constructorError(msg: string): never;
|
|
27
28
|
}) & {
|
|
28
29
|
readonly fixed: true;
|
|
29
30
|
}) & typeof TableBaseToken;
|
|
@@ -87,8 +88,10 @@ export declare class TdToken extends TdToken_base {
|
|
|
87
88
|
* @override
|
|
88
89
|
* @param key 属性键
|
|
89
90
|
* @param value 属性值
|
|
91
|
+
* @param prop 属性对象
|
|
90
92
|
*/
|
|
91
93
|
setAttr<T extends string>(key: T, value: TdAttrSetter<T>): void;
|
|
94
|
+
setAttr(prop: Record<string, string | number | boolean>): void;
|
|
92
95
|
/** @override */
|
|
93
96
|
escape(): void;
|
|
94
97
|
}
|
package/dist/src/table/td.js
CHANGED
|
@@ -207,13 +207,14 @@ class TdToken extends (0, fixed_1.fixed)(base_1.TableBaseToken) {
|
|
|
207
207
|
}
|
|
208
208
|
return attr;
|
|
209
209
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
210
|
+
setAttr(keyOrProp, value) {
|
|
211
|
+
if (typeof keyOrProp !== 'string') {
|
|
212
|
+
for (const [key, val] of Object.entries(keyOrProp)) {
|
|
213
|
+
this.setAttr(key, val);
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const key = keyOrProp.toLowerCase().trim();
|
|
217
218
|
let v;
|
|
218
219
|
if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
|
|
219
220
|
v = value === 1 ? false : String(value);
|
|
@@ -251,9 +252,7 @@ const createTd = (inner, subtype = 'td', attr = {}, include = false, config = Pa
|
|
|
251
252
|
const innerToken = typeof inner === 'string' ? Parser.parse(inner, include, undefined, config) : inner, token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
|
|
252
253
|
token.setSyntax(subtype);
|
|
253
254
|
token.lastChild.safeReplaceWith(innerToken);
|
|
254
|
-
|
|
255
|
-
token.setAttr(k, v);
|
|
256
|
-
}
|
|
255
|
+
token.setAttr(attr);
|
|
257
256
|
return token;
|
|
258
257
|
};
|
|
259
258
|
exports.createTd = createTd;
|
|
@@ -41,7 +41,6 @@ export declare abstract class TrBaseToken extends TableBaseToken {
|
|
|
41
41
|
* @throws `RangeError` 不存在对应单元格
|
|
42
42
|
*/
|
|
43
43
|
getNthCol(n: number, insert?: false): TdToken | undefined;
|
|
44
|
-
/** @ignore */
|
|
45
44
|
getNthCol(n: number, insert: true): TdToken | TrToken | SyntaxToken | undefined;
|
|
46
45
|
/**
|
|
47
46
|
* 插入新的单元格
|
package/dist/src/table/trBase.js
CHANGED
|
@@ -15,11 +15,7 @@ class TrBaseToken extends base_1.TableBaseToken {
|
|
|
15
15
|
if (!inter) {
|
|
16
16
|
return errors;
|
|
17
17
|
}
|
|
18
|
-
const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u,
|
|
19
|
-
/** @ignore */
|
|
20
|
-
isArg = (token) => token.type === 'arg',
|
|
21
|
-
/** @ignore */
|
|
22
|
-
isTransclude = (token) => token.type === 'magic-word';
|
|
18
|
+
const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u, isArg = (0, debug_1.isToken)('arg'), isTransclude = (0, debug_1.isToken)('magic-word');
|
|
23
19
|
if (!first
|
|
24
20
|
|| tdPattern.test(String(first))
|
|
25
21
|
|| isArg(first) && tdPattern.test(first.default || '')) {
|
|
@@ -115,7 +111,6 @@ class TrBaseToken extends base_1.TableBaseToken {
|
|
|
115
111
|
}
|
|
116
112
|
return count;
|
|
117
113
|
}
|
|
118
|
-
/** @ignore */
|
|
119
114
|
getNthCol(n, insert = false) {
|
|
120
115
|
const nCols = this.getColCount();
|
|
121
116
|
n += n < 0 ? nCols : 0;
|
|
@@ -123,10 +118,7 @@ class TrBaseToken extends base_1.TableBaseToken {
|
|
|
123
118
|
throw new RangeError(`不存在第 ${n} 个单元格!`);
|
|
124
119
|
}
|
|
125
120
|
let last = 0;
|
|
126
|
-
|
|
127
|
-
const isTr = (token) => token.type === 'tr',
|
|
128
|
-
/** @ignore */
|
|
129
|
-
isSyntax = (token) => token.type === 'table-syntax';
|
|
121
|
+
const isTr = (0, debug_1.isToken)('tr'), isSyntax = (0, debug_1.isToken)('table-syntax');
|
|
130
122
|
for (const child of this.childNodes.slice(2)) {
|
|
131
123
|
if (child instanceof td_1.TdToken) {
|
|
132
124
|
if (child.isIndependent()) {
|
|
@@ -15,6 +15,7 @@ declare const ExtToken_base: (abstract new (...args: any[]) => {
|
|
|
15
15
|
getAttrNames(): Set<string>;
|
|
16
16
|
getAttrs(): Record<string, string | true>;
|
|
17
17
|
setAttr(key: string, value: string | boolean): void;
|
|
18
|
+
setAttr(prop: Record<string, string | boolean>): void;
|
|
18
19
|
removeAttr(key: string): void;
|
|
19
20
|
toggleAttr(key: string, force?: boolean | undefined): void;
|
|
20
21
|
readonly length: number;
|
|
@@ -27,6 +28,7 @@ declare const ExtToken_base: (abstract new (...args: any[]) => {
|
|
|
27
28
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
28
29
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
29
30
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
31
|
+
constructorError(msg: string): never;
|
|
30
32
|
}) & typeof TagPairToken;
|
|
31
33
|
/**
|
|
32
34
|
* 扩展标签
|
|
@@ -13,6 +13,7 @@ declare const IncludeToken_base: ((abstract new (...args: any[]) => {
|
|
|
13
13
|
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
14
14
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
15
15
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
16
|
+
constructorError(msg: string): never;
|
|
16
17
|
}) & {
|
|
17
18
|
readonly hidden: true;
|
|
18
19
|
}) & typeof TagPairToken;
|
|
@@ -14,6 +14,7 @@ declare const TagPairToken_base: ((abstract new (...args: any[]) => {
|
|
|
14
14
|
setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
|
|
15
15
|
addEventListener(events: string | string[], listener: AstListener): void;
|
|
16
16
|
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
17
|
+
constructorError(msg: string): never;
|
|
17
18
|
}) & {
|
|
18
19
|
readonly fixed: true;
|
|
19
20
|
}) & typeof Parser.Token;
|
package/dist/src/transclude.js
CHANGED
|
@@ -291,7 +291,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
291
291
|
}
|
|
292
292
|
/** 获取所有参数 */
|
|
293
293
|
getAllArgs() {
|
|
294
|
-
return this.childNodes.filter((
|
|
294
|
+
return this.childNodes.filter((0, debug_1.isToken)('parameter'));
|
|
295
295
|
}
|
|
296
296
|
/** 获取所有匿名参数 */
|
|
297
297
|
getAnonArgs() {
|
|
@@ -329,7 +329,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
329
329
|
if (this.isTemplate()) {
|
|
330
330
|
return [...this.#args].filter(([, { size }]) => size > 1).map(([key, args]) => [key, [...args]]);
|
|
331
331
|
}
|
|
332
|
-
throw new Error(
|
|
332
|
+
throw new Error('getDuplicatedArgs 方法仅供模板使用!');
|
|
333
333
|
}
|
|
334
334
|
/**
|
|
335
335
|
* 对特定魔术字获取可能的取值
|
|
@@ -499,7 +499,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
499
499
|
*/
|
|
500
500
|
setValue(key, value) {
|
|
501
501
|
if (!this.isTemplate()) {
|
|
502
|
-
throw new Error(
|
|
502
|
+
throw new Error('setValue 方法仅供模板使用!');
|
|
503
503
|
}
|
|
504
504
|
const arg = this.getArg(key);
|
|
505
505
|
if (arg) {
|
|
@@ -518,7 +518,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
518
518
|
*/
|
|
519
519
|
anonToNamed() {
|
|
520
520
|
if (!this.isTemplate()) {
|
|
521
|
-
throw new Error(
|
|
521
|
+
throw new Error('anonToNamed 方法仅供模板使用!');
|
|
522
522
|
}
|
|
523
523
|
for (const token of this.getAnonArgs()) {
|
|
524
524
|
token.firstChild.replaceChildren(token.name);
|
|
@@ -531,7 +531,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
531
531
|
*/
|
|
532
532
|
replaceTemplate(title) {
|
|
533
533
|
if (this.type === 'magic-word') {
|
|
534
|
-
throw new Error(
|
|
534
|
+
throw new Error('replaceTemplate 方法仅用于更换模板!');
|
|
535
535
|
}
|
|
536
536
|
const { childNodes } = Parser.parse(title, this.getAttribute('include'), 2, this.getAttribute('config'));
|
|
537
537
|
this.firstChild.replaceChildren(...childNodes);
|
|
@@ -543,7 +543,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
543
543
|
*/
|
|
544
544
|
replaceModule(title) {
|
|
545
545
|
if (this.type !== 'magic-word' || this.name !== 'invoke') {
|
|
546
|
-
throw new Error(
|
|
546
|
+
throw new Error('replaceModule 方法仅用于更换模块!');
|
|
547
547
|
}
|
|
548
548
|
const config = this.getAttribute('config');
|
|
549
549
|
if (this.length === 1) {
|
|
@@ -563,7 +563,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
563
563
|
*/
|
|
564
564
|
replaceFunction(func) {
|
|
565
565
|
if (this.type !== 'magic-word' || this.name !== 'invoke') {
|
|
566
|
-
throw new Error(
|
|
566
|
+
throw new Error('replaceModule 方法仅用于更换模块!');
|
|
567
567
|
}
|
|
568
568
|
else if (this.length < 2) {
|
|
569
569
|
throw new Error('尚未指定模块名称!');
|
|
@@ -586,7 +586,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
586
586
|
if (this.isTemplate()) {
|
|
587
587
|
return this.getAllArgs().length - this.getKeys().length;
|
|
588
588
|
}
|
|
589
|
-
throw new Error(
|
|
589
|
+
throw new Error('hasDuplicatedArgs 方法仅供模板使用!');
|
|
590
590
|
}
|
|
591
591
|
/**
|
|
592
592
|
* 修复重名参数:
|
|
@@ -678,9 +678,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
678
678
|
if (!/\n[^\S\n]*(?::+[^\S\n]*)?\{\|/u.test(this.text())) {
|
|
679
679
|
return this;
|
|
680
680
|
}
|
|
681
|
-
const stripped = String(this).slice(2, -2), include = this.getAttribute('include'), config = this.getAttribute('config'), parsed = Parser.parse(stripped, include, 4, config),
|
|
682
|
-
/** @ignore */
|
|
683
|
-
isTable = (token) => token.type === 'table';
|
|
681
|
+
const stripped = String(this).slice(2, -2), include = this.getAttribute('include'), config = this.getAttribute('config'), parsed = Parser.parse(stripped, include, 4, config), isTable = (0, debug_1.isToken)('table');
|
|
684
682
|
for (const table of parsed.childNodes) {
|
|
685
683
|
if (isTable(table)) {
|
|
686
684
|
table.escape();
|
package/dist/util/debug.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.undo = exports.Shadow = void 0;
|
|
3
|
+
exports.undo = exports.emptyArray = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
|
|
4
4
|
exports.Shadow = {
|
|
5
5
|
/* NOT FOR BROWSER */
|
|
6
6
|
running: false,
|
|
@@ -20,7 +20,39 @@ exports.Shadow = {
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* 是否是某一特定类型的节点
|
|
25
|
+
* @param type 节点类型
|
|
26
|
+
*/
|
|
27
|
+
const isToken = (type) => (node) => node.type === type;
|
|
28
|
+
exports.isToken = isToken;
|
|
29
|
+
/**
|
|
30
|
+
* 更新chldNodes
|
|
31
|
+
* @param parent 父节点
|
|
32
|
+
* @param position 子节点位置
|
|
33
|
+
* @param deleteCount 移除的子节点数量
|
|
34
|
+
* @param inserted 插入的子节点
|
|
35
|
+
*/
|
|
36
|
+
const setChildNodes = (parent, position, deleteCount, inserted = []) => {
|
|
37
|
+
const childNodes = [...parent.childNodes], removed = childNodes.splice(position, deleteCount, ...inserted);
|
|
38
|
+
parent.setAttribute('childNodes', childNodes);
|
|
39
|
+
for (const node of inserted) {
|
|
40
|
+
node.setAttribute('parentNode', parent);
|
|
41
|
+
}
|
|
42
|
+
for (const node of removed) {
|
|
43
|
+
node.setAttribute('parentNode', undefined);
|
|
44
|
+
}
|
|
45
|
+
return removed;
|
|
46
|
+
};
|
|
47
|
+
exports.setChildNodes = setChildNodes;
|
|
23
48
|
/* NOT FOR BROWSER */
|
|
49
|
+
/**
|
|
50
|
+
* 生成一个指定长度的空数组
|
|
51
|
+
* @param n 数组长度
|
|
52
|
+
* @param callback 回调函数
|
|
53
|
+
*/
|
|
54
|
+
const emptyArray = (n, callback) => new Array(n).fill(undefined).map((_, i) => callback(i));
|
|
55
|
+
exports.emptyArray = emptyArray;
|
|
24
56
|
/**
|
|
25
57
|
* 撤销最近一次Mutation
|
|
26
58
|
* @param e 事件
|
|
@@ -30,28 +62,15 @@ exports.Shadow = {
|
|
|
30
62
|
const undo = (e, data) => {
|
|
31
63
|
const { target, type } = e;
|
|
32
64
|
switch (data.type) {
|
|
33
|
-
case 'remove':
|
|
34
|
-
|
|
35
|
-
childNodes.splice(data.position, 0, data.removed);
|
|
36
|
-
data.removed.setAttribute('parentNode', target);
|
|
37
|
-
target.setAttribute('childNodes', childNodes);
|
|
65
|
+
case 'remove':
|
|
66
|
+
(0, exports.setChildNodes)(target, data.position, 0, [data.removed]);
|
|
38
67
|
break;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const childNodes = [...target.childNodes];
|
|
42
|
-
childNodes.splice(data.position, 1);
|
|
43
|
-
data.inserted.setAttribute('parentNode', undefined);
|
|
44
|
-
target.setAttribute('childNodes', childNodes);
|
|
68
|
+
case 'insert':
|
|
69
|
+
(0, exports.setChildNodes)(target, data.position, 1);
|
|
45
70
|
break;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const { parentNode } = target, childNodes = [...parentNode.childNodes];
|
|
49
|
-
childNodes.splice(data.position, 1, data.oldToken);
|
|
50
|
-
data.oldToken.setAttribute('parentNode', parentNode);
|
|
51
|
-
data.newToken.setAttribute('parentNode', undefined);
|
|
52
|
-
parentNode.setAttribute('childNodes', childNodes);
|
|
71
|
+
case 'replace':
|
|
72
|
+
(0, exports.setChildNodes)(target.parentNode, data.position, 1, [data.oldToken]);
|
|
53
73
|
break;
|
|
54
|
-
}
|
|
55
74
|
case 'text':
|
|
56
75
|
if (target.type === 'text') {
|
|
57
76
|
target.replaceData(data.oldText);
|
package/dist/util/lint.js
CHANGED
|
@@ -3,44 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateForSelf = exports.generateForChild = void 0;
|
|
4
4
|
const Parser = require("../index");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param boundingRect 父节点的绝对定位
|
|
9
|
-
* @param msg 错误信息
|
|
10
|
-
* @param severity 严重程度
|
|
6
|
+
* 生成lint函数
|
|
7
|
+
* @param func lint函数
|
|
11
8
|
*/
|
|
12
|
-
const
|
|
13
|
-
const
|
|
9
|
+
const factory = (func) => (token, boundingRect, msg, severity = 'error') => {
|
|
10
|
+
const { start } = boundingRect, { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start), { offsetHeight, offsetWidth } = token, { startIndex, startLine, startCol } = func(token, start, top, left);
|
|
14
11
|
return {
|
|
15
12
|
message: Parser.msg(msg),
|
|
16
13
|
severity,
|
|
17
14
|
startIndex,
|
|
18
|
-
endIndex: startIndex + String(
|
|
15
|
+
endIndex: startIndex + String(token).length,
|
|
19
16
|
startLine,
|
|
20
17
|
endLine: startLine + offsetHeight - 1,
|
|
21
18
|
startCol,
|
|
22
19
|
endCol: offsetHeight === 1 ? startCol + offsetWidth : offsetWidth,
|
|
23
20
|
};
|
|
24
21
|
};
|
|
25
|
-
exports.generateForChild =
|
|
26
|
-
|
|
27
|
-
* 生成对于自己的LintError对象
|
|
28
|
-
* @param token 节点
|
|
29
|
-
* @param boundingRect 绝对定位
|
|
30
|
-
* @param msg 错误信息
|
|
31
|
-
* @param severity 严重程度
|
|
32
|
-
*/
|
|
33
|
-
const generateForSelf = (token, boundingRect, msg, severity = 'error') => {
|
|
34
|
-
const { start } = boundingRect, { offsetHeight, offsetWidth } = token, { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start);
|
|
22
|
+
exports.generateForChild = factory((child, start, line, col) => {
|
|
23
|
+
const index = child.getRelativeIndex(), { top, left } = child.parentNode.posFromIndex(index);
|
|
35
24
|
return {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
endIndex: start + String(token).length,
|
|
40
|
-
startLine: top,
|
|
41
|
-
endLine: top + offsetHeight - 1,
|
|
42
|
-
startCol: left,
|
|
43
|
-
endCol: offsetHeight === 1 ? left + offsetWidth : offsetWidth,
|
|
25
|
+
startIndex: start + index,
|
|
26
|
+
startLine: line + top,
|
|
27
|
+
startCol: top ? left : col + left,
|
|
44
28
|
};
|
|
45
|
-
};
|
|
46
|
-
exports.generateForSelf =
|
|
29
|
+
});
|
|
30
|
+
exports.generateForSelf = factory((_, startIndex, startLine, startCol) => ({ startIndex, startLine, startCol }));
|
package/dist/util/string.js
CHANGED
|
@@ -4,17 +4,15 @@ exports.normalizeSpace = exports.print = exports.noWrap = exports.decodeHtml = e
|
|
|
4
4
|
exports.extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])';
|
|
5
5
|
exports.extUrlChar = '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+[c!~]\\x7F)*';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param
|
|
7
|
+
* 生成正则替换函数
|
|
8
|
+
* @param regex 正则表达式
|
|
9
|
+
* @param replace 替换字符串或函数
|
|
9
10
|
*/
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
const escapeRegExp = (str) => str.replace(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
|
|
17
|
-
exports.escapeRegExp = escapeRegExp;
|
|
11
|
+
const factory = (regex, replace) => (str) => str.replace(regex, replace);
|
|
12
|
+
/** remove half-parsed comment-like tokens */
|
|
13
|
+
exports.removeComment = factory(/\0\d+c\x7F/gu, '');
|
|
14
|
+
/** escape special chars for RegExp constructor */
|
|
15
|
+
exports.escapeRegExp = factory(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
|
|
18
16
|
/**
|
|
19
17
|
* extract effective wikitext
|
|
20
18
|
* @param childNodes a Token's contents
|
|
@@ -22,18 +20,10 @@ exports.escapeRegExp = escapeRegExp;
|
|
|
22
20
|
*/
|
|
23
21
|
const text = (childNodes, separator = '') => childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
24
22
|
exports.text = text;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const decodeHtml = (str) => str.replace(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number(`${code.toLowerCase().startsWith('x') ? '0' : ''}${code}`)));
|
|
30
|
-
exports.decodeHtml = decodeHtml;
|
|
31
|
-
/**
|
|
32
|
-
* escape newlines
|
|
33
|
-
* @param str 原字符串
|
|
34
|
-
*/
|
|
35
|
-
const noWrap = (str) => str.replaceAll('\n', '\\n');
|
|
36
|
-
exports.noWrap = noWrap;
|
|
23
|
+
/** decode HTML entities */
|
|
24
|
+
exports.decodeHtml = factory(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number(`${code.toLowerCase().startsWith('x') ? '0' : ''}${code}`)));
|
|
25
|
+
/** escape newlines */
|
|
26
|
+
exports.noWrap = factory(/\n/gu, '\\n');
|
|
37
27
|
/**
|
|
38
28
|
* 以HTML格式打印
|
|
39
29
|
* @param childNodes 子节点
|