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/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/lib/text.js
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../typings/token').LintError} LintError */
|
|
4
|
-
|
|
5
|
-
const Parser = require('..'),
|
|
6
|
-
AstNode = require('./node'),
|
|
7
|
-
AstElement = require('./element');
|
|
8
|
-
|
|
9
|
-
const errorSyntax = /https?:\/\/|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu,
|
|
10
|
-
errorSyntaxUrl = /\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu,
|
|
11
|
-
disallowedTags = [
|
|
12
|
-
'html',
|
|
13
|
-
'base',
|
|
14
|
-
'head',
|
|
15
|
-
'style',
|
|
16
|
-
'title',
|
|
17
|
-
'body',
|
|
18
|
-
'menu',
|
|
19
|
-
'a',
|
|
20
|
-
'area',
|
|
21
|
-
'audio',
|
|
22
|
-
'img',
|
|
23
|
-
'map',
|
|
24
|
-
'track',
|
|
25
|
-
'video',
|
|
26
|
-
'embed',
|
|
27
|
-
'iframe',
|
|
28
|
-
'object',
|
|
29
|
-
'picture',
|
|
30
|
-
'source',
|
|
31
|
-
'canvas',
|
|
32
|
-
'script',
|
|
33
|
-
'col',
|
|
34
|
-
'colgroup',
|
|
35
|
-
'tbody',
|
|
36
|
-
'tfoot',
|
|
37
|
-
'thead',
|
|
38
|
-
'button',
|
|
39
|
-
'datalist',
|
|
40
|
-
'fieldset',
|
|
41
|
-
'form',
|
|
42
|
-
'input',
|
|
43
|
-
'label',
|
|
44
|
-
'legend',
|
|
45
|
-
'meter',
|
|
46
|
-
'optgroup',
|
|
47
|
-
'option',
|
|
48
|
-
'output',
|
|
49
|
-
'progress',
|
|
50
|
-
'select',
|
|
51
|
-
'textarea',
|
|
52
|
-
'details',
|
|
53
|
-
'dialog',
|
|
54
|
-
'slot',
|
|
55
|
-
'template',
|
|
56
|
-
'dir',
|
|
57
|
-
'frame',
|
|
58
|
-
'frameset',
|
|
59
|
-
'marquee',
|
|
60
|
-
'param',
|
|
61
|
-
'xmp',
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
/** 文本节点 */
|
|
65
|
-
class AstText extends AstNode {
|
|
66
|
-
type = 'text';
|
|
67
|
-
/** @type {string} */ data;
|
|
68
|
-
|
|
69
|
-
/** 文本长度 */
|
|
70
|
-
get length() {
|
|
71
|
-
return this.data.length;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** @param {string} text 包含文本 */
|
|
75
|
-
constructor(text = '') {
|
|
76
|
-
super();
|
|
77
|
-
Object.defineProperties(this, {
|
|
78
|
-
data: {value: text, writable: false},
|
|
79
|
-
childNodes: {enumerable: false, configurable: false},
|
|
80
|
-
type: {enumerable: false, writable: false, configurable: false},
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** 输出字符串 */
|
|
85
|
-
toString() {
|
|
86
|
-
return this.data;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** @override */
|
|
90
|
-
text() {
|
|
91
|
-
return this.data;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Linter
|
|
96
|
-
* @this {AstText & {parentNode: AstElement}}
|
|
97
|
-
* @param {number} start 起始位置
|
|
98
|
-
* @returns {LintError[]}
|
|
99
|
-
*/
|
|
100
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
101
|
-
const {data, parentNode, nextSibling, previousSibling} = this,
|
|
102
|
-
type = parentNode?.type,
|
|
103
|
-
name = parentNode?.name,
|
|
104
|
-
nextType = nextSibling?.type,
|
|
105
|
-
previousType = previousSibling?.type,
|
|
106
|
-
errorRegex
|
|
107
|
-
= type === 'free-ext-link' || type === 'ext-link-url' || type === 'image-parameter' && name === 'link'
|
|
108
|
-
? errorSyntaxUrl
|
|
109
|
-
: errorSyntax,
|
|
110
|
-
errors = [...data.matchAll(errorRegex)],
|
|
111
|
-
{ext, html} = this.getRootNode().getAttribute('config');
|
|
112
|
-
if (errors.length > 0) {
|
|
113
|
-
const root = this.getRootNode(),
|
|
114
|
-
{top, left} = root.posFromIndex(start),
|
|
115
|
-
tags = new Set([ext, html, disallowedTags].flat(2));
|
|
116
|
-
return errors.map(/** @returns {LintError} */ ({0: error, 1: prefix, 2: tag, index}) => {
|
|
117
|
-
if (prefix) {
|
|
118
|
-
index += prefix.length;
|
|
119
|
-
error = error.slice(prefix.length);
|
|
120
|
-
}
|
|
121
|
-
const startIndex = start + index,
|
|
122
|
-
lines = data.slice(0, index).split('\n'),
|
|
123
|
-
startLine = lines.length + top - 1,
|
|
124
|
-
line = lines.at(-1),
|
|
125
|
-
startCol = lines.length > 1 ? line.length : left + line.length,
|
|
126
|
-
{0: char, length} = error,
|
|
127
|
-
endIndex = startIndex + length,
|
|
128
|
-
end = char === '}' || char === ']' ? endIndex + 1 : startIndex + 49,
|
|
129
|
-
rootStr = String(root),
|
|
130
|
-
nextChar = rootStr[endIndex],
|
|
131
|
-
previousChar = rootStr[startIndex - 1],
|
|
132
|
-
severity = length > 1 && (char !== '<' || /[\s/>]/u.test(nextChar))
|
|
133
|
-
|| char === '{' && (nextChar === char || previousChar === '-')
|
|
134
|
-
|| char === '}' && (previousChar === char || nextChar === '-')
|
|
135
|
-
|| char === '[' && (
|
|
136
|
-
nextChar === char || type === 'ext-link-text'
|
|
137
|
-
|| !data.slice(index + 1).trim() && nextType === 'free-ext-link'
|
|
138
|
-
)
|
|
139
|
-
|| char === ']' && (
|
|
140
|
-
previousChar === char
|
|
141
|
-
|| !data.slice(0, index).trim() && previousType === 'free-ext-link'
|
|
142
|
-
)
|
|
143
|
-
? 'error'
|
|
144
|
-
: 'warning';
|
|
145
|
-
return (char !== 'h' || index > 0) && (char !== '<' || tags.has(tag.toLowerCase())) && {
|
|
146
|
-
message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
|
|
147
|
-
severity,
|
|
148
|
-
startIndex,
|
|
149
|
-
endIndex,
|
|
150
|
-
startLine,
|
|
151
|
-
endLine: startLine,
|
|
152
|
-
startCol,
|
|
153
|
-
endCol: startCol + length,
|
|
154
|
-
excerpt: rootStr.slice(Math.max(0, end - 50), end),
|
|
155
|
-
};
|
|
156
|
-
}).filter(Boolean);
|
|
157
|
-
}
|
|
158
|
-
return [];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 修改内容
|
|
163
|
-
* @param {string} text 新内容
|
|
164
|
-
*/
|
|
165
|
-
#setData(text) {
|
|
166
|
-
text = String(text);
|
|
167
|
-
const {data} = this,
|
|
168
|
-
e = new Event('text', {bubbles: true});
|
|
169
|
-
this.setAttribute('data', text);
|
|
170
|
-
if (data !== text) {
|
|
171
|
-
this.dispatchEvent(e, {oldText: data, newText: text});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* 替换字符串
|
|
177
|
-
* @param {string} text 替换的字符串
|
|
178
|
-
*/
|
|
179
|
-
replaceData(text = '') {
|
|
180
|
-
this.#setData(text);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** 复制 */
|
|
184
|
-
cloneNode() {
|
|
185
|
-
return new AstText(this.data);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @override
|
|
190
|
-
* @template {string} T
|
|
191
|
-
* @param {T} key 属性键
|
|
192
|
-
* @returns {import('../typings/node').TokenAttribute<T>}
|
|
193
|
-
* @throws `Error` 文本节点没有子节点
|
|
194
|
-
*/
|
|
195
|
-
getAttribute(key) {
|
|
196
|
-
return key === 'verifyChild'
|
|
197
|
-
? () => {
|
|
198
|
-
throw new Error('文本节点没有子节点!');
|
|
199
|
-
}
|
|
200
|
-
: super.getAttribute(key);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* 在后方添加字符串
|
|
205
|
-
* @param {string} text 添加的字符串
|
|
206
|
-
*/
|
|
207
|
-
appendData(text) {
|
|
208
|
-
this.#setData(this.data + text);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* 删减字符串
|
|
213
|
-
* @param {number} offset 起始位置
|
|
214
|
-
* @param {number} count 删减字符数
|
|
215
|
-
*/
|
|
216
|
-
deleteData(offset, count) {
|
|
217
|
-
this.#setData(this.data.slice(0, offset) + this.data.slice(offset + count));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* 插入字符串
|
|
222
|
-
* @param {number} offset 插入位置
|
|
223
|
-
* @param {string} text 待插入的字符串
|
|
224
|
-
*/
|
|
225
|
-
insertData(offset, text) {
|
|
226
|
-
this.#setData(this.data.slice(0, offset) + text + this.data.slice(offset));
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* 提取子串
|
|
231
|
-
* @param {number} offset 起始位置
|
|
232
|
-
* @param {number} count 字符数
|
|
233
|
-
*/
|
|
234
|
-
substringData(offset, count) {
|
|
235
|
-
return this.data.slice(offset, offset + count);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* 将文本子节点分裂为两部分
|
|
240
|
-
* @param {number} offset 分裂位置
|
|
241
|
-
* @throws `RangeError` 错误的断开位置
|
|
242
|
-
* @throws `Error` 没有父节点
|
|
243
|
-
*/
|
|
244
|
-
splitText(offset) {
|
|
245
|
-
if (!Number.isInteger(offset)) {
|
|
246
|
-
this.typeError('splitText', 'Number');
|
|
247
|
-
} else if (offset > this.length || offset < -this.length) {
|
|
248
|
-
throw new RangeError(`错误的断开位置!${offset}`);
|
|
249
|
-
}
|
|
250
|
-
const {parentNode, data} = this;
|
|
251
|
-
if (!parentNode) {
|
|
252
|
-
throw new Error('待分裂的文本节点没有父节点!');
|
|
253
|
-
}
|
|
254
|
-
const newText = new AstText(data.slice(offset)),
|
|
255
|
-
childNodes = [...parentNode.childNodes];
|
|
256
|
-
this.setAttribute('data', data.slice(0, offset));
|
|
257
|
-
childNodes.splice(childNodes.indexOf(this) + 1, 0, newText);
|
|
258
|
-
newText.setAttribute('parentNode', parentNode);
|
|
259
|
-
parentNode.setAttribute('childNodes', childNodes);
|
|
260
|
-
return newText;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
Parser.classes.AstText = __filename;
|
|
265
|
-
module.exports = AstText;
|
package/lib/title.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {decodeHtml} = require('../util/string'),
|
|
4
|
-
Parser = require('..');
|
|
5
|
-
|
|
6
|
-
/** MediaWiki页面标题对象 */
|
|
7
|
-
class Title {
|
|
8
|
-
valid = true;
|
|
9
|
-
ns = 0;
|
|
10
|
-
fragment;
|
|
11
|
-
encoded = false;
|
|
12
|
-
title = '';
|
|
13
|
-
main = '';
|
|
14
|
-
prefix = '';
|
|
15
|
-
interwiki = '';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param {string} title 标题(含或不含命名空间前缀)
|
|
19
|
-
* @param {number} defaultNs 命名空间
|
|
20
|
-
* @param {boolean} decode 是否需要解码
|
|
21
|
-
* @param {boolean} selfLink 是否允许selfLink
|
|
22
|
-
*/
|
|
23
|
-
constructor(title, defaultNs = 0, config = Parser.getConfig(), decode = false, selfLink = false) {
|
|
24
|
-
const {namespaces, nsid} = config;
|
|
25
|
-
let namespace = namespaces[defaultNs];
|
|
26
|
-
title = decodeHtml(title);
|
|
27
|
-
if (decode && title.includes('%')) {
|
|
28
|
-
try {
|
|
29
|
-
const encoded = /%(?!21|3[ce]|5[bd]|7[b-d])[\da-f]{2}/iu.test(title);
|
|
30
|
-
title = decodeURIComponent(title);
|
|
31
|
-
this.encoded = encoded;
|
|
32
|
-
} catch {}
|
|
33
|
-
}
|
|
34
|
-
title = title.replaceAll('_', ' ').trim();
|
|
35
|
-
if (title[0] === ':') {
|
|
36
|
-
namespace = '';
|
|
37
|
-
title = title.slice(1).trim();
|
|
38
|
-
}
|
|
39
|
-
const iw = defaultNs ? undefined : Parser.isInterwiki(title, config);
|
|
40
|
-
if (iw) {
|
|
41
|
-
this.interwiki = iw[1].toLowerCase();
|
|
42
|
-
title = title.slice(iw[0].length);
|
|
43
|
-
}
|
|
44
|
-
const m = title.split(':');
|
|
45
|
-
if (m.length > 1) {
|
|
46
|
-
const id = namespaces[nsid[m[0].trim().toLowerCase()]];
|
|
47
|
-
if (id !== undefined) {
|
|
48
|
-
namespace = id;
|
|
49
|
-
title = m.slice(1).join(':').trim();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
this.ns = nsid[namespace.toLowerCase()];
|
|
53
|
-
const i = title.indexOf('#');
|
|
54
|
-
let fragment;
|
|
55
|
-
if (i !== -1) {
|
|
56
|
-
fragment = title.slice(i + 1).trimEnd();
|
|
57
|
-
if (fragment.includes('%')) {
|
|
58
|
-
try {
|
|
59
|
-
fragment = decodeURIComponent(fragment);
|
|
60
|
-
} catch {}
|
|
61
|
-
} else if (fragment.includes('.')) {
|
|
62
|
-
try {
|
|
63
|
-
fragment = decodeURIComponent(fragment.replaceAll('.', '%'));
|
|
64
|
-
} catch {}
|
|
65
|
-
}
|
|
66
|
-
title = title.slice(0, i).trim();
|
|
67
|
-
}
|
|
68
|
-
this.valid = Boolean(title || selfLink && fragment !== undefined || this.interwiki)
|
|
69
|
-
&& !/\0\d+[eh!+-]\x7F|[<>[\]{}|]|%[\da-f]{2}/iu.test(title);
|
|
70
|
-
this.fragment = fragment;
|
|
71
|
-
this.main = title && `${title[0].toUpperCase()}${title.slice(1)}`;
|
|
72
|
-
this.prefix = `${namespace}${namespace && ':'}`;
|
|
73
|
-
this.title = `${iw ? `${this.interwiki}:` : ''}${this.prefix}${this.main.replaceAll(' ', '_')}`;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** @override */
|
|
77
|
-
toString() {
|
|
78
|
-
return `${this.title}${this.fragment === undefined ? '' : `#${this.fragment}`}`;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
Parser.classes.Title = __filename;
|
|
83
|
-
module.exports = Title;
|
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/hidden.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('..');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 解析后不可见的类
|
|
7
|
-
* @template T
|
|
8
|
-
* @param {T} Constructor 基类
|
|
9
|
-
* @returns {T}
|
|
10
|
-
*/
|
|
11
|
-
const hidden = Constructor => class extends Constructor {
|
|
12
|
-
static hidden = true;
|
|
13
|
-
|
|
14
|
-
/** 没有可见部分 */
|
|
15
|
-
text() { // eslint-disable-line class-methods-use-this
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
Parser.mixins.hidden = __filename;
|
|
21
|
-
module.exports = hidden;
|
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;
|