wikiparser-node 1.16.4 → 1.16.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/README.md +1 -1
- package/bundle/bundle.es7.js +27 -27
- package/bundle/bundle.lsp.js +30 -30
- package/bundle/bundle.min.js +29 -29
- package/dist/addon/table.js +7 -4
- package/dist/addon/token.js +13 -7
- package/dist/addon/transclude.js +7 -5
- package/dist/base.d.mts +99 -30
- package/dist/base.d.ts +99 -30
- package/dist/index.d.ts +10 -4
- package/dist/index.js +59 -14
- package/dist/lib/attributes.js +2 -2
- package/dist/lib/element.d.ts +96 -42
- package/dist/lib/element.js +98 -45
- package/dist/lib/lsp.d.ts +64 -35
- package/dist/lib/lsp.js +208 -159
- package/dist/lib/node.d.ts +122 -53
- package/dist/lib/node.js +172 -75
- package/dist/lib/range.d.ts +83 -31
- package/dist/lib/range.js +83 -31
- package/dist/lib/ranges.d.ts +1 -1
- package/dist/lib/ranges.js +3 -2
- package/dist/lib/text.d.ts +40 -14
- package/dist/lib/text.js +47 -19
- package/dist/lib/title.d.ts +50 -16
- package/dist/lib/title.js +77 -36
- package/dist/mixin/attributesParent.d.ts +37 -21
- package/dist/mixin/attributesParent.js +0 -2
- package/dist/mixin/flagsParent.d.ts +38 -12
- package/dist/mixin/hidden.d.ts +0 -2
- package/dist/mixin/hidden.js +0 -2
- package/dist/mixin/magicLinkParent.d.ts +11 -5
- package/dist/mixin/singleLine.d.ts +0 -2
- package/dist/mixin/singleLine.js +3 -3
- package/dist/mixin/sol.d.ts +0 -2
- package/dist/mixin/sol.js +2 -3
- package/dist/mixin/syntax.d.ts +0 -2
- package/dist/mixin/syntax.js +0 -2
- package/dist/parser/braces.js +52 -20
- package/dist/parser/commentAndExt.js +19 -6
- package/dist/parser/links.js +13 -7
- package/dist/parser/list.js +3 -1
- package/dist/parser/quotes.js +22 -2
- package/dist/parser/redirect.js +4 -1
- package/dist/src/arg.d.ts +19 -9
- package/dist/src/arg.js +34 -15
- package/dist/src/atom.d.ts +5 -1
- package/dist/src/atom.js +5 -1
- package/dist/src/attribute.d.ts +26 -8
- package/dist/src/attribute.js +30 -11
- package/dist/src/attributes.d.ts +50 -22
- package/dist/src/attributes.js +54 -26
- package/dist/src/converter.d.ts +4 -2
- package/dist/src/converter.js +12 -9
- package/dist/src/converterFlags.d.ts +45 -15
- package/dist/src/converterFlags.js +45 -15
- package/dist/src/converterRule.d.ts +30 -11
- package/dist/src/converterRule.js +46 -16
- package/dist/src/extLink.d.ts +6 -2
- package/dist/src/extLink.js +14 -11
- package/dist/src/gallery.d.ts +13 -9
- package/dist/src/gallery.js +35 -21
- package/dist/src/heading.d.ts +13 -7
- package/dist/src/heading.js +21 -11
- package/dist/src/hidden.d.ts +5 -1
- package/dist/src/hidden.js +7 -3
- package/dist/src/html.d.ts +11 -5
- package/dist/src/html.js +16 -7
- package/dist/src/imageParameter.d.ts +23 -11
- package/dist/src/imageParameter.js +22 -10
- package/dist/src/imagemap.d.ts +4 -4
- package/dist/src/imagemap.js +9 -5
- package/dist/src/imagemapLink.d.ts +3 -1
- package/dist/src/imagemapLink.js +3 -1
- package/dist/src/index.d.ts +65 -20
- package/dist/src/index.js +111 -39
- package/dist/src/link/base.d.ts +14 -6
- package/dist/src/link/base.js +40 -17
- package/dist/src/link/category.d.ts +7 -2
- package/dist/src/link/category.js +20 -4
- package/dist/src/link/file.d.ts +71 -23
- package/dist/src/link/file.js +100 -36
- package/dist/src/link/galleryImage.d.ts +8 -4
- package/dist/src/link/galleryImage.js +15 -8
- package/dist/src/link/index.d.ts +12 -4
- package/dist/src/link/index.js +15 -5
- package/dist/src/link/redirectTarget.d.ts +3 -2
- package/dist/src/link/redirectTarget.js +5 -3
- package/dist/src/magicLink.d.ts +24 -11
- package/dist/src/magicLink.js +36 -19
- package/dist/src/nested.d.ts +5 -3
- package/dist/src/nested.js +9 -6
- package/dist/src/nowiki/base.d.ts +4 -2
- package/dist/src/nowiki/base.js +6 -5
- package/dist/src/nowiki/comment.d.ts +6 -2
- package/dist/src/nowiki/comment.js +8 -3
- package/dist/src/nowiki/dd.d.ts +0 -3
- package/dist/src/nowiki/dd.js +0 -8
- 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/listBase.d.ts +15 -5
- package/dist/src/nowiki/listBase.js +40 -9
- package/dist/src/nowiki/noinclude.d.ts +5 -1
- package/dist/src/nowiki/noinclude.js +5 -1
- package/dist/src/nowiki/quote.d.ts +15 -8
- package/dist/src/nowiki/quote.js +32 -12
- package/dist/src/onlyinclude.d.ts +4 -2
- package/dist/src/onlyinclude.js +4 -2
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +1 -1
- package/dist/src/parameter.d.ts +24 -12
- package/dist/src/parameter.js +45 -27
- 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.d.ts +5 -1
- package/dist/src/table/base.js +10 -3
- package/dist/src/table/index.d.ts +134 -66
- package/dist/src/table/index.js +150 -81
- package/dist/src/table/td.d.ts +18 -10
- package/dist/src/table/td.js +25 -15
- package/dist/src/table/tr.d.ts +13 -3
- package/dist/src/table/tr.js +14 -6
- package/dist/src/table/trBase.d.ts +28 -12
- package/dist/src/table/trBase.js +28 -18
- package/dist/src/tagPair/ext.d.ts +3 -1
- package/dist/src/tagPair/ext.js +10 -8
- package/dist/src/tagPair/include.d.ts +8 -2
- package/dist/src/tagPair/include.js +8 -2
- package/dist/src/tagPair/index.d.ts +6 -2
- package/dist/src/tagPair/index.js +6 -2
- package/dist/src/transclude.d.ts +102 -33
- package/dist/src/transclude.js +114 -42
- package/dist/util/debug.js +2 -7
- package/dist/util/html.js +1 -18
- package/dist/util/string.js +7 -1
- package/extensions/dist/base.js +27 -16
- package/extensions/dist/codejar.js +2 -1
- package/extensions/dist/lsp.js +5 -10
- package/extensions/es7/base.js +27 -16
- package/extensions/ui.css +1 -162
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +3 -3
package/dist/lib/text.js
CHANGED
|
@@ -8,7 +8,6 @@ const node_1 = require("./node");
|
|
|
8
8
|
/* NOT FOR BROWSER */
|
|
9
9
|
const constants_1 = require("../util/constants");
|
|
10
10
|
const debug_1 = require("../util/debug");
|
|
11
|
-
const html_1 = require("../util/html");
|
|
12
11
|
/* NOT FOR BROWSER END */
|
|
13
12
|
const sp = String.raw `[${string_1.zs}\t]*`, source = String.raw `<\s*(?:/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|(?:rfc|pmid)(?=[-::]?${sp}\d)|isbn(?=[-::]?${sp}(?:\d(?:${sp}|-)){6})`;
|
|
14
13
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, es-x/no-regexp-unicode-property-escapes
|
|
@@ -91,14 +90,18 @@ try {
|
|
|
91
90
|
catch /* istanbul ignore next */ {
|
|
92
91
|
wordRegex = /\w/u;
|
|
93
92
|
}
|
|
94
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* text node
|
|
95
|
+
*
|
|
96
|
+
* 文本节点
|
|
97
|
+
*/
|
|
95
98
|
class AstText extends node_1.AstNode {
|
|
96
99
|
data = '';
|
|
97
100
|
get type() {
|
|
98
101
|
return 'text';
|
|
99
102
|
}
|
|
100
103
|
/* NOT FOR BROWSER */
|
|
101
|
-
/** 文本长度 */
|
|
104
|
+
/** text length / 文本长度 */
|
|
102
105
|
get length() {
|
|
103
106
|
return this.data.length;
|
|
104
107
|
}
|
|
@@ -181,7 +184,8 @@ class AstText extends node_1.AstNode {
|
|
|
181
184
|
const { 0: char, length } = error, magicLink = char === 'r' || char === 'p' || char === 'i';
|
|
182
185
|
if (char === '<' && !tags.has(tag.toLowerCase())
|
|
183
186
|
|| char === '[' && type === 'ext-link-text' && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
184
|
-
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
187
|
+
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
188
|
+
&& nextSibling.innerText?.includes(']'))
|
|
185
189
|
|| magicLink && (!parentNode.getAttribute('plain') || noLinkTypes.has(type))) {
|
|
186
190
|
continue;
|
|
187
191
|
}
|
|
@@ -275,8 +279,10 @@ class AstText extends node_1.AstNode {
|
|
|
275
279
|
}
|
|
276
280
|
}
|
|
277
281
|
/**
|
|
282
|
+
* Replace the text
|
|
283
|
+
*
|
|
278
284
|
* 替换字符串
|
|
279
|
-
* @param text 替换的字符串
|
|
285
|
+
* @param text new text / 替换的字符串
|
|
280
286
|
*/
|
|
281
287
|
replaceData(text) {
|
|
282
288
|
this.#setData(text);
|
|
@@ -286,44 +292,59 @@ class AstText extends node_1.AstNode {
|
|
|
286
292
|
return (0, string_1.escape)(this.data);
|
|
287
293
|
}
|
|
288
294
|
/* NOT FOR BROWSER */
|
|
289
|
-
/**
|
|
295
|
+
/**
|
|
296
|
+
* Clone the node
|
|
297
|
+
*
|
|
298
|
+
* 复制
|
|
299
|
+
*/
|
|
290
300
|
cloneNode() {
|
|
291
301
|
return new AstText(this.data);
|
|
292
302
|
}
|
|
293
303
|
/**
|
|
304
|
+
* Insert text at the end
|
|
305
|
+
*
|
|
294
306
|
* 在后方添加字符串
|
|
295
|
-
* @param text 添加的字符串
|
|
307
|
+
* @param text text to be inserted / 添加的字符串
|
|
296
308
|
*/
|
|
297
309
|
appendData(text) {
|
|
298
310
|
this.#setData(this.data + text);
|
|
299
311
|
}
|
|
300
312
|
/**
|
|
313
|
+
* Delete text
|
|
314
|
+
*
|
|
301
315
|
* 删减字符串
|
|
302
|
-
* @param offset 起始位置
|
|
303
|
-
* @param count 删减字符数
|
|
316
|
+
* @param offset start position / 起始位置
|
|
317
|
+
* @param count number of characters to be deleted / 删减字符数
|
|
304
318
|
*/
|
|
305
319
|
deleteData(offset, count = Infinity) {
|
|
306
|
-
this.#setData(this.data.slice(0, offset)
|
|
320
|
+
this.#setData(this.data.slice(0, offset)
|
|
321
|
+
+ (offset < 0 && offset + count >= 0 ? '' : this.data.slice(offset + count)));
|
|
307
322
|
}
|
|
308
323
|
/**
|
|
324
|
+
* Insert text
|
|
325
|
+
*
|
|
309
326
|
* 插入字符串
|
|
310
|
-
* @param offset 插入位置
|
|
311
|
-
* @param text 待插入的字符串
|
|
327
|
+
* @param offset position to be inserted at / 插入位置
|
|
328
|
+
* @param text text to be inserted / 待插入的字符串
|
|
312
329
|
*/
|
|
313
330
|
insertData(offset, text) {
|
|
314
331
|
this.#setData(this.data.slice(0, offset) + text + this.data.slice(offset));
|
|
315
332
|
}
|
|
316
333
|
/**
|
|
334
|
+
* Get the substring
|
|
335
|
+
*
|
|
317
336
|
* 提取子串
|
|
318
|
-
* @param offset 起始位置
|
|
319
|
-
* @param count 字符数
|
|
337
|
+
* @param offset start position / 起始位置
|
|
338
|
+
* @param count number of characters / 字符数
|
|
320
339
|
*/
|
|
321
340
|
substringData(offset, count) {
|
|
322
341
|
return this.data.substr(offset, count);
|
|
323
342
|
}
|
|
324
343
|
/**
|
|
344
|
+
* Split the text node into two parts
|
|
345
|
+
*
|
|
325
346
|
* 将文本子节点分裂为两部分
|
|
326
|
-
* @param offset 分裂位置
|
|
347
|
+
* @param offset position to be splitted at / 分裂位置
|
|
327
348
|
* @throws `RangeError` 错误的断开位置
|
|
328
349
|
* @throws `Error` 没有父节点
|
|
329
350
|
*/
|
|
@@ -353,10 +374,15 @@ class AstText extends node_1.AstNode {
|
|
|
353
374
|
}
|
|
354
375
|
return j;
|
|
355
376
|
}
|
|
356
|
-
/**
|
|
377
|
+
/**
|
|
378
|
+
* Escape `=`
|
|
379
|
+
*
|
|
380
|
+
* 转义 `=`
|
|
381
|
+
*/
|
|
357
382
|
escape() {
|
|
358
383
|
const { TranscludeToken } = require('../src/transclude');
|
|
359
|
-
|
|
384
|
+
let i = this.data.lastIndexOf('=');
|
|
385
|
+
for (; i >= 0; i = this.data.lastIndexOf('=', i - 1)) {
|
|
360
386
|
if (i < this.length - 1) {
|
|
361
387
|
this.splitText(i + 1);
|
|
362
388
|
}
|
|
@@ -367,12 +393,14 @@ class AstText extends node_1.AstNode {
|
|
|
367
393
|
}
|
|
368
394
|
}
|
|
369
395
|
/**
|
|
396
|
+
* Generate HTML
|
|
397
|
+
*
|
|
370
398
|
* 生成HTML
|
|
371
|
-
* @param nowrap 是否不换行
|
|
399
|
+
* @param nowrap whether to disable line-wrapping / 是否不换行
|
|
372
400
|
*/
|
|
373
401
|
toHtml(nowrap) {
|
|
374
402
|
const { data } = this;
|
|
375
|
-
return (0,
|
|
403
|
+
return (0, string_1.sanitize)(nowrap ? data.replaceAll('\n', ' ') : data);
|
|
376
404
|
}
|
|
377
405
|
/** @private */
|
|
378
406
|
removeBlankLines() {
|
package/dist/lib/title.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
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
|
+
interwiki: string;
|
|
11
|
+
/** namespace number / 命名空间 */
|
|
8
12
|
get ns(): number;
|
|
9
13
|
/** 片段标识符 */
|
|
10
14
|
get fragment(): string | undefined;
|
|
11
|
-
/** 不含命名空间的标题主体部分 */
|
|
15
|
+
/** main part without the namespace / 不含命名空间的标题主体部分 */
|
|
12
16
|
get main(): string;
|
|
13
17
|
set main(title: string);
|
|
14
|
-
/** 命名空间前缀 */
|
|
18
|
+
/** namespace prefix / 命名空间前缀 */
|
|
15
19
|
get prefix(): string;
|
|
16
|
-
/** 完整标题 */
|
|
20
|
+
/** full title / 完整标题 */
|
|
17
21
|
get title(): string;
|
|
18
|
-
/** 扩展名 */
|
|
22
|
+
/** file extension / 扩展名 */
|
|
19
23
|
get extension(): string | undefined;
|
|
20
24
|
set extension(extension: string | undefined);
|
|
21
25
|
/** @throws `RangeError` undefined namespace */
|
|
@@ -29,24 +33,54 @@ export declare class Title {
|
|
|
29
33
|
* @param decode 是否需要解码
|
|
30
34
|
* @param selfLink 是否允许selfLink
|
|
31
35
|
*/
|
|
32
|
-
constructor(title: string, defaultNs: number, config: Config, decode: boolean, selfLink: boolean);
|
|
33
|
-
/**
|
|
36
|
+
constructor(title: string, defaultNs: number, config: Config, temporary: boolean, decode: boolean, selfLink: boolean);
|
|
37
|
+
/**
|
|
38
|
+
* Check if the title is a redirect
|
|
39
|
+
*
|
|
40
|
+
* 检测是否是重定向
|
|
41
|
+
*/
|
|
34
42
|
getRedirection(): [boolean, string];
|
|
35
43
|
/**
|
|
44
|
+
* Get the URL of the title
|
|
45
|
+
*
|
|
36
46
|
* 生成URL
|
|
37
|
-
* @param articlePath 条目路径
|
|
47
|
+
* @param articlePath article path / 条目路径
|
|
38
48
|
*/
|
|
39
49
|
getUrl(articlePath?: string): string;
|
|
40
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Perform unidirectional language conversion
|
|
52
|
+
*
|
|
53
|
+
* 执行单向转换
|
|
54
|
+
*/
|
|
41
55
|
autoConvert(): void;
|
|
42
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Get the title of its subject page
|
|
58
|
+
*
|
|
59
|
+
* 转换为主页面
|
|
60
|
+
*/
|
|
43
61
|
toSubjectPage(): void;
|
|
44
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Get the title of its talk page
|
|
64
|
+
*
|
|
65
|
+
* 转换为讨论页面
|
|
66
|
+
*/
|
|
45
67
|
toTalkPage(): void;
|
|
46
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Check if the title is a talk page
|
|
70
|
+
*
|
|
71
|
+
* 是否是讨论页
|
|
72
|
+
*/
|
|
47
73
|
isTalkPage(): boolean;
|
|
48
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Get the title of its base page
|
|
76
|
+
*
|
|
77
|
+
* 转换为上一级页面
|
|
78
|
+
*/
|
|
49
79
|
toBasePage(): void;
|
|
50
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Get the title of its root page
|
|
82
|
+
*
|
|
83
|
+
* 转换为根页面
|
|
84
|
+
*/
|
|
51
85
|
toRootPage(): void;
|
|
52
86
|
}
|
package/dist/lib/title.js
CHANGED
|
@@ -6,25 +6,29 @@ const string_1 = require("../util/string");
|
|
|
6
6
|
const constants_1 = require("../util/constants");
|
|
7
7
|
const index_1 = require("../index");
|
|
8
8
|
/* NOT FOR BROWSER END */
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* title object of a MediaWiki page
|
|
11
|
+
*
|
|
12
|
+
* MediaWiki页面标题对象
|
|
13
|
+
*/
|
|
10
14
|
class Title {
|
|
11
15
|
#main;
|
|
12
16
|
#namespaces;
|
|
13
17
|
#path;
|
|
14
18
|
#ns;
|
|
15
19
|
#fragment;
|
|
16
|
-
interwiki = '';
|
|
17
20
|
valid;
|
|
18
21
|
/** @private */
|
|
19
22
|
encoded = false;
|
|
20
23
|
/* NOT FOR BROWSER */
|
|
21
24
|
#redirectFragment;
|
|
25
|
+
interwiki = '';
|
|
22
26
|
/** @private */
|
|
23
27
|
conversionTable = new Map();
|
|
24
28
|
/** @private */
|
|
25
29
|
redirects = new Map();
|
|
26
30
|
/* NOT FOR BROWSER END */
|
|
27
|
-
/** 命名空间 */
|
|
31
|
+
/** namespace number / 命名空间 */
|
|
28
32
|
get ns() {
|
|
29
33
|
return this.#ns;
|
|
30
34
|
}
|
|
@@ -32,7 +36,7 @@ class Title {
|
|
|
32
36
|
get fragment() {
|
|
33
37
|
return this.#fragment;
|
|
34
38
|
}
|
|
35
|
-
/** 不含命名空间的标题主体部分 */
|
|
39
|
+
/** main part without the namespace / 不含命名空间的标题主体部分 */
|
|
36
40
|
get main() {
|
|
37
41
|
return this.#main;
|
|
38
42
|
}
|
|
@@ -40,16 +44,16 @@ class Title {
|
|
|
40
44
|
title = title.replace(/_/gu, ' ').trim();
|
|
41
45
|
this.#main = title && title[0].toUpperCase() + title.slice(1);
|
|
42
46
|
}
|
|
43
|
-
/** 命名空间前缀 */
|
|
47
|
+
/** namespace prefix / 命名空间前缀 */
|
|
44
48
|
get prefix() {
|
|
45
49
|
const namespace = this.#namespaces[this.ns];
|
|
46
50
|
return namespace + (namespace && ':');
|
|
47
51
|
}
|
|
48
|
-
/** 完整标题 */
|
|
52
|
+
/** full title / 完整标题 */
|
|
49
53
|
get title() {
|
|
50
54
|
return this.getRedirection()[1];
|
|
51
55
|
}
|
|
52
|
-
/** 扩展名 */
|
|
56
|
+
/** file extension / 扩展名 */
|
|
53
57
|
get extension() {
|
|
54
58
|
const { main } = this, i = main.lastIndexOf('.');
|
|
55
59
|
return i === -1 ? undefined : main.slice(i + 1).toLowerCase();
|
|
@@ -80,7 +84,8 @@ class Title {
|
|
|
80
84
|
catch { }
|
|
81
85
|
}
|
|
82
86
|
// eslint-disable-next-line es-x/no-string-prototype-trimstart-trimend
|
|
83
|
-
this.#fragment = (0, string_1.decodeHtml)(fragment).replace(/[_ ]+/gu, ' ').trimEnd()
|
|
87
|
+
this.#fragment = (0, string_1.decodeHtml)(fragment).replace(/[_ ]+/gu, ' ').trimEnd()
|
|
88
|
+
.replaceAll(' ', '_');
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
/* NOT FOR BROWSER END */
|
|
@@ -92,7 +97,7 @@ class Title {
|
|
|
92
97
|
* @param decode 是否需要解码
|
|
93
98
|
* @param selfLink 是否允许selfLink
|
|
94
99
|
*/
|
|
95
|
-
constructor(title, defaultNs, config, decode, selfLink) {
|
|
100
|
+
constructor(title, defaultNs, config, temporary, decode, selfLink) {
|
|
96
101
|
const subpage = title.trim().startsWith('../');
|
|
97
102
|
if (decode && title.includes('%')) {
|
|
98
103
|
try {
|
|
@@ -141,35 +146,35 @@ class Title {
|
|
|
141
146
|
this.#fragment = fragment.replace(/ /gu, '_');
|
|
142
147
|
title = title.slice(0, i).trim();
|
|
143
148
|
}
|
|
144
|
-
this.valid = Boolean(title
|
|
149
|
+
this.valid = Boolean(title
|
|
150
|
+
|| this.interwiki
|
|
151
|
+
|| selfLink && this.ns === 0 && this.#fragment !== undefined)
|
|
145
152
|
&& (0, string_1.decodeHtml)(title) === title
|
|
146
153
|
&& !/^:|\0\d+[eh!+-]\x7F|[<>[\]{}|\n]|%[\da-f]{2}|(?:^|\/)\.{1,2}(?:$|\/)/iu.test(subpage ? /^(?:\.\.\/)+(.*)/u.exec(title)[1] : title);
|
|
147
154
|
this.main = title;
|
|
148
|
-
Object.defineProperties(this, {
|
|
149
|
-
encoded: { enumerable: false, writable: false },
|
|
150
|
-
/* NOT FOR BROWSER */
|
|
151
|
-
valid: { writable: false },
|
|
152
|
-
conversionTable: { enumerable: false },
|
|
153
|
-
redirects: { enumerable: false },
|
|
154
|
-
});
|
|
155
155
|
this.#namespaces = config.namespaces;
|
|
156
156
|
this.#path = config.articlePath || '/wiki/$1';
|
|
157
157
|
if (!this.#path.includes('$1')) {
|
|
158
158
|
this.#path += `${this.#path.endsWith('/') ? '' : '/'}$1`;
|
|
159
159
|
}
|
|
160
|
+
if (!temporary) {
|
|
161
|
+
Object.defineProperties(this, {
|
|
162
|
+
encoded: { enumerable: false, writable: false },
|
|
163
|
+
/* NOT FOR BROWSER */
|
|
164
|
+
valid: { writable: false },
|
|
165
|
+
conversionTable: { enumerable: false },
|
|
166
|
+
redirects: { enumerable: false },
|
|
167
|
+
});
|
|
168
|
+
}
|
|
160
169
|
}
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
? ''
|
|
167
|
-
: `#${this.#fragment
|
|
168
|
-
?? this.#redirectFragment}`);
|
|
169
|
-
}
|
|
170
|
-
/** 检测是否是重定向 */
|
|
170
|
+
/**
|
|
171
|
+
* Check if the title is a redirect
|
|
172
|
+
*
|
|
173
|
+
* 检测是否是重定向
|
|
174
|
+
*/
|
|
171
175
|
getRedirection() {
|
|
172
|
-
const prefix = this.interwiki + (this.interwiki && ':') +
|
|
176
|
+
const prefix = this.interwiki + (this.interwiki && ':') + // eslint-disable-line @stylistic/operator-linebreak
|
|
177
|
+
this.prefix;
|
|
173
178
|
let title = (prefix + this.main).replace(/ /gu, '_');
|
|
174
179
|
/* NOT FOR BROWSER */
|
|
175
180
|
let redirected = this.#redirect(title);
|
|
@@ -190,8 +195,10 @@ class Title {
|
|
|
190
195
|
this.#fragment = fragment;
|
|
191
196
|
}
|
|
192
197
|
/**
|
|
198
|
+
* Get the URL of the title
|
|
199
|
+
*
|
|
193
200
|
* 生成URL
|
|
194
|
-
* @param articlePath 条目路径
|
|
201
|
+
* @param articlePath article path / 条目路径
|
|
195
202
|
*/
|
|
196
203
|
getUrl(articlePath) {
|
|
197
204
|
LSP: { // eslint-disable-line no-unused-labels
|
|
@@ -214,6 +221,15 @@ class Title {
|
|
|
214
221
|
}
|
|
215
222
|
}
|
|
216
223
|
/* NOT FOR BROWSER */
|
|
224
|
+
/** @private */
|
|
225
|
+
toString(display) {
|
|
226
|
+
return (display ? this.title.replace(/_/gu, ' ') : this.title)
|
|
227
|
+
+ (this.#fragment === undefined
|
|
228
|
+
&& this.#redirectFragment === undefined
|
|
229
|
+
? ''
|
|
230
|
+
: `#${this.#fragment
|
|
231
|
+
?? this.#redirectFragment}`);
|
|
232
|
+
}
|
|
217
233
|
/**
|
|
218
234
|
* 处理重定向
|
|
219
235
|
* @param title 原标题
|
|
@@ -232,7 +248,11 @@ class Title {
|
|
|
232
248
|
}
|
|
233
249
|
return '';
|
|
234
250
|
}
|
|
235
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* Perform unidirectional language conversion
|
|
253
|
+
*
|
|
254
|
+
* 执行单向转换
|
|
255
|
+
*/
|
|
236
256
|
autoConvert() {
|
|
237
257
|
const { conversionTable } = this;
|
|
238
258
|
if (conversionTable.size > 0) {
|
|
@@ -240,33 +260,54 @@ class Title {
|
|
|
240
260
|
this.main = this.main.replace(regex, p => conversionTable.get(p));
|
|
241
261
|
}
|
|
242
262
|
}
|
|
243
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* Get the title of its subject page
|
|
265
|
+
*
|
|
266
|
+
* 转换为主页面
|
|
267
|
+
*/
|
|
244
268
|
toSubjectPage() {
|
|
245
269
|
if (this.isTalkPage()) {
|
|
246
270
|
this.#ns--;
|
|
247
271
|
}
|
|
248
272
|
}
|
|
249
|
-
/**
|
|
273
|
+
/**
|
|
274
|
+
* Get the title of its talk page
|
|
275
|
+
*
|
|
276
|
+
* 转换为讨论页面
|
|
277
|
+
*/
|
|
250
278
|
toTalkPage() {
|
|
251
279
|
if (!this.isTalkPage()) {
|
|
252
280
|
this.#ns++;
|
|
253
281
|
}
|
|
254
282
|
}
|
|
255
|
-
/**
|
|
283
|
+
/**
|
|
284
|
+
* Check if the title is a talk page
|
|
285
|
+
*
|
|
286
|
+
* 是否是讨论页
|
|
287
|
+
*/
|
|
256
288
|
isTalkPage() {
|
|
257
289
|
return this.ns % 2 === 1;
|
|
258
290
|
}
|
|
259
|
-
/**
|
|
291
|
+
/**
|
|
292
|
+
* Get the title of its base page
|
|
293
|
+
*
|
|
294
|
+
* 转换为上一级页面
|
|
295
|
+
*/
|
|
260
296
|
toBasePage() {
|
|
261
297
|
this.main = this.main.replace(/\/[^/]*$/u, '');
|
|
262
298
|
}
|
|
263
|
-
/**
|
|
299
|
+
/**
|
|
300
|
+
* Get the title of its root page
|
|
301
|
+
*
|
|
302
|
+
* 转换为根页面
|
|
303
|
+
*/
|
|
264
304
|
toRootPage() {
|
|
265
305
|
this.main = this.main.replace(/\/.*/u, '');
|
|
266
306
|
}
|
|
267
307
|
/** @private */
|
|
268
308
|
getTitleAttr() {
|
|
269
|
-
return this.title.replace(/^Media:/u, '')
|
|
309
|
+
return this.title.replace(/^Media:/u, '')
|
|
310
|
+
.replace(/["_]/gu, p => p === '"' ? '"' : ' ');
|
|
270
311
|
}
|
|
271
312
|
}
|
|
272
313
|
exports.Title = Title;
|
|
@@ -1,49 +1,65 @@
|
|
|
1
1
|
export interface AttributesParentBase {
|
|
2
|
-
/**
|
|
2
|
+
/** all attributes / 全部属性 */
|
|
3
3
|
attributes: Record<string, string | true>;
|
|
4
|
-
/** 以字符串表示的class属性 */
|
|
4
|
+
/** class attribute in string / 以字符串表示的class属性 */
|
|
5
5
|
className: string;
|
|
6
|
-
/** 以Set表示的class属性 */
|
|
6
|
+
/** class attribute in Set / 以Set表示的class属性 */
|
|
7
7
|
readonly classList: Set<string>;
|
|
8
|
-
/** id属性 */
|
|
8
|
+
/** id attribute / id属性 */
|
|
9
9
|
id: string;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Get the attribute
|
|
12
|
+
*
|
|
13
|
+
* 获取指定属性
|
|
14
|
+
* @param key attribute name / 属性键
|
|
13
15
|
*/
|
|
14
16
|
getAttr(key: string): string | true | undefined;
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
+
* Check if the token has a certain attribute
|
|
19
|
+
*
|
|
20
|
+
* 是否具有某属性
|
|
21
|
+
* @param key attribute name / 属性键
|
|
18
22
|
*/
|
|
19
23
|
hasAttr(key: string): boolean;
|
|
20
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Get all attribute names
|
|
26
|
+
*
|
|
27
|
+
* 获取全部的属性名
|
|
28
|
+
*/
|
|
21
29
|
getAttrNames(): Set<string>;
|
|
22
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Get all attributes
|
|
32
|
+
*
|
|
33
|
+
* 获取全部属性
|
|
34
|
+
*/
|
|
23
35
|
getAttrs(): Record<string, string | true>;
|
|
24
36
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param
|
|
37
|
+
* Set the attribute
|
|
38
|
+
*
|
|
39
|
+
* 设置指定属性
|
|
40
|
+
* @param key attribute name / 属性键
|
|
41
|
+
* @param value attribute value / 属性值
|
|
42
|
+
* @param prop attribute object / 属性对象
|
|
29
43
|
*/
|
|
30
44
|
setAttr(key: string, value: string | boolean): void;
|
|
31
45
|
setAttr(prop: Record<string, string | boolean>): void;
|
|
32
46
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
47
|
+
* Remove an attribute
|
|
48
|
+
*
|
|
49
|
+
* 移除指定属性
|
|
50
|
+
* @param key attribute name / 属性键
|
|
35
51
|
*/
|
|
36
52
|
removeAttr(key: string): void;
|
|
37
53
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
54
|
+
* Toggle the specified attribute
|
|
55
|
+
*
|
|
56
|
+
* 开关指定属性
|
|
57
|
+
* @param key attribute name / 属性键
|
|
58
|
+
* @param force whether to force enabling or disabling / 强制开启或关闭
|
|
41
59
|
*/
|
|
42
60
|
toggleAttr(key: string, force?: boolean): void;
|
|
43
61
|
}
|
|
44
62
|
/**
|
|
45
63
|
* 子节点含有AttributesToken的类
|
|
46
64
|
* @param i AttributesToken子节点的位置
|
|
47
|
-
* @param constructor 基类
|
|
48
|
-
* @param _ context
|
|
49
65
|
*/
|
|
@@ -7,8 +7,6 @@ const constants_1 = require("../util/constants");
|
|
|
7
7
|
/**
|
|
8
8
|
* 子节点含有AttributesToken的类
|
|
9
9
|
* @param i AttributesToken子节点的位置
|
|
10
|
-
* @param constructor 基类
|
|
11
|
-
* @param _ context
|
|
12
10
|
*/
|
|
13
11
|
const attributesParent = (i = 0) => (constructor, _) => {
|
|
14
12
|
/** 子节点含有AttributesToken的类 */
|
|
@@ -1,38 +1,64 @@
|
|
|
1
1
|
import type { ConverterFlagsToken } from '../src/converterFlags';
|
|
2
2
|
export interface FlagsParentBase {
|
|
3
|
-
/** 所有转换类型标记 */
|
|
3
|
+
/** all language conversion flags / 所有转换类型标记 */
|
|
4
4
|
flags: Set<string>;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Get all language conversion flags
|
|
7
|
+
*
|
|
8
|
+
* 获取所有转换类型标记
|
|
9
|
+
*/
|
|
6
10
|
getAllFlags(): Set<string>;
|
|
7
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Get effective language conversion flags
|
|
13
|
+
*
|
|
14
|
+
* 获取有效的转换类型标记
|
|
15
|
+
*/
|
|
8
16
|
getEffectiveFlags(): Set<string>;
|
|
9
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Get unknown language conversion flags
|
|
19
|
+
*
|
|
20
|
+
* 获取未知的转换类型标记
|
|
21
|
+
*/
|
|
10
22
|
getUnknownFlags(): Set<string>;
|
|
11
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Get language coversion flags that specify a language variant
|
|
25
|
+
*
|
|
26
|
+
* 获取指定语言变体的转换标记
|
|
27
|
+
*/
|
|
12
28
|
getVariantFlags(): Set<string>;
|
|
13
29
|
/**
|
|
30
|
+
* Check if a language conversion flag is present
|
|
31
|
+
*
|
|
14
32
|
* 是否具有某转换类型标记
|
|
15
|
-
* @param flag 转换类型标记
|
|
33
|
+
* @param flag language conversion flag / 转换类型标记
|
|
16
34
|
*/
|
|
17
35
|
hasFlag(flag: string): boolean;
|
|
18
36
|
/**
|
|
37
|
+
* Check if an effective language conversion flag is present
|
|
38
|
+
*
|
|
19
39
|
* 是否具有某有效的转换类型标记
|
|
20
|
-
* @param flag 转换类型标记
|
|
40
|
+
* @param flag language conversion flag / 转换类型标记
|
|
21
41
|
*/
|
|
22
42
|
hasEffectiveFlag(flag: string): boolean;
|
|
23
43
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
44
|
+
* Remove a language conversion flag
|
|
45
|
+
*
|
|
46
|
+
* 移除某转换类型标记
|
|
47
|
+
* @param flag language conversion flag / 转换类型标记
|
|
26
48
|
*/
|
|
27
49
|
removeFlag(flag: string): void;
|
|
28
50
|
/**
|
|
51
|
+
* Set a language conversion flag
|
|
52
|
+
*
|
|
29
53
|
* 设置转换类型标记
|
|
30
|
-
* @param flag 转换类型标记
|
|
54
|
+
* @param flag language conversion flag / 转换类型标记
|
|
31
55
|
*/
|
|
32
56
|
setFlag(flag: string): void;
|
|
33
57
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
58
|
+
* Toggle a language conversion flag
|
|
59
|
+
*
|
|
60
|
+
* 开关转换类型标记
|
|
61
|
+
* @param flag language conversion flag / 转换类型标记
|
|
36
62
|
*/
|
|
37
63
|
toggleFlag(flag: string): void;
|
|
38
64
|
}
|
package/dist/mixin/hidden.d.ts
CHANGED
package/dist/mixin/hidden.js
CHANGED
|
@@ -9,8 +9,6 @@ const constants_1 = require("../util/constants");
|
|
|
9
9
|
* 解析后不可见的类
|
|
10
10
|
* @param linter 是否覆写 lint 方法
|
|
11
11
|
* @param html 是否覆写 toHtml 方法
|
|
12
|
-
* @param constructor 基类
|
|
13
|
-
* @param _ context
|
|
14
12
|
*/
|
|
15
13
|
const hiddenToken = (linter = true, html = true) => (constructor, _) => {
|
|
16
14
|
/** 解析后不可见的类 */
|