wikilint 2.16.3 → 2.16.5
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/coverage/badge.svg +1 -1
- package/data/signatures.json +43 -0
- package/dist/base.d.mts +84 -27
- package/dist/base.d.ts +84 -27
- package/dist/bin/cli.js +2 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +55 -11
- package/dist/lib/element.d.ts +56 -10
- package/dist/lib/element.js +97 -11
- package/dist/lib/lsp.d.ts +62 -27
- package/dist/lib/lsp.js +395 -304
- package/dist/lib/node.d.ts +51 -19
- package/dist/lib/node.js +80 -34
- package/dist/lib/text.d.ts +8 -2
- package/dist/lib/text.js +10 -3
- package/dist/lib/title.d.ts +23 -9
- package/dist/lib/title.js +56 -21
- package/dist/mixin/attributesParent.d.ts +4 -4
- package/dist/mixin/attributesParent.js +2 -4
- package/dist/mixin/hidden.d.ts +0 -2
- package/dist/mixin/hidden.js +0 -2
- package/dist/parser/braces.js +4 -2
- package/dist/parser/links.js +8 -7
- package/dist/parser/list.js +3 -1
- package/dist/parser/quotes.js +2 -1
- package/dist/parser/redirect.js +4 -1
- package/dist/src/arg.d.ts +4 -2
- package/dist/src/arg.js +8 -4
- package/dist/src/atom.d.ts +5 -1
- package/dist/src/atom.js +5 -1
- package/dist/src/attribute.d.ts +9 -3
- package/dist/src/attribute.js +9 -3
- package/dist/src/attributes.d.ts +12 -4
- package/dist/src/attributes.js +12 -4
- package/dist/src/converter.d.ts +3 -1
- package/dist/src/converter.js +8 -5
- package/dist/src/converterFlags.d.ts +13 -3
- package/dist/src/converterFlags.js +13 -3
- package/dist/src/converterRule.d.ts +3 -1
- package/dist/src/converterRule.js +3 -1
- package/dist/src/extLink.d.ts +2 -0
- package/dist/src/extLink.js +2 -0
- package/dist/src/gallery.d.ts +3 -1
- package/dist/src/gallery.js +7 -5
- package/dist/src/heading.d.ts +3 -1
- package/dist/src/heading.js +10 -8
- package/dist/src/hidden.d.ts +5 -1
- package/dist/src/hidden.js +5 -1
- package/dist/src/html.d.ts +9 -2
- package/dist/src/html.js +201 -146
- package/dist/src/imageParameter.d.ts +11 -3
- package/dist/src/imageParameter.js +12 -4
- package/dist/src/imagemap.d.ts +1 -1
- package/dist/src/imagemap.js +5 -4
- package/dist/src/imagemapLink.d.ts +2 -0
- package/dist/src/imagemapLink.js +2 -0
- package/dist/src/index.d.ts +5 -24
- package/dist/src/index.js +28 -73
- package/dist/src/link/base.d.ts +5 -1
- package/dist/src/link/base.js +17 -7
- package/dist/src/link/category.d.ts +4 -0
- package/dist/src/link/category.js +2 -0
- package/dist/src/link/file.d.ts +17 -7
- package/dist/src/link/file.js +28 -14
- package/dist/src/link/galleryImage.d.ts +5 -1
- package/dist/src/link/galleryImage.js +9 -5
- package/dist/src/link/index.d.ts +4 -0
- package/dist/src/link/index.js +2 -0
- package/dist/src/link/redirectTarget.d.ts +3 -1
- package/dist/src/link/redirectTarget.js +4 -2
- package/dist/src/magicLink.d.ts +12 -3
- package/dist/src/magicLink.js +36 -7
- package/dist/src/nested.d.ts +3 -1
- package/dist/src/nested.js +7 -4
- package/dist/src/nowiki/base.d.ts +3 -1
- package/dist/src/nowiki/base.js +3 -1
- package/dist/src/nowiki/comment.d.ts +5 -1
- package/dist/src/nowiki/comment.js +5 -1
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -1
- package/dist/src/nowiki/doubleUnderscore.js +5 -1
- package/dist/src/nowiki/index.d.ts +5 -1
- package/dist/src/nowiki/index.js +5 -1
- package/dist/src/nowiki/list.d.ts +5 -1
- package/dist/src/nowiki/list.js +5 -1
- package/dist/src/nowiki/noinclude.d.ts +5 -1
- package/dist/src/nowiki/noinclude.js +5 -1
- package/dist/src/nowiki/quote.d.ts +5 -1
- package/dist/src/nowiki/quote.js +5 -1
- package/dist/src/onlyinclude.d.ts +3 -1
- package/dist/src/onlyinclude.js +3 -1
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +1 -1
- package/dist/src/parameter.d.ts +3 -1
- package/dist/src/parameter.js +3 -1
- package/dist/src/pre.d.ts +1 -1
- package/dist/src/pre.js +1 -1
- package/dist/src/redirect.d.ts +2 -0
- package/dist/src/redirect.js +2 -0
- package/dist/src/syntax.d.ts +5 -1
- package/dist/src/syntax.js +5 -1
- package/dist/src/table/base.js +3 -1
- package/dist/src/table/index.d.ts +20 -15
- package/dist/src/table/index.js +22 -23
- package/dist/src/table/td.d.ts +9 -3
- package/dist/src/table/td.js +9 -3
- package/dist/src/table/tr.d.ts +3 -1
- package/dist/src/table/tr.js +4 -2
- package/dist/src/table/trBase.d.ts +9 -9
- package/dist/src/table/trBase.js +13 -18
- package/dist/src/tagPair/ext.d.ts +6 -1
- package/dist/src/tagPair/ext.js +151 -98
- package/dist/src/tagPair/include.d.ts +2 -0
- package/dist/src/tagPair/include.js +2 -0
- package/dist/src/tagPair/index.d.ts +6 -2
- package/dist/src/tagPair/index.js +6 -2
- package/dist/src/transclude.d.ts +39 -10
- package/dist/src/transclude.js +69 -18
- package/dist/util/debug.js +2 -16
- package/dist/util/string.js +2 -0
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +3 -2
- package/dist/bin/coverage.js +0 -20
package/dist/lib/node.d.ts
CHANGED
|
@@ -13,57 +13,89 @@ export interface CaretPosition {
|
|
|
13
13
|
readonly offsetNode: AstNodes;
|
|
14
14
|
readonly offset: number;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Node-like
|
|
18
|
+
*
|
|
19
|
+
* 类似Node
|
|
20
|
+
*/
|
|
17
21
|
export declare abstract class AstNode implements AstNodeBase {
|
|
18
22
|
#private;
|
|
19
23
|
data?: string | undefined;
|
|
20
24
|
readonly childNodes: readonly AstNodes[];
|
|
21
25
|
abstract get type(): TokenTypes | 'text';
|
|
22
26
|
abstract set type(value: TokenTypes | "text");
|
|
23
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Get the visible text
|
|
29
|
+
*
|
|
30
|
+
* 可见部分
|
|
31
|
+
*/
|
|
24
32
|
text(): string;
|
|
25
33
|
lint(): LintError[];
|
|
26
|
-
/** 首位子节点 */
|
|
34
|
+
/** first child node / 首位子节点 */
|
|
27
35
|
get firstChild(): AstNodes | undefined;
|
|
28
|
-
/** 末位子节点 */
|
|
36
|
+
/** last child node / 末位子节点 */
|
|
29
37
|
get lastChild(): AstNodes | undefined;
|
|
30
|
-
/** 父节点 */
|
|
38
|
+
/** parent node / 父节点 */
|
|
31
39
|
get parentNode(): Token | undefined;
|
|
32
|
-
/** 后一个兄弟节点 */
|
|
40
|
+
/** next sibling node / 后一个兄弟节点 */
|
|
33
41
|
get nextSibling(): AstNodes | undefined;
|
|
34
|
-
/** 前一个兄弟节点 */
|
|
42
|
+
/** previous sibling node / 前一个兄弟节点 */
|
|
35
43
|
get previousSibling(): AstNodes | undefined;
|
|
36
|
-
/** 行数 */
|
|
44
|
+
/** number of lines / 行数 */
|
|
37
45
|
get offsetHeight(): number;
|
|
38
|
-
/** 最后一行的列数 */
|
|
46
|
+
/** number of columns of the last line / 最后一行的列数 */
|
|
39
47
|
get offsetWidth(): number;
|
|
40
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Get the root node
|
|
50
|
+
*
|
|
51
|
+
* 获取根节点
|
|
52
|
+
*/
|
|
41
53
|
getRootNode(): Token | this;
|
|
42
54
|
/**
|
|
55
|
+
* Convert the position to the character index
|
|
56
|
+
*
|
|
43
57
|
* 将行列号转换为字符位置
|
|
44
|
-
* @param top 行号
|
|
45
|
-
* @param left 列号
|
|
58
|
+
* @param top line number / 行号
|
|
59
|
+
* @param left column number / 列号
|
|
46
60
|
*/
|
|
47
61
|
indexFromPos(top: number, left: number): number | undefined;
|
|
48
62
|
/**
|
|
63
|
+
* Convert the character indenx to the position
|
|
64
|
+
*
|
|
49
65
|
* 将字符位置转换为行列号
|
|
50
|
-
* @param index 字符位置
|
|
66
|
+
* @param index character index / 字符位置
|
|
51
67
|
*/
|
|
52
68
|
posFromIndex(index: number): Position | undefined;
|
|
53
69
|
/**
|
|
70
|
+
* Get the relative character index of the current node, or its `j`-th child node
|
|
71
|
+
*
|
|
54
72
|
* 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
|
|
55
|
-
* @param j 子节点序号
|
|
73
|
+
* @param j rank of the child node / 子节点序号
|
|
56
74
|
*/
|
|
57
75
|
getRelativeIndex(j?: number): number;
|
|
58
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Get the absolute character index of the current node
|
|
78
|
+
*
|
|
79
|
+
* 获取当前节点的绝对位置
|
|
80
|
+
*/
|
|
59
81
|
getAbsoluteIndex(): number;
|
|
60
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Get the position and dimension of the current node
|
|
84
|
+
*
|
|
85
|
+
* 获取当前节点的行列位置和大小
|
|
86
|
+
*/
|
|
61
87
|
getBoundingClientRect(): Dimension & Position;
|
|
62
88
|
/**
|
|
89
|
+
* Whether to be of a certain type
|
|
90
|
+
*
|
|
63
91
|
* 是否是某种类型的节点
|
|
64
|
-
* @param type 节点类型
|
|
92
|
+
* @param type token type / 节点类型
|
|
93
|
+
*/
|
|
94
|
+
is<T extends Token>(type: TokenTypes): this is T;
|
|
95
|
+
/**
|
|
96
|
+
* Get the text and the start/end positions of all lines
|
|
97
|
+
*
|
|
98
|
+
* 获取所有行的wikitext和起止位置
|
|
65
99
|
*/
|
|
66
|
-
is<T extends Token>(type: string): this is T;
|
|
67
|
-
/** 获取所有行的wikitext和起止位置 */
|
|
68
100
|
getLines(): [string, number, number][];
|
|
69
101
|
}
|
package/dist/lib/node.js
CHANGED
|
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AstNode = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-base-to-string */
|
|
5
5
|
const lint_1 = require("../util/lint");
|
|
6
|
+
const debug_1 = require("../util/debug");
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Node-like
|
|
9
|
+
*
|
|
10
|
+
* 类似Node
|
|
10
11
|
*/
|
|
11
|
-
const getIndex = (j, parent) => parent.childNodes.slice(0, j).reduce((acc, cur, i) => acc + cur.toString().length + parent.getGaps(i), 0)
|
|
12
|
-
+ parent.getAttribute('padding');
|
|
13
|
-
/** 类似Node */
|
|
14
12
|
class AstNode {
|
|
15
13
|
childNodes = [];
|
|
16
14
|
#parentNode;
|
|
@@ -19,35 +17,41 @@ class AstNode {
|
|
|
19
17
|
#lines;
|
|
20
18
|
#root;
|
|
21
19
|
#aIndex;
|
|
22
|
-
|
|
20
|
+
#rIndex = {};
|
|
21
|
+
/** first child node / 首位子节点 */
|
|
23
22
|
get firstChild() {
|
|
24
23
|
return this.childNodes[0];
|
|
25
24
|
}
|
|
26
|
-
/** 末位子节点 */
|
|
25
|
+
/** last child node / 末位子节点 */
|
|
27
26
|
get lastChild() {
|
|
28
27
|
return this.childNodes[this.childNodes.length - 1];
|
|
29
28
|
}
|
|
30
|
-
/** 父节点 */
|
|
29
|
+
/** parent node / 父节点 */
|
|
31
30
|
get parentNode() {
|
|
32
31
|
return this.#parentNode;
|
|
33
32
|
}
|
|
34
|
-
/** 后一个兄弟节点 */
|
|
33
|
+
/** next sibling node / 后一个兄弟节点 */
|
|
35
34
|
get nextSibling() {
|
|
36
35
|
return this.#nextSibling;
|
|
37
36
|
}
|
|
38
|
-
/** 前一个兄弟节点 */
|
|
37
|
+
/** previous sibling node / 前一个兄弟节点 */
|
|
39
38
|
get previousSibling() {
|
|
40
39
|
return this.#previousSibling;
|
|
41
40
|
}
|
|
42
|
-
/** 行数 */
|
|
41
|
+
/** number of lines / 行数 */
|
|
43
42
|
get offsetHeight() {
|
|
44
43
|
return this.#getDimension().height;
|
|
45
44
|
}
|
|
46
|
-
/** 最后一行的列数 */
|
|
45
|
+
/** number of columns of the last line / 最后一行的列数 */
|
|
47
46
|
get offsetWidth() {
|
|
48
47
|
return this.#getDimension().width;
|
|
49
48
|
}
|
|
50
49
|
/** @private */
|
|
50
|
+
getChildNodes() {
|
|
51
|
+
const { childNodes } = this;
|
|
52
|
+
return Object.isFrozen(childNodes) ? [...childNodes] : childNodes;
|
|
53
|
+
}
|
|
54
|
+
/** @private */
|
|
51
55
|
getAttribute(key) {
|
|
52
56
|
return (key === 'padding' ? 0 : this[key]);
|
|
53
57
|
}
|
|
@@ -67,38 +71,51 @@ class AstNode {
|
|
|
67
71
|
case 'previousSibling':
|
|
68
72
|
this.#previousSibling = value;
|
|
69
73
|
break;
|
|
74
|
+
case 'aIndex':
|
|
75
|
+
this.#aIndex = [debug_1.Shadow.rev, value];
|
|
76
|
+
break;
|
|
70
77
|
default:
|
|
71
78
|
this[key] = value; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Get the root node
|
|
83
|
+
*
|
|
84
|
+
* 获取根节点
|
|
85
|
+
*/
|
|
75
86
|
getRootNode() {
|
|
76
87
|
return (0, lint_1.cache)(this.#root, () => this.parentNode?.getRootNode() ?? this, value => {
|
|
77
88
|
const [, root] = value;
|
|
78
|
-
if (root.type === 'root'
|
|
89
|
+
if (root.type === 'root') {
|
|
79
90
|
this.#root = value;
|
|
80
91
|
}
|
|
81
92
|
});
|
|
82
93
|
}
|
|
83
94
|
/**
|
|
95
|
+
* Convert the position to the character index
|
|
96
|
+
*
|
|
84
97
|
* 将行列号转换为字符位置
|
|
85
|
-
* @param top 行号
|
|
86
|
-
* @param left 列号
|
|
98
|
+
* @param top line number / 行号
|
|
99
|
+
* @param left column number / 列号
|
|
87
100
|
*/
|
|
88
101
|
indexFromPos(top, left) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
LSP: { // eslint-disable-line no-unused-labels
|
|
103
|
+
if (top < 0 || left < 0) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const lines = this.getLines();
|
|
107
|
+
if (top >= lines.length) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const [, start, end] = lines[top], index = start + left;
|
|
111
|
+
return index > end ? undefined : index;
|
|
95
112
|
}
|
|
96
|
-
const [, start, end] = lines[top], index = start + left;
|
|
97
|
-
return index > end ? undefined : index;
|
|
98
113
|
}
|
|
99
114
|
/**
|
|
115
|
+
* Convert the character indenx to the position
|
|
116
|
+
*
|
|
100
117
|
* 将字符位置转换为行列号
|
|
101
|
-
* @param index 字符位置
|
|
118
|
+
* @param index character index / 字符位置
|
|
102
119
|
*/
|
|
103
120
|
posFromIndex(index) {
|
|
104
121
|
const { length } = String(this);
|
|
@@ -119,17 +136,35 @@ class AstNode {
|
|
|
119
136
|
return 0;
|
|
120
137
|
}
|
|
121
138
|
/**
|
|
139
|
+
* Get the relative character index of the current node, or its `j`-th child node
|
|
140
|
+
*
|
|
122
141
|
* 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
|
|
123
|
-
* @param j 子节点序号
|
|
142
|
+
* @param j rank of the child node / 子节点序号
|
|
124
143
|
*/
|
|
125
144
|
getRelativeIndex(j) {
|
|
126
145
|
if (j === undefined) {
|
|
127
146
|
const { parentNode } = this;
|
|
128
|
-
return parentNode
|
|
147
|
+
return parentNode
|
|
148
|
+
? parentNode.getRelativeIndex(parentNode.childNodes.indexOf(this))
|
|
149
|
+
: 0;
|
|
129
150
|
}
|
|
130
|
-
return
|
|
151
|
+
return (0, lint_1.cache)(this.#rIndex[j], () => {
|
|
152
|
+
const { childNodes } = this, n = j + (j < 0 ? childNodes.length : 0);
|
|
153
|
+
let acc = this.getAttribute('padding');
|
|
154
|
+
for (let i = 0; i < n; i++) {
|
|
155
|
+
this.#rIndex[i] = [debug_1.Shadow.rev, acc];
|
|
156
|
+
acc += childNodes[i].toString().length + this.getGaps(i);
|
|
157
|
+
}
|
|
158
|
+
return acc;
|
|
159
|
+
}, value => {
|
|
160
|
+
this.#rIndex[j] = value;
|
|
161
|
+
});
|
|
131
162
|
}
|
|
132
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Get the absolute character index of the current node
|
|
165
|
+
*
|
|
166
|
+
* 获取当前节点的绝对位置
|
|
167
|
+
*/
|
|
133
168
|
getAbsoluteIndex() {
|
|
134
169
|
return (0, lint_1.cache)(this.#aIndex, () => {
|
|
135
170
|
const { parentNode } = this;
|
|
@@ -138,9 +173,14 @@ class AstNode {
|
|
|
138
173
|
this.#aIndex = value;
|
|
139
174
|
});
|
|
140
175
|
}
|
|
141
|
-
/**
|
|
176
|
+
/**
|
|
177
|
+
* Get the position and dimension of the current node
|
|
178
|
+
*
|
|
179
|
+
* 获取当前节点的行列位置和大小
|
|
180
|
+
*/
|
|
142
181
|
getBoundingClientRect() {
|
|
143
|
-
|
|
182
|
+
// eslint-disable-next-line no-unused-labels
|
|
183
|
+
LSP: return { ...this.#getDimension(), ...this.getRootNode().posFromIndex(this.getAbsoluteIndex()) };
|
|
144
184
|
}
|
|
145
185
|
/** @private */
|
|
146
186
|
seal(key, permanent) {
|
|
@@ -150,13 +190,19 @@ class AstNode {
|
|
|
150
190
|
});
|
|
151
191
|
}
|
|
152
192
|
/**
|
|
193
|
+
* Whether to be of a certain type
|
|
194
|
+
*
|
|
153
195
|
* 是否是某种类型的节点
|
|
154
|
-
* @param type 节点类型
|
|
196
|
+
* @param type token type / 节点类型
|
|
155
197
|
*/
|
|
156
198
|
is(type) {
|
|
157
199
|
return this.type === type;
|
|
158
200
|
}
|
|
159
|
-
/**
|
|
201
|
+
/**
|
|
202
|
+
* Get the text and the start/end positions of all lines
|
|
203
|
+
*
|
|
204
|
+
* 获取所有行的wikitext和起止位置
|
|
205
|
+
*/
|
|
160
206
|
getLines() {
|
|
161
207
|
return (0, lint_1.cache)(this.#lines, () => {
|
|
162
208
|
const results = [];
|
package/dist/lib/text.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { AstNode } from './node';
|
|
2
2
|
import type { LintError } from '../base';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* text node
|
|
5
|
+
*
|
|
6
|
+
* 文本节点
|
|
7
|
+
*/
|
|
4
8
|
export declare class AstText extends AstNode {
|
|
5
9
|
#private;
|
|
6
10
|
readonly name: undefined;
|
|
@@ -9,8 +13,10 @@ export declare class AstText extends AstNode {
|
|
|
9
13
|
/** @param text 包含文本 */
|
|
10
14
|
constructor(text: string);
|
|
11
15
|
/**
|
|
16
|
+
* Replace the text
|
|
17
|
+
*
|
|
12
18
|
* 替换字符串
|
|
13
|
-
* @param text 替换的字符串
|
|
19
|
+
* @param text new text / 替换的字符串
|
|
14
20
|
*/
|
|
15
21
|
replaceData(text: string): void;
|
|
16
22
|
}
|
package/dist/lib/text.js
CHANGED
|
@@ -57,7 +57,11 @@ try {
|
|
|
57
57
|
catch /* istanbul ignore next */ {
|
|
58
58
|
wordRegex = /\w/u;
|
|
59
59
|
}
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* text node
|
|
62
|
+
*
|
|
63
|
+
* 文本节点
|
|
64
|
+
*/
|
|
61
65
|
class AstText extends node_1.AstNode {
|
|
62
66
|
data = '';
|
|
63
67
|
get type() {
|
|
@@ -134,7 +138,8 @@ class AstText extends node_1.AstNode {
|
|
|
134
138
|
const { 0: char, length } = error, magicLink = char === 'r' || char === 'p' || char === 'i';
|
|
135
139
|
if (char === '<' && !tags.has(tag.toLowerCase())
|
|
136
140
|
|| char === '[' && type === 'ext-link-text' && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
137
|
-
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
141
|
+
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
142
|
+
&& nextSibling.innerText?.includes(']'))
|
|
138
143
|
|| magicLink && (!parentNode.getAttribute('plain') || noLinkTypes.has(type))) {
|
|
139
144
|
continue;
|
|
140
145
|
}
|
|
@@ -221,8 +226,10 @@ class AstText extends node_1.AstNode {
|
|
|
221
226
|
this.setAttribute('data', text);
|
|
222
227
|
}
|
|
223
228
|
/**
|
|
229
|
+
* Replace the text
|
|
230
|
+
*
|
|
224
231
|
* 替换字符串
|
|
225
|
-
* @param text 替换的字符串
|
|
232
|
+
* @param text new text / 替换的字符串
|
|
226
233
|
*/
|
|
227
234
|
replaceData(text) {
|
|
228
235
|
this.#setData(text);
|
package/dist/lib/title.d.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import type { Config } from '../base';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* title object of a MediaWiki page
|
|
4
|
+
*
|
|
5
|
+
* MediaWiki页面标题对象
|
|
6
|
+
*/
|
|
3
7
|
export declare class Title {
|
|
4
8
|
#private;
|
|
5
|
-
interwiki: string;
|
|
6
9
|
readonly valid: boolean;
|
|
7
|
-
/** 命名空间 */
|
|
10
|
+
/** namespace number / 命名空间 */
|
|
8
11
|
get ns(): number;
|
|
9
12
|
/** 片段标识符 */
|
|
10
13
|
get fragment(): string | undefined;
|
|
11
|
-
/** 不含命名空间的标题主体部分 */
|
|
14
|
+
/** main part without the namespace / 不含命名空间的标题主体部分 */
|
|
12
15
|
get main(): string;
|
|
13
16
|
set main(title: string);
|
|
14
|
-
/** 命名空间前缀 */
|
|
17
|
+
/** namespace prefix / 命名空间前缀 */
|
|
15
18
|
get prefix(): string;
|
|
16
|
-
/** 完整标题 */
|
|
19
|
+
/** full title / 完整标题 */
|
|
17
20
|
get title(): string;
|
|
18
|
-
/** 扩展名 */
|
|
21
|
+
/** file extension / 扩展名 */
|
|
19
22
|
get extension(): string | undefined;
|
|
20
23
|
/**
|
|
21
24
|
* @see MediaWikiTitleCodec::splitTitleString
|
|
@@ -25,7 +28,18 @@ export declare class Title {
|
|
|
25
28
|
* @param decode 是否需要解码
|
|
26
29
|
* @param selfLink 是否允许selfLink
|
|
27
30
|
*/
|
|
28
|
-
constructor(title: string, defaultNs: number, config: Config, decode: boolean, selfLink: boolean);
|
|
29
|
-
/**
|
|
31
|
+
constructor(title: string, defaultNs: number, config: Config, temporary: boolean, decode: boolean, selfLink: boolean);
|
|
32
|
+
/**
|
|
33
|
+
* Check if the title is a redirect
|
|
34
|
+
*
|
|
35
|
+
* 检测是否是重定向
|
|
36
|
+
*/
|
|
30
37
|
getRedirection(): [boolean, string];
|
|
38
|
+
/**
|
|
39
|
+
* Get the URL of the title
|
|
40
|
+
*
|
|
41
|
+
* 生成URL
|
|
42
|
+
* @param articlePath article path / 条目路径
|
|
43
|
+
*/
|
|
44
|
+
getUrl(articlePath?: string): string;
|
|
31
45
|
}
|
package/dist/lib/title.js
CHANGED
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Title = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* title object of a MediaWiki page
|
|
7
|
+
*
|
|
8
|
+
* MediaWiki页面标题对象
|
|
9
|
+
*/
|
|
6
10
|
class Title {
|
|
7
11
|
#main;
|
|
8
12
|
#namespaces;
|
|
13
|
+
#path;
|
|
9
14
|
#ns;
|
|
10
15
|
#fragment;
|
|
11
|
-
interwiki = '';
|
|
12
16
|
valid;
|
|
13
17
|
/** @private */
|
|
14
18
|
encoded = false;
|
|
15
|
-
/** 命名空间 */
|
|
19
|
+
/** namespace number / 命名空间 */
|
|
16
20
|
get ns() {
|
|
17
21
|
return this.#ns;
|
|
18
22
|
}
|
|
@@ -20,7 +24,7 @@ class Title {
|
|
|
20
24
|
get fragment() {
|
|
21
25
|
return this.#fragment;
|
|
22
26
|
}
|
|
23
|
-
/** 不含命名空间的标题主体部分 */
|
|
27
|
+
/** main part without the namespace / 不含命名空间的标题主体部分 */
|
|
24
28
|
get main() {
|
|
25
29
|
return this.#main;
|
|
26
30
|
}
|
|
@@ -28,16 +32,16 @@ class Title {
|
|
|
28
32
|
title = title.replace(/_/gu, ' ').trim();
|
|
29
33
|
this.#main = title && title[0].toUpperCase() + title.slice(1);
|
|
30
34
|
}
|
|
31
|
-
/** 命名空间前缀 */
|
|
35
|
+
/** namespace prefix / 命名空间前缀 */
|
|
32
36
|
get prefix() {
|
|
33
37
|
const namespace = this.#namespaces[this.ns];
|
|
34
38
|
return namespace + (namespace && ':');
|
|
35
39
|
}
|
|
36
|
-
/** 完整标题 */
|
|
40
|
+
/** full title / 完整标题 */
|
|
37
41
|
get title() {
|
|
38
42
|
return this.getRedirection()[1];
|
|
39
43
|
}
|
|
40
|
-
/** 扩展名 */
|
|
44
|
+
/** file extension / 扩展名 */
|
|
41
45
|
get extension() {
|
|
42
46
|
const { main } = this, i = main.lastIndexOf('.');
|
|
43
47
|
return i === -1 ? undefined : main.slice(i + 1).toLowerCase();
|
|
@@ -50,7 +54,7 @@ class Title {
|
|
|
50
54
|
* @param decode 是否需要解码
|
|
51
55
|
* @param selfLink 是否允许selfLink
|
|
52
56
|
*/
|
|
53
|
-
constructor(title, defaultNs, config, decode, selfLink) {
|
|
57
|
+
constructor(title, defaultNs, config, temporary, decode, selfLink) {
|
|
54
58
|
const subpage = title.trim().startsWith('../');
|
|
55
59
|
if (decode && title.includes('%')) {
|
|
56
60
|
try {
|
|
@@ -92,25 +96,30 @@ class Title {
|
|
|
92
96
|
this.#fragment = fragment.replace(/ /gu, '_');
|
|
93
97
|
title = title.slice(0, i).trim();
|
|
94
98
|
}
|
|
95
|
-
this.valid = Boolean(title
|
|
99
|
+
this.valid = Boolean(title
|
|
100
|
+
|| selfLink && this.ns === 0 && this.#fragment !== undefined)
|
|
96
101
|
&& (0, string_1.decodeHtml)(title) === title
|
|
97
102
|
&& !/^:|\0\d+[eh!+-]\x7F|[<>[\]{}|\n]|%[\da-f]{2}|(?:^|\/)\.{1,2}(?:$|\/)/iu.test(subpage ? /^(?:\.\.\/)+(.*)/u.exec(title)[1] : title);
|
|
98
103
|
this.main = title;
|
|
99
|
-
Object.defineProperties(this, {
|
|
100
|
-
encoded: { enumerable: false, writable: false },
|
|
101
|
-
});
|
|
102
104
|
this.#namespaces = config.namespaces;
|
|
105
|
+
this.#path = config.articlePath || '/wiki/$1';
|
|
106
|
+
if (!this.#path.includes('$1')) {
|
|
107
|
+
this.#path += `${this.#path.endsWith('/') ? '' : '/'}$1`;
|
|
108
|
+
}
|
|
109
|
+
if (!temporary) {
|
|
110
|
+
Object.defineProperties(this, {
|
|
111
|
+
encoded: { enumerable: false, writable: false },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
103
114
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
: `#${this.#fragment}`);
|
|
110
|
-
}
|
|
111
|
-
/** 检测是否是重定向 */
|
|
115
|
+
/**
|
|
116
|
+
* Check if the title is a redirect
|
|
117
|
+
*
|
|
118
|
+
* 检测是否是重定向
|
|
119
|
+
*/
|
|
112
120
|
getRedirection() {
|
|
113
|
-
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/prefer-destructuring
|
|
122
|
+
const prefix = this.prefix;
|
|
114
123
|
// eslint-disable-next-line prefer-const
|
|
115
124
|
let title = (prefix + this.main).replace(/ /gu, '_');
|
|
116
125
|
return [false, title];
|
|
@@ -119,5 +128,31 @@ class Title {
|
|
|
119
128
|
setFragment(fragment) {
|
|
120
129
|
this.#fragment = fragment;
|
|
121
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the URL of the title
|
|
133
|
+
*
|
|
134
|
+
* 生成URL
|
|
135
|
+
* @param articlePath article path / 条目路径
|
|
136
|
+
*/
|
|
137
|
+
getUrl(articlePath) {
|
|
138
|
+
LSP: { // eslint-disable-line no-unused-labels
|
|
139
|
+
if (typeof articlePath === 'string') {
|
|
140
|
+
this.#path = articlePath || '/wiki/$1';
|
|
141
|
+
if (!this.#path.includes('$1')) {
|
|
142
|
+
this.#path += `${this.#path.endsWith('/') ? '' : '/'}$1`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const { title, fragment } = this;
|
|
146
|
+
if (title) {
|
|
147
|
+
return this.#path.replace('$1', encodeURIComponent(title)
|
|
148
|
+
+ (fragment === undefined
|
|
149
|
+
? ''
|
|
150
|
+
: `#${encodeURIComponent(
|
|
151
|
+
// eslint-disable-next-line @stylistic/comma-dangle
|
|
152
|
+
fragment)}`));
|
|
153
|
+
}
|
|
154
|
+
return fragment === undefined ? '' : `#${encodeURIComponent(fragment)}`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
122
157
|
}
|
|
123
158
|
exports.Title = Title;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export interface AttributesParentBase {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Get the attribute
|
|
4
|
+
*
|
|
5
|
+
* 获取指定属性
|
|
6
|
+
* @param key attribute name / 属性键
|
|
5
7
|
*/
|
|
6
8
|
getAttr(key: string): string | true | undefined;
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
11
|
* 子节点含有AttributesToken的类
|
|
10
12
|
* @param i AttributesToken子节点的位置
|
|
11
|
-
* @param constructor 基类
|
|
12
|
-
* @param _ context
|
|
13
13
|
*/
|
|
@@ -5,19 +5,17 @@ const debug_1 = require("../util/debug");
|
|
|
5
5
|
/**
|
|
6
6
|
* 子节点含有AttributesToken的类
|
|
7
7
|
* @param i AttributesToken子节点的位置
|
|
8
|
-
* @param constructor 基类
|
|
9
|
-
* @param _ context
|
|
10
8
|
*/
|
|
11
9
|
const attributesParent = (i = 0) => (constructor, _) => {
|
|
12
10
|
/** 子节点含有AttributesToken的类 */
|
|
13
11
|
class AttributesParent extends constructor {
|
|
14
12
|
/** AttributesToken子节点 */
|
|
15
|
-
|
|
13
|
+
#getAttributesChild() {
|
|
16
14
|
return this.childNodes[i];
|
|
17
15
|
}
|
|
18
16
|
/** @implements */
|
|
19
17
|
getAttr(key) {
|
|
20
|
-
return this.#
|
|
18
|
+
return this.#getAttributesChild().getAttr(key);
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
(0, debug_1.mixin)(AttributesParent, constructor);
|
package/dist/mixin/hidden.d.ts
CHANGED
package/dist/mixin/hidden.js
CHANGED
|
@@ -6,8 +6,6 @@ const debug_1 = require("../util/debug");
|
|
|
6
6
|
* 解析后不可见的类
|
|
7
7
|
* @param linter 是否覆写 lint 方法
|
|
8
8
|
* @param html 是否覆写 toHtml 方法
|
|
9
|
-
* @param constructor 基类
|
|
10
|
-
* @param _ context
|
|
11
9
|
*/
|
|
12
10
|
const hiddenToken = (linter = true, html = true) => (constructor, _) => {
|
|
13
11
|
/** 解析后不可见的类 */
|
package/dist/parser/braces.js
CHANGED
|
@@ -30,7 +30,8 @@ const parseBraces = (wikitext, config, accum) => {
|
|
|
30
30
|
let moreBraces = lastBraces + wikitext.length !== -1;
|
|
31
31
|
let regex = new RegExp(source + (moreBraces ? openBraces : ''), 'gmu'), mt = regex.exec(wikitext), lastIndex;
|
|
32
32
|
while (mt
|
|
33
|
-
|| lastIndex !== undefined && lastIndex <= wikitext.length
|
|
33
|
+
|| lastIndex !== undefined && lastIndex <= wikitext.length
|
|
34
|
+
&& stack[stack.length - 1]?.[0]?.startsWith('=')) {
|
|
34
35
|
if (mt?.[1]) {
|
|
35
36
|
const [, { length }] = mt;
|
|
36
37
|
mt[0] = mt[0].slice(length);
|
|
@@ -80,7 +81,8 @@ const parseBraces = (wikitext, config, accum) => {
|
|
|
80
81
|
const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
|
|
81
82
|
// @ts-expect-error abstract class
|
|
82
83
|
new arg_1.ArgToken(argParts, config, accum);
|
|
83
|
-
if (str && str.endsWith(':')
|
|
84
|
+
if (str && str.endsWith(':')
|
|
85
|
+
&& subst.includes(str.slice(0, -1).toLowerCase())) {
|
|
84
86
|
ch = 's';
|
|
85
87
|
}
|
|
86
88
|
}
|