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,51 @@
|
|
|
1
|
+
import Token = require('../src');
|
|
2
|
+
import Title = require('../lib/title');
|
|
3
|
+
import {ParserConfig} from './token';
|
|
4
|
+
|
|
5
|
+
declare interface Parser {
|
|
6
|
+
config: string|ParserConfig;
|
|
7
|
+
i18n: string|Record<string, string>;
|
|
8
|
+
|
|
9
|
+
readonly MAX_STAGE: number;
|
|
10
|
+
|
|
11
|
+
/** 获取设置 */
|
|
12
|
+
getConfig(): ParserConfig;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 生成I18N消息
|
|
16
|
+
* @param msg 消息名
|
|
17
|
+
* @param arg 额外参数
|
|
18
|
+
*/
|
|
19
|
+
msg(msg: string, arg: string): string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 规范化页面标题
|
|
23
|
+
* @param title 标题(含或不含命名空间前缀)
|
|
24
|
+
* @param defaultNs 命名空间
|
|
25
|
+
* @param include 是否嵌入
|
|
26
|
+
* @param halfParsed 是否是半解析状态
|
|
27
|
+
* @param decode 是否需要解码
|
|
28
|
+
* @param selfLink 是否允许selfLink
|
|
29
|
+
*/
|
|
30
|
+
normalizeTitle(
|
|
31
|
+
title: string,
|
|
32
|
+
defaultNs?: number,
|
|
33
|
+
include?: boolean,
|
|
34
|
+
config?: ParserConfig,
|
|
35
|
+
halfParsed?: boolean,
|
|
36
|
+
decode?: boolean,
|
|
37
|
+
selfLink?: boolean,
|
|
38
|
+
): Title;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 解析wikitext
|
|
42
|
+
* @param wikitext wikitext
|
|
43
|
+
* @param include 是否嵌入
|
|
44
|
+
* @param maxStage 最大解析层级
|
|
45
|
+
*/
|
|
46
|
+
parse(wikitext: string, include?: boolean, maxStage?: number, config?: ParserConfig): Token;
|
|
47
|
+
|
|
48
|
+
run<T>(callback: () => T): T;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export = Parser;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Token = require('../src');
|
|
2
|
+
import AstText = require('../lib/text');
|
|
3
|
+
import {ParserConfig, accum} from './token';
|
|
4
|
+
|
|
5
|
+
type buildFromStr = <S extends string>(str: string, type: S) => S extends 'string'|'text' ? string : (AstText|Token)[];
|
|
6
|
+
|
|
7
|
+
export type TokenAttribute<T> =
|
|
8
|
+
T extends 'stage' ? number :
|
|
9
|
+
T extends 'config' ? ParserConfig :
|
|
10
|
+
T extends 'accum' ? accum :
|
|
11
|
+
T extends 'parentNode' ? Token|undefined :
|
|
12
|
+
T extends 'parseOnce' ? (n: number, include: boolean) => Token :
|
|
13
|
+
T extends 'buildFromStr' ? buildFromStr :
|
|
14
|
+
T extends 'build' ? () => void :
|
|
15
|
+
T extends 'bracket'|'include' ? boolean :
|
|
16
|
+
string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Token = require('../src');
|
|
2
|
+
|
|
3
|
+
export interface ParserConfig {
|
|
4
|
+
ext: string[];
|
|
5
|
+
html: string[][];
|
|
6
|
+
namespaces: Record<string, string>;
|
|
7
|
+
nsid: Record<string, number>;
|
|
8
|
+
parserFunction: [Record<string, string>, string[], string[], string[]];
|
|
9
|
+
doubleUnderscore: string[][];
|
|
10
|
+
protocol: string;
|
|
11
|
+
img: Record<string, string>;
|
|
12
|
+
variants: string[];
|
|
13
|
+
excludes: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type accum = Token[];
|
|
17
|
+
|
|
18
|
+
export interface LintError {
|
|
19
|
+
message: string;
|
|
20
|
+
severity: 'error'|'warning';
|
|
21
|
+
startIndex: number;
|
|
22
|
+
endIndex: number;
|
|
23
|
+
startLine: number;
|
|
24
|
+
startCol: number;
|
|
25
|
+
endLine: number;
|
|
26
|
+
endCol: number;
|
|
27
|
+
excerpt: string;
|
|
28
|
+
}
|
package/util/lint.js
CHANGED
package/util/string.js
CHANGED
|
@@ -9,23 +9,6 @@ const extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uF
|
|
|
9
9
|
*/
|
|
10
10
|
const removeComment = str => str.replace(/\0\d+c\x7F/gu, '');
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* 以HTML格式打印
|
|
14
|
-
* @param {(AstText|AstElement)[]} childNodes 子节点
|
|
15
|
-
* @param {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
12
|
/**
|
|
30
13
|
* escape special chars for RegExp constructor
|
|
31
14
|
* @param {string} str RegExp source
|
|
@@ -81,46 +64,12 @@ const decodeHtml = str => str?.replace(
|
|
|
81
64
|
/** @param {string} code */ (_, code) => String.fromCodePoint(`${code[0].toLowerCase() === 'x' ? '0' : ''}${code}`),
|
|
82
65
|
);
|
|
83
66
|
|
|
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
67
|
module.exports = {
|
|
115
68
|
extUrlCharFirst,
|
|
116
69
|
extUrlChar,
|
|
117
70
|
removeComment,
|
|
118
|
-
print,
|
|
119
71
|
escapeRegExp,
|
|
120
72
|
explode,
|
|
121
73
|
text,
|
|
122
74
|
decodeHtml,
|
|
123
|
-
toCase,
|
|
124
|
-
noWrap,
|
|
125
|
-
normalizeSpace,
|
|
126
75
|
};
|
package/lib/ranges.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('..');
|
|
4
|
-
|
|
5
|
-
/** 模拟Python的Range对象。除`step`至少为`1`外,允许负数、小数或`end < start`的情形。 */
|
|
6
|
-
class Range {
|
|
7
|
-
start;
|
|
8
|
-
end;
|
|
9
|
-
step;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {string|Range} str 表达式
|
|
13
|
-
* @throws `RangeError` 起点、终点和步长均应为整数
|
|
14
|
-
* @throws `RangeError` n的系数不能为0
|
|
15
|
-
* @throws `RangeError` 应使用CSS选择器或Python切片的格式
|
|
16
|
-
*/
|
|
17
|
-
constructor(str) {
|
|
18
|
-
if (str instanceof Range) {
|
|
19
|
-
Object.assign(this, str);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
str = str.trim();
|
|
23
|
-
if (str === 'odd') {
|
|
24
|
-
Object.assign(this, {start: 1, end: Infinity, step: 2});
|
|
25
|
-
} else if (str === 'even') {
|
|
26
|
-
Object.assign(this, {start: 0, end: Infinity, step: 2});
|
|
27
|
-
} else if (str.includes(':')) {
|
|
28
|
-
const [start, end, step = '1'] = str.split(':', 3);
|
|
29
|
-
this.start = Number(start);
|
|
30
|
-
this.end = Number(end || Infinity);
|
|
31
|
-
this.step = Math.max(Number(step), 1);
|
|
32
|
-
if (!Number.isInteger(this.start)) {
|
|
33
|
-
throw new RangeError(`起点 ${this.start} 应为整数!`);
|
|
34
|
-
} else if (this.end !== Infinity && !Number.isInteger(this.end)) {
|
|
35
|
-
throw new RangeError(`终点 ${this.end} 应为整数!`);
|
|
36
|
-
} else if (!Number.isInteger(this.step)) {
|
|
37
|
-
throw new RangeError(`步长 ${this.step} 应为整数!`);
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
const mt = /^([+-])?(\d+)?n(?:([+-])(\d+))?$/u.exec(str);
|
|
41
|
-
if (mt) {
|
|
42
|
-
const [, sgnA = '+', a = 1, sgnB = '+'] = mt,
|
|
43
|
-
b = Number(mt[4] ?? 0);
|
|
44
|
-
this.step = Number(a);
|
|
45
|
-
if (this.step === 0) {
|
|
46
|
-
throw new RangeError(`参数 ${str} 中 "n" 的系数不允许为 0!`);
|
|
47
|
-
} else if (sgnA === '+') {
|
|
48
|
-
this.start = sgnB === '+' || b === 0 ? b : this.step - 1 - (b - 1) % this.step;
|
|
49
|
-
this.end = Infinity;
|
|
50
|
-
} else if (sgnB === '-') {
|
|
51
|
-
this.start = 0;
|
|
52
|
-
this.end = b > 0 ? 0 : this.step;
|
|
53
|
-
} else {
|
|
54
|
-
this.start = b % this.step;
|
|
55
|
-
this.end = this.step + b;
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
throw new RangeError(`参数 ${str} 应写作CSS选择器的 "an+b" 形式或Python切片!`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 将Range转换为针对特定数组的下标集
|
|
65
|
-
* @param {number|*[]} arr 参考数组
|
|
66
|
-
* @complexity `n`
|
|
67
|
-
*/
|
|
68
|
-
applyTo(arr) {
|
|
69
|
-
return new Array(typeof arr === 'number' ? arr : arr.length).fill().map((_, i) => i).slice(this.start, this.end)
|
|
70
|
-
.filter((_, j) => j % this.step === 0);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** @extends {Array<number|Range>} */
|
|
75
|
-
class Ranges extends Array {
|
|
76
|
-
/** @param {number|string|Range|(number|string|Range)[]} arr 表达式数组 */
|
|
77
|
-
constructor(arr) {
|
|
78
|
-
super();
|
|
79
|
-
if (arr === undefined) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
arr = Array.isArray(arr) ? arr : [arr];
|
|
83
|
-
for (const ele of arr) {
|
|
84
|
-
if (ele instanceof Range) {
|
|
85
|
-
this.push(new Range(ele));
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const number = Number(ele);
|
|
89
|
-
if (Number.isInteger(number)) {
|
|
90
|
-
this.push(number);
|
|
91
|
-
} else if (typeof ele === 'string' && Number.isNaN(number)) {
|
|
92
|
-
try {
|
|
93
|
-
const range = new Range(ele);
|
|
94
|
-
this.push(range);
|
|
95
|
-
} catch {}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 将Ranges转换为针对特定Array的下标集
|
|
102
|
-
* @param {number|*[]} arr 参考数组
|
|
103
|
-
* @complexity `n`
|
|
104
|
-
*/
|
|
105
|
-
applyTo(arr) {
|
|
106
|
-
const length = typeof arr === 'number' ? arr : arr.length;
|
|
107
|
-
return [
|
|
108
|
-
...new Set(
|
|
109
|
-
[...this].flatMap(ele => {
|
|
110
|
-
if (typeof ele === 'number') {
|
|
111
|
-
return ele < 0 ? ele + length : ele;
|
|
112
|
-
}
|
|
113
|
-
return ele.applyTo(length);
|
|
114
|
-
}),
|
|
115
|
-
),
|
|
116
|
-
].filter(i => i >= 0 && i < length).sort();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 检查某个下标是否符合表达式
|
|
121
|
-
* @param {string} str 表达式
|
|
122
|
-
* @param {number} i 待检查的下标
|
|
123
|
-
*/
|
|
124
|
-
static nth(str, i) {
|
|
125
|
-
return new Ranges(str.split(',')).applyTo(i + 1).includes(i);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
Parser.classes.Ranges = __filename;
|
|
130
|
-
module.exports = Ranges;
|
package/mixin/attributeParent.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('..'),
|
|
4
|
-
AttributesToken = require('../src/attributes');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 子节点含有AttributesToken的类
|
|
8
|
-
* @template T
|
|
9
|
-
* @param {T} Constructor 基类
|
|
10
|
-
* @param {number} i AttributesToken子节点的位置
|
|
11
|
-
* @returns {T}
|
|
12
|
-
*/
|
|
13
|
-
const attributeParent = (Constructor, i = 0) => class extends Constructor {
|
|
14
|
-
/** getAttrs()方法的getter写法 */
|
|
15
|
-
get attributes() {
|
|
16
|
-
return this.getAttrs();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** 以字符串表示的class属性 */
|
|
20
|
-
get className() {
|
|
21
|
-
const attr = this.getAttr('class');
|
|
22
|
-
return typeof attr === 'string' ? attr : '';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
set className(className) {
|
|
26
|
-
this.setAttr('class', className);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** 以Set表示的class属性 */
|
|
30
|
-
get classList() {
|
|
31
|
-
return new Set(this.className.split(/\s/u));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** id属性 */
|
|
35
|
-
get id() {
|
|
36
|
-
const attr = this.getAttr('id');
|
|
37
|
-
return typeof attr === 'string' ? attr : '';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
set id(id) {
|
|
41
|
-
this.setAttr('id', id);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* AttributesToken子节点是否具有某属性
|
|
46
|
-
* @this {{childNodes: AttributesToken[]}}
|
|
47
|
-
* @param {string} key 属性键
|
|
48
|
-
*/
|
|
49
|
-
hasAttr(key) {
|
|
50
|
-
return this.childNodes.at(i).hasAttr(key);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 获取AttributesToken子节点的属性
|
|
55
|
-
* @this {{childNodes: AttributesToken[]}}
|
|
56
|
-
* @param {string} key 属性键
|
|
57
|
-
*/
|
|
58
|
-
getAttr(key) {
|
|
59
|
-
return this.childNodes.at(i).getAttr(key);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 列举AttributesToken子节点的属性键
|
|
64
|
-
* @this {{childNodes: AttributesToken[]}}
|
|
65
|
-
*/
|
|
66
|
-
getAttrNames() {
|
|
67
|
-
return this.childNodes.at(i).getAttrNames();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* AttributesToken子节点是否具有任意属性
|
|
72
|
-
* @this {{childNodes: AttributesToken[]}}
|
|
73
|
-
*/
|
|
74
|
-
hasAttrs() {
|
|
75
|
-
return this.childNodes.at(i).hasAttrs();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 获取AttributesToken子节点的全部标签属性
|
|
80
|
-
* @this {{childNodes: AttributesToken[]}}
|
|
81
|
-
*/
|
|
82
|
-
getAttrs() {
|
|
83
|
-
return this.childNodes.at(i).getAttrs();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 对AttributesToken子节点设置属性
|
|
88
|
-
* @this {{childNodes: AttributesToken[]}}
|
|
89
|
-
* @param {string} key 属性键
|
|
90
|
-
* @param {string|boolean} value 属性值
|
|
91
|
-
*/
|
|
92
|
-
setAttr(key, value) {
|
|
93
|
-
return this.childNodes.at(i).setAttr(key, value);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 移除AttributesToken子节点的某属性
|
|
98
|
-
* @this {{childNodes: AttributesToken[]}}
|
|
99
|
-
* @param {string} key 属性键
|
|
100
|
-
*/
|
|
101
|
-
removeAttr(key) {
|
|
102
|
-
this.childNodes.at(i).removeAttr(key);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 开关AttributesToken子节点的某属性
|
|
107
|
-
* @this {{childNodes: AttributesToken[]}}
|
|
108
|
-
* @param {string} key 属性键
|
|
109
|
-
* @param {boolean|undefined} force 强制开启或关闭
|
|
110
|
-
*/
|
|
111
|
-
toggleAttr(key, force) {
|
|
112
|
-
this.childNodes.at(i).toggleAttr(key, force);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
Parser.mixins.attributeParent = __filename;
|
|
117
|
-
module.exports = attributeParent;
|
package/mixin/fixedToken.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('..'),
|
|
4
|
-
Token = require('../src');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 不可增删子节点的类
|
|
8
|
-
* @template T
|
|
9
|
-
* @param {T} Constructor 基类
|
|
10
|
-
* @returns {T}
|
|
11
|
-
*/
|
|
12
|
-
const fixedToken = Constructor => class extends Constructor {
|
|
13
|
-
static fixed = true;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 移除子节点
|
|
17
|
-
* @throws `Error`
|
|
18
|
-
*/
|
|
19
|
-
removeAt() {
|
|
20
|
-
throw new Error(`${this.constructor.name} 不可删除元素!`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 插入子节点
|
|
25
|
-
* @template {Token} T
|
|
26
|
-
* @param {T} token 待插入的子节点
|
|
27
|
-
* @param {number} i 插入位置
|
|
28
|
-
* @throws `Error`
|
|
29
|
-
*/
|
|
30
|
-
insertAt(token, i = this.length) {
|
|
31
|
-
if (Parser.running) {
|
|
32
|
-
super.insertAt(token, i);
|
|
33
|
-
return token;
|
|
34
|
-
}
|
|
35
|
-
throw new Error(`${this.constructor.name} 不可插入元素!`);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
Parser.mixins.fixedToken = __filename;
|
|
40
|
-
module.exports = fixedToken;
|
package/mixin/singleLine.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('..');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 不可包含换行符的类
|
|
7
|
-
* @template {Function} T
|
|
8
|
-
* @param {T} Constructor 基类
|
|
9
|
-
* @returns {T}
|
|
10
|
-
*/
|
|
11
|
-
const singleLine = Constructor => {
|
|
12
|
-
const SingleLineConstructor = class extends Constructor {
|
|
13
|
-
/**
|
|
14
|
-
* @override
|
|
15
|
-
* @param {string} selector
|
|
16
|
-
*/
|
|
17
|
-
toString(selector) {
|
|
18
|
-
return super.toString(selector).replaceAll('\n', ' ');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @override */
|
|
22
|
-
text() {
|
|
23
|
-
return super.text().replaceAll('\n', ' ');
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(SingleLineConstructor, 'name', {value: `SingleLine${Constructor.name}`});
|
|
27
|
-
return SingleLineConstructor;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
Parser.mixins.singleLine = __filename;
|
|
31
|
-
module.exports = singleLine;
|
package/mixin/sol.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('..'),
|
|
4
|
-
Token = require('../src');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 只能位于行首的类
|
|
8
|
-
* @template T
|
|
9
|
-
* @param {T} Constructor 基类
|
|
10
|
-
* @returns {T}
|
|
11
|
-
*/
|
|
12
|
-
const sol = Constructor => class SolToken extends Constructor {
|
|
13
|
-
/**
|
|
14
|
-
* 是否可以视为root节点
|
|
15
|
-
* @this {Token}
|
|
16
|
-
*/
|
|
17
|
-
#isRoot() {
|
|
18
|
-
const {parentNode, type} = this;
|
|
19
|
-
return parentNode?.type === 'root'
|
|
20
|
-
|| type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 在前方插入newline
|
|
25
|
-
* @this {SolToken & Token}
|
|
26
|
-
*/
|
|
27
|
-
prependNewLine() {
|
|
28
|
-
return (this.previousVisibleSibling || !this.#isRoot()) && !String(this.previousVisibleSibling).endsWith('\n')
|
|
29
|
-
? '\n'
|
|
30
|
-
: '';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 还原为wikitext
|
|
35
|
-
* @this {SolToken & Token}
|
|
36
|
-
* @param {string} selector
|
|
37
|
-
*/
|
|
38
|
-
toString(selector) {
|
|
39
|
-
return selector && this.matches(selector) ? '' : `${this.prependNewLine()}${super.toString(selector)}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** 获取padding */
|
|
43
|
-
getPadding() {
|
|
44
|
-
return this.prependNewLine().length;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** 可见部分 */
|
|
48
|
-
text() {
|
|
49
|
-
return `${this.prependNewLine()}${super.text()}`;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
Parser.mixins.sol = __filename;
|
|
54
|
-
module.exports = sol;
|