wikiparser-node 1.0.0-beta.2 → 1.0.0-beta.4
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/minimum.json +136 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/internal.d.ts +1 -1
- package/dist/lib/element.d.ts +12 -8
- package/dist/lib/element.js +72 -57
- package/dist/lib/node.js +4 -5
- package/dist/lib/range.js +5 -8
- package/dist/lib/ranges.js +2 -2
- package/dist/lib/text.d.ts +2 -2
- package/dist/lib/text.js +5 -5
- package/dist/lib/title.d.ts +3 -2
- package/dist/lib/title.js +11 -10
- package/dist/mixin/attributesParent.js +2 -2
- package/dist/mixin/fixed.js +3 -3
- package/dist/mixin/hidden.js +2 -2
- package/dist/mixin/singleLine.js +4 -4
- package/dist/mixin/sol.js +6 -6
- package/dist/parser/braces.js +4 -9
- package/dist/parser/commentAndExt.js +24 -18
- package/dist/parser/converter.js +8 -7
- package/dist/parser/externalLinks.js +3 -4
- package/dist/parser/hrAndDoubleUnderscore.js +4 -7
- package/dist/parser/html.js +4 -7
- package/dist/parser/links.js +4 -5
- package/dist/parser/list.js +3 -6
- package/dist/parser/magicLinks.js +3 -3
- package/dist/parser/quotes.js +4 -5
- package/dist/parser/selector.js +4 -7
- package/dist/parser/table.js +6 -15
- package/dist/src/arg.d.ts +6 -5
- package/dist/src/arg.js +31 -27
- package/dist/src/atom.d.ts +2 -1
- package/dist/src/atom.js +4 -4
- package/dist/src/attribute.d.ts +14 -13
- package/dist/src/attribute.js +41 -31
- package/dist/src/attributes.d.ts +4 -3
- package/dist/src/attributes.js +15 -21
- package/dist/src/converter.d.ts +4 -3
- package/dist/src/converter.js +10 -17
- package/dist/src/converterFlags.d.ts +9 -8
- package/dist/src/converterFlags.js +14 -15
- package/dist/src/converterRule.d.ts +4 -3
- package/dist/src/converterRule.js +20 -22
- package/dist/src/extLink.d.ts +5 -4
- package/dist/src/extLink.js +16 -17
- package/dist/src/gallery.d.ts +7 -5
- package/dist/src/gallery.js +15 -19
- package/dist/src/heading.d.ts +12 -10
- package/dist/src/heading.js +17 -18
- package/dist/src/hidden.d.ts +4 -3
- package/dist/src/hidden.js +4 -4
- package/dist/src/html.d.ts +17 -15
- package/dist/src/html.js +25 -23
- package/dist/src/imageParameter.d.ts +5 -4
- package/dist/src/imageParameter.js +22 -23
- package/dist/src/imagemap.d.ts +7 -5
- package/dist/src/imagemap.js +14 -19
- package/dist/src/imagemapLink.d.ts +8 -7
- package/dist/src/imagemapLink.js +4 -8
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +48 -46
- package/dist/src/link/base.d.ts +5 -4
- package/dist/src/link/base.js +26 -28
- package/dist/src/link/category.d.ts +1 -1
- package/dist/src/link/category.js +3 -2
- package/dist/src/link/file.d.ts +5 -4
- package/dist/src/link/file.js +22 -20
- package/dist/src/link/galleryImage.d.ts +5 -5
- package/dist/src/link/galleryImage.js +11 -10
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/link/index.js +8 -6
- package/dist/src/magicLink.d.ts +3 -2
- package/dist/src/magicLink.js +10 -11
- package/dist/src/nested.d.ts +4 -2
- package/dist/src/nested.js +5 -9
- package/dist/src/nowiki/base.d.ts +6 -5
- package/dist/src/nowiki/base.js +4 -4
- package/dist/src/nowiki/comment.d.ts +6 -5
- package/dist/src/nowiki/comment.js +8 -10
- package/dist/src/nowiki/dd.d.ts +1 -1
- package/dist/src/nowiki/dd.js +3 -2
- package/dist/src/nowiki/doubleUnderscore.d.ts +8 -6
- package/dist/src/nowiki/doubleUnderscore.js +13 -13
- package/dist/src/nowiki/hr.d.ts +2 -8
- package/dist/src/nowiki/hr.js +4 -11
- package/dist/src/nowiki/index.d.ts +2 -1
- package/dist/src/nowiki/index.js +6 -5
- package/dist/src/nowiki/list.d.ts +4 -4
- package/dist/src/nowiki/list.js +3 -2
- package/dist/src/nowiki/noinclude.d.ts +2 -2
- package/dist/src/nowiki/noinclude.js +3 -2
- package/dist/src/nowiki/quote.d.ts +1 -8
- package/dist/src/nowiki/quote.js +25 -17
- package/dist/src/onlyinclude.d.ts +5 -4
- package/dist/src/onlyinclude.js +13 -13
- package/dist/src/paramTag/index.d.ts +5 -3
- package/dist/src/paramTag/index.js +7 -7
- package/dist/src/paramTag/inputbox.d.ts +3 -2
- package/dist/src/paramTag/inputbox.js +6 -5
- package/dist/src/parameter.d.ts +11 -10
- package/dist/src/parameter.js +29 -30
- package/dist/src/pre.d.ts +4 -2
- package/dist/src/pre.js +19 -14
- package/dist/src/syntax.d.ts +2 -1
- package/dist/src/syntax.js +7 -7
- package/dist/src/table/base.d.ts +6 -5
- package/dist/src/table/base.js +6 -8
- package/dist/src/table/index.d.ts +9 -8
- package/dist/src/table/index.js +23 -24
- package/dist/src/table/td.d.ts +12 -10
- package/dist/src/table/td.js +19 -20
- package/dist/src/table/tr.d.ts +3 -2
- package/dist/src/table/tr.js +4 -3
- package/dist/src/table/trBase.d.ts +3 -3
- package/dist/src/table/trBase.js +10 -10
- package/dist/src/tagPair/ext.d.ts +7 -6
- package/dist/src/tagPair/ext.js +5 -17
- package/dist/src/tagPair/include.d.ts +5 -5
- package/dist/src/tagPair/include.js +4 -5
- package/dist/src/tagPair/index.d.ts +7 -7
- package/dist/src/tagPair/index.js +13 -19
- package/dist/src/transclude.d.ts +10 -9
- package/dist/src/transclude.js +41 -46
- package/dist/util/lint.js +14 -4
- package/dist/util/string.js +21 -20
- package/package.json +11 -9
package/dist/lib/title.js
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Title = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
5
|
+
const Parser = require("../index");
|
|
6
6
|
/** MediaWiki页面标题对象 */
|
|
7
7
|
class Title {
|
|
8
8
|
/** @browser */
|
|
9
|
-
valid
|
|
9
|
+
valid;
|
|
10
10
|
/** @browser */
|
|
11
|
-
ns
|
|
11
|
+
ns;
|
|
12
12
|
/** @browser */
|
|
13
13
|
fragment;
|
|
14
14
|
/** @browser */
|
|
15
15
|
encoded = false;
|
|
16
|
-
main
|
|
17
|
-
prefix
|
|
16
|
+
main;
|
|
17
|
+
prefix;
|
|
18
18
|
interwiki = '';
|
|
19
19
|
conversionTable = new Map();
|
|
20
20
|
redirects = new Map();
|
|
@@ -31,14 +31,15 @@ class Title {
|
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* @browser
|
|
34
|
-
* @param
|
|
34
|
+
* @param title 标题(含或不含命名空间前缀)
|
|
35
35
|
* @param defaultNs 命名空间
|
|
36
36
|
* @param decode 是否需要解码
|
|
37
37
|
* @param selfLink 是否允许selfLink
|
|
38
38
|
*/
|
|
39
|
-
constructor(
|
|
39
|
+
constructor(title, defaultNs = 0, config = Parser.getConfig(), decode = false, selfLink = false) {
|
|
40
40
|
const { namespaces, nsid } = config;
|
|
41
|
-
let namespace = namespaces[defaultNs]
|
|
41
|
+
let namespace = namespaces[defaultNs];
|
|
42
|
+
title = (0, string_1.decodeHtml)(title);
|
|
42
43
|
if (decode && title.includes('%')) {
|
|
43
44
|
try {
|
|
44
45
|
const encoded = /%(?!21|3[ce]|5[bd]|7[b-d])[\da-f]{2}/iu.test(title);
|
|
@@ -52,7 +53,7 @@ class Title {
|
|
|
52
53
|
namespace = '';
|
|
53
54
|
title = title.slice(1).trim();
|
|
54
55
|
}
|
|
55
|
-
const iw = defaultNs ?
|
|
56
|
+
const iw = defaultNs ? null : Parser.isInterwiki(title, config);
|
|
56
57
|
if (iw) {
|
|
57
58
|
this.interwiki = iw[1].toLowerCase();
|
|
58
59
|
title = title.slice(iw[0].length);
|
|
@@ -107,4 +108,4 @@ class Title {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
exports.Title = Title;
|
|
110
|
-
|
|
111
|
+
Parser.classes['Title'] = __filename;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.attributesParent = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
/**
|
|
6
6
|
* 子节点含有AttributesToken的类
|
|
7
7
|
* @param constructor 基类
|
|
@@ -90,4 +90,4 @@ const attributesParent = (constructor, i = 0) => {
|
|
|
90
90
|
return AttributesParent;
|
|
91
91
|
};
|
|
92
92
|
exports.attributesParent = attributesParent;
|
|
93
|
-
|
|
93
|
+
Parser.mixins['attributesParent'] = __filename;
|
package/dist/mixin/fixed.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fixed = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
/**
|
|
6
6
|
* 不可增删子节点的类
|
|
7
7
|
* @param constructor 基类
|
|
@@ -20,7 +20,7 @@ const fixed = (constructor) => {
|
|
|
20
20
|
}
|
|
21
21
|
/** @ignore */
|
|
22
22
|
insertAt(token, i = this.length) {
|
|
23
|
-
if (
|
|
23
|
+
if (Parser.running) {
|
|
24
24
|
return super.insertAt(token, i);
|
|
25
25
|
}
|
|
26
26
|
throw new Error(`${this.constructor.name} 不可插入元素!`);
|
|
@@ -29,4 +29,4 @@ const fixed = (constructor) => {
|
|
|
29
29
|
return FixedToken;
|
|
30
30
|
};
|
|
31
31
|
exports.fixed = fixed;
|
|
32
|
-
|
|
32
|
+
Parser.mixins['fixed'] = __filename;
|
package/dist/mixin/hidden.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hidden = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
/**
|
|
6
6
|
* 解析后不可见的类
|
|
7
7
|
* @param constructor 基类
|
|
@@ -20,4 +20,4 @@ const hidden = (constructor) => {
|
|
|
20
20
|
return AnyHiddenToken;
|
|
21
21
|
};
|
|
22
22
|
exports.hidden = hidden;
|
|
23
|
-
|
|
23
|
+
Parser.mixins['hidden'] = __filename;
|
package/dist/mixin/singleLine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.singleLine = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
/**
|
|
6
6
|
* 不可包含换行符的类
|
|
7
7
|
* @param constructor 基类
|
|
@@ -11,8 +11,8 @@ const singleLine = (constructor) => {
|
|
|
11
11
|
/** 不可包含换行符的类 */
|
|
12
12
|
class SingleLineToken extends constructor {
|
|
13
13
|
/** @override */
|
|
14
|
-
toString(
|
|
15
|
-
return super.toString(
|
|
14
|
+
toString(omit) {
|
|
15
|
+
return super.toString(omit).replaceAll('\n', ' ');
|
|
16
16
|
}
|
|
17
17
|
/** @override */
|
|
18
18
|
text() {
|
|
@@ -23,4 +23,4 @@ const singleLine = (constructor) => {
|
|
|
23
23
|
return SingleLineToken;
|
|
24
24
|
};
|
|
25
25
|
exports.singleLine = singleLine;
|
|
26
|
-
|
|
26
|
+
Parser.mixins['singleLine'] = __filename;
|
package/dist/mixin/sol.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sol = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
/**
|
|
6
6
|
* 只能位于行首的类
|
|
7
7
|
* @param constructor 基类
|
|
@@ -19,15 +19,15 @@ const sol = (constructor) => {
|
|
|
19
19
|
/** 在前方插入newline */
|
|
20
20
|
prependNewLine() {
|
|
21
21
|
const { previousVisibleSibling } = this;
|
|
22
|
-
return (previousVisibleSibling
|
|
22
|
+
return (previousVisibleSibling && !String(previousVisibleSibling).endsWith('\n')) ?? !this.#isRoot()
|
|
23
23
|
? '\n'
|
|
24
24
|
: '';
|
|
25
25
|
}
|
|
26
26
|
/** @override */
|
|
27
|
-
toString(
|
|
28
|
-
return
|
|
27
|
+
toString(omit) {
|
|
28
|
+
return omit && this.matchesTypes(omit)
|
|
29
29
|
? ''
|
|
30
|
-
: `${this.prependNewLine()}${super.toString(
|
|
30
|
+
: `${this.prependNewLine()}${super.toString(omit)}`;
|
|
31
31
|
}
|
|
32
32
|
/** @override */
|
|
33
33
|
getPadding() {
|
|
@@ -41,4 +41,4 @@ const sol = (constructor) => {
|
|
|
41
41
|
return SolToken;
|
|
42
42
|
};
|
|
43
43
|
exports.sol = sol;
|
|
44
|
-
|
|
44
|
+
Parser.mixins['sol'] = __filename;
|
package/dist/parser/braces.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseBraces = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
5
|
+
const Parser = require("../index");
|
|
6
6
|
const heading_1 = require("../src/heading");
|
|
7
7
|
const transclude_1 = require("../src/transclude");
|
|
8
8
|
const arg_1 = require("../src/arg");
|
|
@@ -13,7 +13,7 @@ const arg_1 = require("../src/arg");
|
|
|
13
13
|
* @param accum
|
|
14
14
|
* @throws TranscludeToken.constructor()
|
|
15
15
|
*/
|
|
16
|
-
const parseBraces = (wikitext, config =
|
|
16
|
+
const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
17
17
|
const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]);
|
|
18
18
|
let regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = wikitext.includes('}}'), lastIndex;
|
|
19
19
|
while (mt || lastIndex !== undefined && lastIndex <= wikitext.length && stack.at(-1)?.[0]?.startsWith('=')) {
|
|
@@ -35,7 +35,6 @@ const parseBraces = (wikitext, config = index_1.default.getConfig(), accum = [])
|
|
|
35
35
|
if (rmt) {
|
|
36
36
|
wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
|
|
37
37
|
lastIndex = index + 4 + String(accum.length).length;
|
|
38
|
-
// @ts-expect-error abstract class
|
|
39
38
|
new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
|
|
40
39
|
}
|
|
41
40
|
}
|
|
@@ -57,7 +56,6 @@ const parseBraces = (wikitext, config = index_1.default.getConfig(), accum = [])
|
|
|
57
56
|
let skip = false, ch = 't';
|
|
58
57
|
if (close.length === 3) {
|
|
59
58
|
const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
|
|
60
|
-
// @ts-expect-error abstract class
|
|
61
59
|
new arg_1.ArgToken(argParts, config, accum);
|
|
62
60
|
if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
|
|
63
61
|
ch = 's';
|
|
@@ -65,7 +63,6 @@ const parseBraces = (wikitext, config = index_1.default.getConfig(), accum = [])
|
|
|
65
63
|
}
|
|
66
64
|
else {
|
|
67
65
|
try {
|
|
68
|
-
// @ts-expect-error absstract class
|
|
69
66
|
new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
|
|
70
67
|
const name = (0, string_1.removeComment)(parts[0][0]).trim();
|
|
71
68
|
if (marks.has(name)) {
|
|
@@ -113,13 +110,11 @@ const parseBraces = (wikitext, config = index_1.default.getConfig(), accum = [])
|
|
|
113
110
|
stack.pop();
|
|
114
111
|
curTop = stack.at(-1);
|
|
115
112
|
}
|
|
116
|
-
regex = new RegExp(source + (curTop
|
|
117
|
-
? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}`
|
|
118
|
-
: ''), 'gmu');
|
|
113
|
+
regex = new RegExp(source + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
|
|
119
114
|
regex.lastIndex = lastIndex;
|
|
120
115
|
mt = regex.exec(wikitext);
|
|
121
116
|
}
|
|
122
117
|
return wikitext;
|
|
123
118
|
};
|
|
124
119
|
exports.parseBraces = parseBraces;
|
|
125
|
-
|
|
120
|
+
Parser.parsers['parseBraces'] = __filename;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseCommentAndExt = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const onlyinclude_1 = require("../src/onlyinclude");
|
|
6
6
|
const noinclude_1 = require("../src/nowiki/noinclude");
|
|
7
7
|
const include_1 = require("../src/tagPair/include");
|
|
@@ -14,18 +14,28 @@ const comment_1 = require("../src/nowiki/comment");
|
|
|
14
14
|
* @param accum
|
|
15
15
|
* @param includeOnly 是否嵌入
|
|
16
16
|
*/
|
|
17
|
-
const parseCommentAndExt = (wikitext, config =
|
|
18
|
-
const onlyinclude =
|
|
19
|
-
if (includeOnly
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], includeOnly = false) => {
|
|
18
|
+
const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
|
|
19
|
+
if (includeOnly) {
|
|
20
|
+
let i = wikitext.indexOf(onlyincludeLeft), j = wikitext.indexOf(onlyincludeRight, i + length);
|
|
21
|
+
if (i !== -1 && j !== -1) { // `<onlyinclude>`拥有最高优先级
|
|
22
|
+
let str = '';
|
|
23
|
+
while (i !== -1 && j !== -1) {
|
|
24
|
+
const token = `\0${accum.length}e\x7F`;
|
|
25
|
+
new onlyinclude_1.OnlyincludeToken(wikitext.slice(i + length, j), config, accum);
|
|
26
|
+
if (i > 0) {
|
|
27
|
+
new noinclude_1.NoincludeToken(wikitext.slice(0, i), config, accum);
|
|
28
|
+
str += `\0${accum.length - 1}c\x7F${token}`;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
str += token;
|
|
32
|
+
}
|
|
33
|
+
wikitext = wikitext.slice(j + length + 1);
|
|
34
|
+
i = wikitext.indexOf(onlyincludeLeft);
|
|
35
|
+
j = wikitext.indexOf(onlyincludeRight, i + length);
|
|
36
|
+
}
|
|
37
|
+
return `${str}${wikitext}`;
|
|
38
|
+
}
|
|
29
39
|
}
|
|
30
40
|
const ext = config.ext.join('|'), includeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', noincludeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)|' // comment
|
|
31
41
|
+ `<${includeRegex}(?:\\s[^>]*?)?>|</${includeRegex}\\s*>|` // <includeonly>
|
|
@@ -35,24 +45,20 @@ const parseCommentAndExt = (wikitext, config = index_1.default.getConfig(), accu
|
|
|
35
45
|
return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
|
|
36
46
|
const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
|
|
37
47
|
if (name) {
|
|
38
|
-
// @ts-expect-error abstract class
|
|
39
48
|
new ext_1.ExtToken(name, attr, inner, closing, config, accum);
|
|
40
49
|
}
|
|
41
50
|
else if (substr.startsWith('<!--')) {
|
|
42
51
|
const closed = substr.endsWith('-->');
|
|
43
|
-
// @ts-expect-error abstract class
|
|
44
52
|
new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
|
|
45
53
|
}
|
|
46
54
|
else if (include) {
|
|
47
|
-
// @ts-expect-error abstract class
|
|
48
55
|
new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
|
|
49
56
|
}
|
|
50
57
|
else {
|
|
51
|
-
// @ts-expect-error abstract class
|
|
52
58
|
new noinclude_1.NoincludeToken(substr, config, accum);
|
|
53
59
|
}
|
|
54
60
|
return str;
|
|
55
61
|
});
|
|
56
62
|
};
|
|
57
63
|
exports.parseCommentAndExt = parseCommentAndExt;
|
|
58
|
-
|
|
64
|
+
Parser.parsers['parseCommentAndExt'] = __filename;
|
package/dist/parser/converter.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseConverter = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const converter_1 = require("../src/converter");
|
|
6
6
|
/**
|
|
7
7
|
* 解析语言变体转换
|
|
8
|
-
* @param
|
|
8
|
+
* @param text
|
|
9
9
|
* @param config
|
|
10
10
|
* @param accum
|
|
11
11
|
*/
|
|
12
|
-
const parseConverter = (
|
|
12
|
+
const parseConverter = (text, config = Parser.getConfig(), accum = []) => {
|
|
13
13
|
const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
|
|
14
|
-
let regex = regex1,
|
|
14
|
+
let regex = regex1, mt = regex.exec(text);
|
|
15
15
|
while (mt) {
|
|
16
16
|
const { 0: syntax, index } = mt;
|
|
17
17
|
if (syntax === '}-') {
|
|
18
|
-
const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)],
|
|
18
|
+
const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)],
|
|
19
|
+
// eslint-disable-next-line regexp/prefer-lookaround
|
|
20
|
+
temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=\\s*(?:${variants}|[^;]*?=>\\s*${variants})\\s*:)`, 'u'))
|
|
19
21
|
.map(rule => rule.replaceAll('\x01', ';'));
|
|
20
|
-
// @ts-expect-error abstract class
|
|
21
22
|
new converter_1.ConverterToken(flags, rules, config, accum);
|
|
22
23
|
text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
|
|
23
24
|
if (stack.length === 0) {
|
|
@@ -35,4 +36,4 @@ const parseConverter = (wikitext, config = index_1.default.getConfig(), accum =
|
|
|
35
36
|
return text;
|
|
36
37
|
};
|
|
37
38
|
exports.parseConverter = parseConverter;
|
|
38
|
-
|
|
39
|
+
Parser.parsers['parseConverter'] = __filename;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseExternalLinks = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
5
|
+
const Parser = require("../index");
|
|
6
6
|
const extLink_1 = require("../src/extLink");
|
|
7
7
|
/**
|
|
8
8
|
* 解析外部链接
|
|
@@ -10,7 +10,7 @@ const extLink_1 = require("../src/extLink");
|
|
|
10
10
|
* @param config
|
|
11
11
|
* @param accum
|
|
12
12
|
*/
|
|
13
|
-
const parseExternalLinks = (wikitext, config =
|
|
13
|
+
const parseExternalLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
14
14
|
const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar})(\\p{Zs}*)([^\\]\x01-\x08\x0A-\x1F\uFFFD]*)\\]`, 'giu');
|
|
15
15
|
return wikitext.replace(regex, (_, url, space, text) => {
|
|
16
16
|
const { length } = accum, mt = /&[lg]t;/u.exec(url);
|
|
@@ -19,10 +19,9 @@ const parseExternalLinks = (wikitext, config = index_1.default.getConfig(), accu
|
|
|
19
19
|
space = '';
|
|
20
20
|
text = `${url.slice(mt.index)}${space}${text}`;
|
|
21
21
|
}
|
|
22
|
-
// @ts-expect-error abstract class
|
|
23
22
|
new extLink_1.ExtLinkToken(url, space, text, config, accum);
|
|
24
23
|
return `\0${length}w\x7F`;
|
|
25
24
|
});
|
|
26
25
|
};
|
|
27
26
|
exports.parseExternalLinks = parseExternalLinks;
|
|
28
|
-
|
|
27
|
+
Parser.parsers['parseExternalLinks'] = __filename;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseHrAndDoubleUnderscore = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const hr_1 = require("../src/nowiki/hr");
|
|
6
6
|
const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
|
|
7
7
|
const heading_1 = require("../src/heading");
|
|
@@ -11,30 +11,27 @@ const heading_1 = require("../src/heading");
|
|
|
11
11
|
* @param config
|
|
12
12
|
* @param accum
|
|
13
13
|
*/
|
|
14
|
-
const parseHrAndDoubleUnderscore = ({ firstChild, type, name }, config =
|
|
14
|
+
const parseHrAndDoubleUnderscore = ({ firstChild, type, name }, config = Parser.getConfig(), accum = []) => {
|
|
15
15
|
const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
|
|
16
16
|
let { data } = firstChild;
|
|
17
17
|
if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
|
|
18
18
|
data = `\0${data}`;
|
|
19
19
|
}
|
|
20
20
|
data = data.replace(/^((?:\0\d+c\x7F)*)(-{4,})/gmu, (_, lead, m) => {
|
|
21
|
-
|
|
22
|
-
new hr_1.HrToken(m.length, config, accum);
|
|
21
|
+
new hr_1.HrToken(m, config, accum);
|
|
23
22
|
return `${lead}\0${accum.length - 1}r\x7F`;
|
|
24
23
|
}).replace(new RegExp(`__(${doubleUnderscore.flat().join('|')})__`, 'giu'), (m, p1) => {
|
|
25
24
|
if (insensitive.has(p1.toLowerCase()) || sensitive.has(p1)) {
|
|
26
|
-
// @ts-expect-error abstract class
|
|
27
25
|
new doubleUnderscore_1.DoubleUnderscoreToken(p1, config, accum);
|
|
28
26
|
return `\0${accum.length - 1}u\x7F`;
|
|
29
27
|
}
|
|
30
28
|
return m;
|
|
31
29
|
}).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
|
|
32
30
|
const text = `${lead}\0${accum.length}h\x7F`;
|
|
33
|
-
// @ts-expect-error abstract class
|
|
34
31
|
new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
|
|
35
32
|
return text;
|
|
36
33
|
});
|
|
37
34
|
return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
|
|
38
35
|
};
|
|
39
36
|
exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
|
|
40
|
-
|
|
37
|
+
Parser.parsers['parseHrAndDoubleUnderscore'] = __filename;
|
package/dist/parser/html.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseHtml = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const attributes_1 = require("../src/attributes");
|
|
6
6
|
const html_1 = require("../src/html");
|
|
7
7
|
/**
|
|
@@ -10,7 +10,7 @@ const html_1 = require("../src/html");
|
|
|
10
10
|
* @param config
|
|
11
11
|
* @param accum
|
|
12
12
|
*/
|
|
13
|
-
const parseHtml = (wikitext, config =
|
|
13
|
+
const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
14
14
|
const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, elements = new Set(config.html.flat()), bits = wikitext.split('<');
|
|
15
15
|
let text = bits.shift();
|
|
16
16
|
for (const x of bits) {
|
|
@@ -19,9 +19,7 @@ const parseHtml = (wikitext, config = index_1.default.getConfig(), accum = []) =
|
|
|
19
19
|
text += `<${x}`;
|
|
20
20
|
continue;
|
|
21
21
|
}
|
|
22
|
-
const [, slash, , params = '', brace, rest] = mt,
|
|
23
|
-
// @ts-expect-error abstract class
|
|
24
|
-
attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
|
|
22
|
+
const [, slash, , params = '', brace, rest] = mt, attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
|
|
25
23
|
if (name === 'meta' && (itemprop === undefined || attr.getAttr('content') === undefined)
|
|
26
24
|
|| name === 'link' && (itemprop === undefined || attr.getAttr('href') === undefined)) {
|
|
27
25
|
text += `<${x}`;
|
|
@@ -29,10 +27,9 @@ const parseHtml = (wikitext, config = index_1.default.getConfig(), accum = []) =
|
|
|
29
27
|
continue;
|
|
30
28
|
}
|
|
31
29
|
text += `\0${accum.length}x\x7F${rest}`;
|
|
32
|
-
// @ts-expect-error abstract class
|
|
33
30
|
new html_1.HtmlToken(t, attr, slash === '/', brace === '/>', config, accum);
|
|
34
31
|
}
|
|
35
32
|
return text;
|
|
36
33
|
};
|
|
37
34
|
exports.parseHtml = parseHtml;
|
|
38
|
-
|
|
35
|
+
Parser.parsers['parseHtml'] = __filename;
|
package/dist/parser/links.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseLinks = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const link_1 = require("../src/link");
|
|
6
6
|
const file_1 = require("../src/link/file");
|
|
7
7
|
const category_1 = require("../src/link/category");
|
|
@@ -11,7 +11,7 @@ const category_1 = require("../src/link/category");
|
|
|
11
11
|
* @param config
|
|
12
12
|
* @param accum
|
|
13
13
|
*/
|
|
14
|
-
const parseLinks = (wikitext, config =
|
|
14
|
+
const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
15
15
|
const { parseQuotes } = require('./quotes.js');
|
|
16
16
|
const regex = /^((?:(?!\0\d+!\x7F)[^\n<>[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n<>[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol})`, 'iu'), bits = wikitext.split('[[');
|
|
17
17
|
let s = bits.shift();
|
|
@@ -41,7 +41,7 @@ const parseLinks = (wikitext, config = index_1.default.getConfig(), accum = [])
|
|
|
41
41
|
s += `[[${x}`;
|
|
42
42
|
continue;
|
|
43
43
|
}
|
|
44
|
-
const title =
|
|
44
|
+
const title = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, interwiki, valid } = title;
|
|
45
45
|
if (!valid) {
|
|
46
46
|
s += `[[${x}`;
|
|
47
47
|
continue;
|
|
@@ -85,10 +85,9 @@ const parseLinks = (wikitext, config = index_1.default.getConfig(), accum = [])
|
|
|
85
85
|
SomeLinkToken = category_1.CategoryToken;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
// @ts-expect-error abstract class
|
|
89
88
|
new SomeLinkToken(link, text, config, accum, delimiter);
|
|
90
89
|
}
|
|
91
90
|
return s;
|
|
92
91
|
};
|
|
93
92
|
exports.parseLinks = parseLinks;
|
|
94
|
-
|
|
93
|
+
Parser.parsers['parseLinks'] = __filename;
|
package/dist/parser/list.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseList = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const list_1 = require("../src/nowiki/list");
|
|
6
6
|
const dd_1 = require("../src/nowiki/dd");
|
|
7
7
|
/**
|
|
@@ -10,14 +10,13 @@ const dd_1 = require("../src/nowiki/dd");
|
|
|
10
10
|
* @param config
|
|
11
11
|
* @param accum
|
|
12
12
|
*/
|
|
13
|
-
const parseList = (wikitext, config =
|
|
13
|
+
const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
14
14
|
const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
|
|
15
15
|
if (!mt) {
|
|
16
16
|
return wikitext;
|
|
17
17
|
}
|
|
18
18
|
const [total, comment, prefix] = mt;
|
|
19
19
|
let text = `${comment}\0${accum.length}d\x7F${wikitext.slice(total.length)}`, dt = prefix.split(';').length - 1;
|
|
20
|
-
// @ts-expect-error abstract class
|
|
21
20
|
new list_1.ListToken(prefix, config, accum);
|
|
22
21
|
if (!dt) {
|
|
23
22
|
return text;
|
|
@@ -27,14 +26,12 @@ const parseList = (wikitext, config = index_1.default.getConfig(), accum = []) =
|
|
|
27
26
|
const { 0: syntax, index } = ex;
|
|
28
27
|
if (syntax.startsWith(':')) {
|
|
29
28
|
if (syntax.length >= dt) {
|
|
30
|
-
// @ts-expect-error abstract class
|
|
31
29
|
new dd_1.DdToken(':'.repeat(dt), config, accum);
|
|
32
30
|
return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + dt)}`;
|
|
33
31
|
}
|
|
34
32
|
text = `${text.slice(0, index)}\0${accum.length}d\x7F${text.slice(regex.lastIndex)}`;
|
|
35
33
|
dt -= syntax.length;
|
|
36
34
|
regex.lastIndex = index + 4 + String(accum.length).length;
|
|
37
|
-
// @ts-expect-error abstract class
|
|
38
35
|
new dd_1.DdToken(syntax, config, accum);
|
|
39
36
|
}
|
|
40
37
|
else if (syntax === '-{') {
|
|
@@ -58,4 +55,4 @@ const parseList = (wikitext, config = index_1.default.getConfig(), accum = []) =
|
|
|
58
55
|
return text;
|
|
59
56
|
};
|
|
60
57
|
exports.parseList = parseList;
|
|
61
|
-
|
|
58
|
+
Parser.parsers['parseList'] = __filename;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMagicLinks = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
5
|
+
const Parser = require("../index");
|
|
6
6
|
const magicLink_1 = require("../src/magicLink");
|
|
7
7
|
/**
|
|
8
8
|
* 解析自由外链
|
|
@@ -10,7 +10,7 @@ const magicLink_1 = require("../src/magicLink");
|
|
|
10
10
|
* @param config
|
|
11
11
|
* @param accum
|
|
12
12
|
*/
|
|
13
|
-
const parseMagicLinks = (wikitext, config =
|
|
13
|
+
const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
14
14
|
const regex = new RegExp(`(?<![\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
|
|
15
15
|
return wikitext.replace(regex, (m, p1) => {
|
|
16
16
|
let trail = '', url = m;
|
|
@@ -36,4 +36,4 @@ const parseMagicLinks = (wikitext, config = index_1.default.getConfig(), accum =
|
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
exports.parseMagicLinks = parseMagicLinks;
|
|
39
|
-
|
|
39
|
+
Parser.parsers['parseMagicLinks'] = __filename;
|
package/dist/parser/quotes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseQuotes = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const quote_1 = require("../src/nowiki/quote");
|
|
6
6
|
/**
|
|
7
7
|
* 解析单引号
|
|
@@ -9,7 +9,7 @@ const quote_1 = require("../src/nowiki/quote");
|
|
|
9
9
|
* @param config
|
|
10
10
|
* @param accum
|
|
11
11
|
*/
|
|
12
|
-
const parseQuotes = (wikitext, config =
|
|
12
|
+
const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
13
13
|
const arr = wikitext.split(/('{2,})/u), { length } = arr;
|
|
14
14
|
if (length === 1) {
|
|
15
15
|
return wikitext;
|
|
@@ -57,11 +57,10 @@ const parseQuotes = (wikitext, config = index_1.default.getConfig(), accum = [])
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
for (let i = 1; i < length; i += 2) {
|
|
60
|
-
|
|
61
|
-
new quote_1.QuoteToken(arr[i].length, config, accum);
|
|
60
|
+
new quote_1.QuoteToken(arr[i], config, accum);
|
|
62
61
|
arr[i] = `\0${accum.length - 1}q\x7F`;
|
|
63
62
|
}
|
|
64
63
|
return arr.join('');
|
|
65
64
|
};
|
|
66
65
|
exports.parseQuotes = parseQuotes;
|
|
67
|
-
|
|
66
|
+
Parser.parsers['parseQuotes'] = __filename;
|
package/dist/parser/selector.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseSelector = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const simplePseudos = new Set([
|
|
6
6
|
'root',
|
|
7
7
|
'first-child',
|
|
@@ -71,10 +71,7 @@ const desanitize = (selector) => {
|
|
|
71
71
|
* 去除首尾的引号
|
|
72
72
|
* @param val 属性值或伪选择器函数的参数
|
|
73
73
|
*/
|
|
74
|
-
const deQuote = (val) =>
|
|
75
|
-
const quotes = /^(["']).*\1$/u.exec(val)?.[1];
|
|
76
|
-
return quotes ? val.slice(1, -1) : val.trim();
|
|
77
|
-
};
|
|
74
|
+
const deQuote = (val) => /^(["']).*\1$/u.exec(val)?.[1] ? val.slice(1, -1) : val.trim();
|
|
78
75
|
/**
|
|
79
76
|
* 解析简单伪选择器
|
|
80
77
|
* @param step 当前顶部
|
|
@@ -155,11 +152,11 @@ const parseSelector = (selector) => {
|
|
|
155
152
|
pushSimple(step, sanitized);
|
|
156
153
|
const pseudos = new Set(stack.flat(2).filter(e => typeof e === 'string' && e.startsWith(':')));
|
|
157
154
|
if (pseudos.size > 0) {
|
|
158
|
-
|
|
155
|
+
Parser.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
|
|
159
156
|
}
|
|
160
157
|
return stack;
|
|
161
158
|
}
|
|
162
159
|
throw new SyntaxError(`非法的选择器!\n${s}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
|
|
163
160
|
};
|
|
164
161
|
exports.parseSelector = parseSelector;
|
|
165
|
-
|
|
162
|
+
Parser.parsers['parseSelector'] = __filename;
|