wikiparser-node 1.4.1 → 1.4.2
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/dist/base.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -12
- package/dist/lib/element.d.ts +5 -5
- package/dist/lib/element.js +45 -37
- package/dist/lib/node.js +6 -0
- package/dist/lib/text.js +81 -40
- package/dist/lib/title.d.ts +1 -1
- package/dist/lib/title.js +13 -4
- package/dist/mixin/flagsParent.d.ts +1 -1
- package/dist/mixin/flagsParent.js +2 -0
- package/dist/mixin/magicLinkParent.d.ts +1 -1
- package/dist/mixin/magicLinkParent.js +2 -0
- package/dist/mixin/singleLine.js +2 -2
- package/dist/mixin/sol.js +2 -4
- package/dist/parser/braces.js +2 -2
- package/dist/parser/commentAndExt.js +2 -2
- package/dist/parser/converter.js +2 -2
- package/dist/parser/externalLinks.js +2 -2
- package/dist/parser/hrAndDoubleUnderscore.js +2 -2
- package/dist/parser/html.js +2 -2
- package/dist/parser/links.js +7 -5
- package/dist/parser/list.js +2 -2
- package/dist/parser/magicLinks.js +2 -2
- package/dist/parser/quotes.js +3 -3
- package/dist/parser/selector.js +2 -2
- package/dist/parser/table.js +7 -7
- package/dist/src/arg.d.ts +1 -1
- package/dist/src/arg.js +10 -9
- package/dist/src/atom.d.ts +1 -1
- package/dist/src/atom.js +4 -4
- package/dist/src/attribute.d.ts +1 -1
- package/dist/src/attribute.js +16 -17
- package/dist/src/attributes.d.ts +1 -1
- package/dist/src/attributes.js +8 -8
- package/dist/src/converter.d.ts +1 -1
- package/dist/src/converter.js +7 -8
- package/dist/src/converterFlags.d.ts +1 -1
- package/dist/src/converterFlags.js +9 -7
- package/dist/src/converterRule.d.ts +1 -1
- package/dist/src/converterRule.js +11 -10
- package/dist/src/extLink.d.ts +1 -1
- package/dist/src/extLink.js +18 -14
- package/dist/src/gallery.d.ts +2 -2
- package/dist/src/gallery.js +7 -7
- package/dist/src/heading.d.ts +1 -1
- package/dist/src/heading.js +12 -13
- package/dist/src/html.d.ts +1 -1
- package/dist/src/html.js +15 -14
- package/dist/src/imageParameter.d.ts +2 -2
- package/dist/src/imageParameter.js +12 -13
- package/dist/src/imagemap.d.ts +2 -2
- package/dist/src/imagemap.js +11 -7
- package/dist/src/imagemapLink.d.ts +1 -1
- package/dist/src/imagemapLink.js +6 -6
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +22 -9
- package/dist/src/link/base.d.ts +1 -1
- package/dist/src/link/base.js +18 -15
- package/dist/src/link/file.d.ts +1 -1
- package/dist/src/link/file.js +9 -5
- package/dist/src/link/galleryImage.d.ts +1 -1
- package/dist/src/link/galleryImage.js +10 -6
- package/dist/src/link/index.js +1 -1
- package/dist/src/magicLink.d.ts +2 -2
- package/dist/src/magicLink.js +8 -7
- package/dist/src/nested.d.ts +1 -1
- package/dist/src/nested.js +6 -5
- package/dist/src/nowiki/base.d.ts +1 -1
- package/dist/src/nowiki/base.js +4 -4
- package/dist/src/nowiki/comment.d.ts +1 -1
- package/dist/src/nowiki/comment.js +9 -6
- package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
- package/dist/src/nowiki/doubleUnderscore.js +5 -4
- package/dist/src/nowiki/hr.js +1 -0
- package/dist/src/nowiki/index.js +2 -2
- package/dist/src/nowiki/list.js +1 -0
- package/dist/src/nowiki/quote.js +3 -3
- package/dist/src/onlyinclude.js +6 -6
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +7 -7
- package/dist/src/paramTag/inputbox.d.ts +1 -1
- package/dist/src/paramTag/inputbox.js +4 -4
- package/dist/src/parameter.d.ts +1 -1
- package/dist/src/parameter.js +18 -20
- package/dist/src/pre.d.ts +1 -1
- package/dist/src/pre.js +5 -5
- package/dist/src/syntax.d.ts +1 -1
- package/dist/src/syntax.js +5 -4
- package/dist/src/table/base.d.ts +1 -1
- package/dist/src/table/base.js +6 -5
- package/dist/src/table/index.d.ts +1 -1
- package/dist/src/table/index.js +11 -6
- package/dist/src/table/td.d.ts +1 -1
- package/dist/src/table/td.js +28 -17
- package/dist/src/table/tr.d.ts +1 -1
- package/dist/src/table/tr.js +2 -2
- package/dist/src/table/trBase.js +2 -2
- package/dist/src/tagPair/ext.d.ts +1 -1
- package/dist/src/tagPair/ext.js +8 -6
- package/dist/src/tagPair/include.d.ts +1 -1
- package/dist/src/tagPair/include.js +6 -6
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +16 -13
- package/dist/src/transclude.d.ts +1 -1
- package/dist/src/transclude.js +35 -20
- package/dist/util/debug.js +7 -0
- package/dist/util/diff.js +11 -1
- package/dist/util/lint.js +2 -2
- package/package.json +1 -1
package/dist/src/table/td.js
CHANGED
|
@@ -3,11 +3,11 @@ var _a;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.createTd = exports.TdToken = void 0;
|
|
5
5
|
const lint_1 = require("../../util/lint");
|
|
6
|
-
const debug_1 = require("../../util/debug");
|
|
7
6
|
const constants_1 = require("../../util/constants");
|
|
7
|
+
const debug_1 = require("../../util/debug");
|
|
8
8
|
const fixed_1 = require("../../mixin/fixed");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const index_1 = require("../../index");
|
|
10
|
+
const index_2 = require("../index");
|
|
11
11
|
const base_1 = require("./base");
|
|
12
12
|
/**
|
|
13
13
|
* `<td>`、`<th>`和`<caption>`
|
|
@@ -43,14 +43,14 @@ class TdToken extends (0, fixed_1.fixedToken)(base_1.TableBaseToken) {
|
|
|
43
43
|
return this.lastChild.text();
|
|
44
44
|
}
|
|
45
45
|
set innerText(text) {
|
|
46
|
-
this.lastChild.replaceChildren(...
|
|
46
|
+
this.lastChild.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
|
|
47
47
|
}
|
|
48
48
|
/* NOT FOR BROWSER END */
|
|
49
49
|
/**
|
|
50
50
|
* @param syntax 单元格语法
|
|
51
51
|
* @param inner 内部wikitext
|
|
52
52
|
*/
|
|
53
|
-
constructor(syntax, inner, config =
|
|
53
|
+
constructor(syntax, inner, config = index_1.default.getConfig(), accum = []) {
|
|
54
54
|
let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
|
|
55
55
|
if (/\[\[|-\{/u.test(attr)) {
|
|
56
56
|
innerSyntax = null;
|
|
@@ -60,14 +60,18 @@ class TdToken extends (0, fixed_1.fixedToken)(base_1.TableBaseToken) {
|
|
|
60
60
|
if (innerSyntax) {
|
|
61
61
|
[this.#innerSyntax] = innerSyntax;
|
|
62
62
|
}
|
|
63
|
-
const innerToken = new
|
|
63
|
+
const innerToken = new index_2.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
|
|
64
64
|
innerToken.type = 'td-inner';
|
|
65
65
|
innerToken.setAttribute('stage', 4);
|
|
66
66
|
this.insertAt(innerToken);
|
|
67
67
|
}
|
|
68
68
|
/** 表格语法信息 */
|
|
69
69
|
#getSyntax() {
|
|
70
|
-
const syntax = this.firstChild.text(),
|
|
70
|
+
const syntax = this.firstChild.text(),
|
|
71
|
+
/* NOT FOR BROWSER */
|
|
72
|
+
esc = syntax.includes('{{'),
|
|
73
|
+
/* NOT FOR BROWSER END */
|
|
74
|
+
char = syntax.slice(-1);
|
|
71
75
|
let subtype = 'td';
|
|
72
76
|
if (char === '!') {
|
|
73
77
|
subtype = 'th';
|
|
@@ -75,6 +79,7 @@ class TdToken extends (0, fixed_1.fixedToken)(base_1.TableBaseToken) {
|
|
|
75
79
|
else if (char === '+') {
|
|
76
80
|
subtype = 'caption';
|
|
77
81
|
}
|
|
82
|
+
/* NOT FOR BROWSER */
|
|
78
83
|
if (this.isIndependent()) {
|
|
79
84
|
return { subtype, escape: esc, correction: false };
|
|
80
85
|
}
|
|
@@ -82,15 +87,17 @@ class TdToken extends (0, fixed_1.fixedToken)(base_1.TableBaseToken) {
|
|
|
82
87
|
if (!(previousSibling instanceof _a)) {
|
|
83
88
|
return { subtype, escape: esc, correction: true };
|
|
84
89
|
}
|
|
85
|
-
const result = previousSibling.#getSyntax();
|
|
90
|
+
const result = previousSibling.#getSyntax(), str = String(previousSibling.lastChild);
|
|
86
91
|
result.escape ||= esc;
|
|
87
|
-
result.correction =
|
|
88
|
-
.
|
|
89
|
-
.includes('\n');
|
|
92
|
+
result.correction = str.includes('\n') && debug_1.Shadow.run(() => {
|
|
93
|
+
const config = this.getAttribute('config'), include = this.getAttribute('include');
|
|
94
|
+
return String(new index_2.Token(str, config).parseOnce(0, include).parseOnce()).includes('\n');
|
|
95
|
+
});
|
|
90
96
|
if (subtype === 'th' && result.subtype !== 'th') {
|
|
91
97
|
result.subtype = 'th';
|
|
92
98
|
result.correction = true;
|
|
93
99
|
}
|
|
100
|
+
/* NOT FOR BROWSER END */
|
|
94
101
|
return result;
|
|
95
102
|
}
|
|
96
103
|
/** @private */
|
|
@@ -100,23 +107,27 @@ class TdToken extends (0, fixed_1.fixedToken)(base_1.TableBaseToken) {
|
|
|
100
107
|
}
|
|
101
108
|
}
|
|
102
109
|
/** @private */
|
|
103
|
-
toString(
|
|
110
|
+
toString() {
|
|
111
|
+
/* NOT FOR BROWSER */
|
|
104
112
|
this.#correct();
|
|
113
|
+
/* NOT FOR BROWSER END */
|
|
105
114
|
const { childNodes: [syntax, attr, inner] } = this;
|
|
106
|
-
return
|
|
107
|
-
? ''
|
|
108
|
-
: `${syntax.toString(omit)}${attr.toString(omit)}${this.#innerSyntax}${inner.toString(omit)}`;
|
|
115
|
+
return `${String(syntax)}${String(attr)}${this.#innerSyntax}${String(inner)}`;
|
|
109
116
|
}
|
|
110
117
|
/** @override */
|
|
111
118
|
text() {
|
|
119
|
+
/* NOT FOR BROWSER */
|
|
112
120
|
this.#correct();
|
|
121
|
+
/* NOT FOR BROWSER END */
|
|
113
122
|
const { childNodes: [syntax, attr, inner] } = this;
|
|
114
123
|
return `${syntax.text()}${attr.text()}${this.#innerSyntax}${inner.text()}`;
|
|
115
124
|
}
|
|
116
125
|
/** @private */
|
|
117
126
|
getGaps(i) {
|
|
118
127
|
if (i === 1) {
|
|
128
|
+
/* NOT FOR BROWSER */
|
|
119
129
|
this.#correct();
|
|
130
|
+
/* NOT FOR BROWSER END */
|
|
120
131
|
return this.#innerSyntax.length;
|
|
121
132
|
}
|
|
122
133
|
return 0;
|
|
@@ -259,8 +270,8 @@ _a = TdToken;
|
|
|
259
270
|
* @param include 是否嵌入
|
|
260
271
|
* @param config
|
|
261
272
|
*/
|
|
262
|
-
const createTd = (inner, subtype = 'td', attr = {}, include = false, config =
|
|
263
|
-
const innerToken = typeof inner === 'string' ?
|
|
273
|
+
const createTd = (inner, subtype = 'td', attr = {}, include = false, config = index_1.default.getConfig()) => {
|
|
274
|
+
const innerToken = typeof inner === 'string' ? index_1.default.parse(inner, include, undefined, config) : inner,
|
|
264
275
|
// @ts-expect-error abstract class
|
|
265
276
|
token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
|
|
266
277
|
token.setSyntax(subtype);
|
package/dist/src/table/tr.d.ts
CHANGED
package/dist/src/table/tr.js
CHANGED
|
@@ -3,7 +3,7 @@ var _a;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.TrToken = void 0;
|
|
5
5
|
const constants_1 = require("../../util/constants");
|
|
6
|
-
const
|
|
6
|
+
const index_1 = require("../../index");
|
|
7
7
|
const trBase_1 = require("./trBase");
|
|
8
8
|
/**
|
|
9
9
|
* 表格行,含开头的换行,不含结尾的换行
|
|
@@ -15,7 +15,7 @@ class TrToken extends trBase_1.TrBaseToken {
|
|
|
15
15
|
* @param syntax 表格语法
|
|
16
16
|
* @param attr 表格属性
|
|
17
17
|
*/
|
|
18
|
-
constructor(syntax, attr, config =
|
|
18
|
+
constructor(syntax, attr, config = index_1.default.getConfig(), accum = []) {
|
|
19
19
|
super(/^\n[^\S\n]*(?:\|-+|\{\{\s*!\s*\}\}-+|\{\{\s*!-\s*\}\}-*)$/u, syntax, attr, config, accum, {
|
|
20
20
|
Token: 2, SyntaxToken: 0, AttributesToken: 1, TdToken: '2:',
|
|
21
21
|
});
|
package/dist/src/table/trBase.js
CHANGED
package/dist/src/tagPair/ext.js
CHANGED
|
@@ -5,9 +5,9 @@ const lint_1 = require("../../util/lint");
|
|
|
5
5
|
const debug_1 = require("../../util/debug");
|
|
6
6
|
const constants_1 = require("../../util/constants");
|
|
7
7
|
const attributesParent_1 = require("../../mixin/attributesParent");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
8
|
+
const index_1 = require("../../index");
|
|
9
|
+
const index_2 = require("../index");
|
|
10
|
+
const index_3 = require("./index");
|
|
11
11
|
const attributes_1 = require("../attributes");
|
|
12
12
|
/**
|
|
13
13
|
* 从数组中删除指定元素
|
|
@@ -19,11 +19,12 @@ const del = (arr, ele) => {
|
|
|
19
19
|
set.delete(ele);
|
|
20
20
|
return [...set];
|
|
21
21
|
};
|
|
22
|
+
/* NOT FOR BROWSER END */
|
|
22
23
|
/**
|
|
23
24
|
* 扩展标签
|
|
24
25
|
* @classdesc `{childNodes: [AttributesToken, Token]}`
|
|
25
26
|
*/
|
|
26
|
-
class ExtToken extends (0, attributesParent_1.attributesParent)(
|
|
27
|
+
class ExtToken extends (0, attributesParent_1.attributesParent)(index_3.TagPairToken) {
|
|
27
28
|
type = 'ext';
|
|
28
29
|
/**
|
|
29
30
|
* @param name 标签名
|
|
@@ -31,7 +32,7 @@ class ExtToken extends (0, attributesParent_1.attributesParent)(index_2.TagPairT
|
|
|
31
32
|
* @param inner 内部wikitext
|
|
32
33
|
* @param closed 是否封闭
|
|
33
34
|
*/
|
|
34
|
-
constructor(name, attr, inner, closed, config =
|
|
35
|
+
constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
|
|
35
36
|
const lcName = name.toLowerCase(),
|
|
36
37
|
// @ts-expect-error abstract class
|
|
37
38
|
attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
|
|
@@ -51,7 +52,7 @@ class ExtToken extends (0, attributesParent_1.attributesParent)(index_2.TagPairT
|
|
|
51
52
|
if (lcName === 'poem') {
|
|
52
53
|
newConfig.excludes.push('heading');
|
|
53
54
|
}
|
|
54
|
-
innerToken = new
|
|
55
|
+
innerToken = new index_2.Token(inner, newConfig, accum);
|
|
55
56
|
break;
|
|
56
57
|
case 'pre': {
|
|
57
58
|
const { PreToken } = require('../pre');
|
|
@@ -119,6 +120,7 @@ class ExtToken extends (0, attributesParent_1.attributesParent)(index_2.TagPairT
|
|
|
119
120
|
innerToken.setAttribute('name', lcName);
|
|
120
121
|
innerToken.type = 'ext-inner';
|
|
121
122
|
super(name, attrToken, innerToken, closed, config, accum);
|
|
123
|
+
/* istanbul ignore next */
|
|
122
124
|
this.seal('closed', true);
|
|
123
125
|
}
|
|
124
126
|
/** @override */
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IncludeToken = void 0;
|
|
4
|
+
const lint_1 = require("../../util/lint");
|
|
4
5
|
const debug_1 = require("../../util/debug");
|
|
5
6
|
const constants_1 = require("../../util/constants");
|
|
6
|
-
const lint_1 = require("../../util/lint");
|
|
7
7
|
const hidden_1 = require("../../mixin/hidden");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const index_1 = require("../../index");
|
|
9
|
+
const index_2 = require("./index");
|
|
10
10
|
/**
|
|
11
11
|
* `<includeonly>`或`<noinclude>`或`<onlyinclude>`
|
|
12
12
|
* @classdesc `{childNodes: [AstText, AstText]}`
|
|
13
13
|
*/
|
|
14
|
-
class IncludeToken extends (0, hidden_1.hiddenToken)(
|
|
14
|
+
class IncludeToken extends (0, hidden_1.hiddenToken)(index_2.TagPairToken) {
|
|
15
15
|
type = 'include';
|
|
16
16
|
/* NOT FOR BROWSER */
|
|
17
17
|
/** @override */
|
|
@@ -34,12 +34,12 @@ class IncludeToken extends (0, hidden_1.hiddenToken)(index_1.TagPairToken) {
|
|
|
34
34
|
* @param inner 内部wikitext
|
|
35
35
|
* @param closed 是否封闭
|
|
36
36
|
*/
|
|
37
|
-
constructor(name, attr = '', inner, closed, config =
|
|
37
|
+
constructor(name, attr = '', inner, closed, config = index_1.default.getConfig(), accum = []) {
|
|
38
38
|
super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
|
|
39
39
|
}
|
|
40
40
|
/** @override */
|
|
41
41
|
lint(start = this.getAbsoluteIndex()) {
|
|
42
|
-
return this.closed ? [] : [(0, lint_1.generateForSelf)(this, { start },
|
|
42
|
+
return this.closed ? [] : [(0, lint_1.generateForSelf)(this, { start }, index_1.default.msg('unclosed $1', `<${this.name}>`))];
|
|
43
43
|
}
|
|
44
44
|
/** @override */
|
|
45
45
|
json() {
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TagPairToken = void 0;
|
|
4
4
|
const constants_1 = require("../../util/constants");
|
|
5
5
|
const fixed_1 = require("../../mixin/fixed");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const index_1 = require("../../index");
|
|
7
|
+
const index_2 = require("../index");
|
|
8
8
|
/** 成对标签 */
|
|
9
|
-
class TagPairToken extends (0, fixed_1.fixedToken)(
|
|
9
|
+
class TagPairToken extends (0, fixed_1.fixedToken)(index_2.Token) {
|
|
10
10
|
#tags;
|
|
11
11
|
closed;
|
|
12
12
|
selfClosing;
|
|
@@ -21,7 +21,7 @@ class TagPairToken extends (0, fixed_1.fixedToken)(index_1.Token) {
|
|
|
21
21
|
* @param inner 内部wikitext
|
|
22
22
|
* @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
|
|
23
23
|
*/
|
|
24
|
-
constructor(name, attr, inner, closed, config =
|
|
24
|
+
constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
|
|
25
25
|
super(undefined, config);
|
|
26
26
|
this.setAttribute('name', name.toLowerCase());
|
|
27
27
|
this.#tags = [name, closed || name];
|
|
@@ -33,18 +33,19 @@ class TagPairToken extends (0, fixed_1.fixedToken)(index_1.Token) {
|
|
|
33
33
|
Object.defineProperty(this, 'closed', { enumerable: false });
|
|
34
34
|
}
|
|
35
35
|
/** @private */
|
|
36
|
-
toString(
|
|
37
|
-
const { selfClosing, firstChild, lastChild,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
toString() {
|
|
37
|
+
const { selfClosing, firstChild, lastChild,
|
|
38
|
+
/* NOT FOR BROWSER */
|
|
39
|
+
nextSibling, name, closed, } = this, [opening, closing] = this.#tags;
|
|
40
|
+
/* NOT FOR BROWSER */
|
|
41
|
+
if (!closed && nextSibling) {
|
|
42
|
+
index_1.default.error(`自动闭合 <${name}>`, lastChild);
|
|
43
43
|
this.closed = true;
|
|
44
44
|
}
|
|
45
|
+
/* NOT FOR BROWSER END */
|
|
45
46
|
return selfClosing
|
|
46
|
-
? `<${opening}${firstChild
|
|
47
|
-
: `<${opening}${firstChild
|
|
47
|
+
? `<${opening}${String(firstChild)}/>`
|
|
48
|
+
: `<${opening}${String(firstChild)}>${String(lastChild)}${this.closed ? `</${closing}>` : ''}`;
|
|
48
49
|
}
|
|
49
50
|
/** @override */
|
|
50
51
|
text() {
|
|
@@ -55,9 +56,11 @@ class TagPairToken extends (0, fixed_1.fixedToken)(index_1.Token) {
|
|
|
55
56
|
}
|
|
56
57
|
/** @private */
|
|
57
58
|
getAttribute(key) {
|
|
59
|
+
/* NOT FOR BROWSER */
|
|
58
60
|
if (key === 'tags') {
|
|
59
61
|
return [...this.#tags];
|
|
60
62
|
}
|
|
63
|
+
/* NOT FOR BROWSER END */
|
|
61
64
|
return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
|
|
62
65
|
}
|
|
63
66
|
/** @private */
|
package/dist/src/transclude.d.ts
CHANGED
package/dist/src/transclude.js
CHANGED
|
@@ -5,8 +5,8 @@ const string_1 = require("../util/string");
|
|
|
5
5
|
const lint_1 = require("../util/lint");
|
|
6
6
|
const debug_1 = require("../util/debug");
|
|
7
7
|
const constants_1 = require("../util/constants");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const index_1 = require("../index");
|
|
9
|
+
const index_2 = require("./index");
|
|
10
10
|
const parameter_1 = require("./parameter");
|
|
11
11
|
const atom_1 = require("./atom");
|
|
12
12
|
const syntax_1 = require("./syntax");
|
|
@@ -22,8 +22,9 @@ const insensitiveVars = new Set([
|
|
|
22
22
|
* 模板或魔术字
|
|
23
23
|
* @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
|
|
24
24
|
*/
|
|
25
|
-
class TranscludeToken extends
|
|
25
|
+
class TranscludeToken extends index_2.Token {
|
|
26
26
|
type = 'template';
|
|
27
|
+
/* NOT FOR BROWSER END */
|
|
27
28
|
modifier = '';
|
|
28
29
|
#raw = false;
|
|
29
30
|
#args = new Map();
|
|
@@ -45,11 +46,13 @@ class TranscludeToken extends index_1.Token {
|
|
|
45
46
|
* @param parts 参数各部分
|
|
46
47
|
* @throws `SyntaxError` 非法的模板名称
|
|
47
48
|
*/
|
|
48
|
-
constructor(title, parts, config =
|
|
49
|
+
constructor(title, parts, config = index_1.default.getConfig(), accum = []) {
|
|
49
50
|
super(undefined, config, accum, {
|
|
50
51
|
AtomToken: 0, SyntaxToken: 0, ParameterToken: '1:',
|
|
51
52
|
});
|
|
53
|
+
/* NOT FOR BROWSER */
|
|
52
54
|
this.seal('modifier');
|
|
55
|
+
/* NOT FOR BROWSER END */
|
|
53
56
|
const { parserFunction: [insensitive, sensitive] } = config, argSubst = /^(?:\s|\0\d+c\x7F)*\0\d+s\x7F/u.exec(title)?.[0];
|
|
54
57
|
if (argSubst) {
|
|
55
58
|
this.setAttribute('modifier', argSubst);
|
|
@@ -75,7 +78,9 @@ class TranscludeToken extends index_1.Token {
|
|
|
75
78
|
parts.unshift([arg.join(':')]);
|
|
76
79
|
}
|
|
77
80
|
if (this.name === 'invoke') {
|
|
81
|
+
/* NOT FOR BROWSER */
|
|
78
82
|
this.setAttribute('acceptable', { SyntaxToken: 0, AtomToken: '1:3', ParameterToken: '3:' });
|
|
83
|
+
/* NOT FOR BROWSER END */
|
|
79
84
|
for (let i = 0; i < 2; i++) {
|
|
80
85
|
const part = parts.shift();
|
|
81
86
|
if (!part) {
|
|
@@ -84,6 +89,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
84
89
|
const invoke = new atom_1.AtomToken(part.join('='), `invoke-${i ? 'function' : 'module'}`, config, accum, { 'Stage-1': ':', '!ExtToken': '' });
|
|
85
90
|
super.insertAt(invoke);
|
|
86
91
|
}
|
|
92
|
+
/* NOT FOR BROWSER */
|
|
87
93
|
this.protectChildren('1:3');
|
|
88
94
|
}
|
|
89
95
|
}
|
|
@@ -92,7 +98,9 @@ class TranscludeToken extends index_1.Token {
|
|
|
92
98
|
const name = (0, string_1.removeComment)((0, string_1.decodeHtml)(title)).split('#')[0].trim();
|
|
93
99
|
if (!name || /^:[\s_]*:|\0\d+[eh!+-]\x7F|[<>[\]{}\n]|%[\da-f]{2}/iu.test(name)) {
|
|
94
100
|
accum.pop();
|
|
95
|
-
|
|
101
|
+
/* NOT FOR BROWSER */
|
|
102
|
+
index_1.default.debug(`非法的模板名称:${(0, string_1.noWrap)(name)}`);
|
|
103
|
+
/* NOT FOR BROWSER END */
|
|
96
104
|
throw new SyntaxError('非法的模板名称');
|
|
97
105
|
}
|
|
98
106
|
const token = new atom_1.AtomToken(title, 'template-name', config, accum, {
|
|
@@ -115,6 +123,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
115
123
|
// @ts-expect-error abstract class
|
|
116
124
|
this.insertAt(new parameter_1.ParameterToken(...part, config, accum));
|
|
117
125
|
}
|
|
126
|
+
/* NOT FOR BROWSER */
|
|
118
127
|
this.protectChildren(0);
|
|
119
128
|
}
|
|
120
129
|
/**
|
|
@@ -150,6 +159,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
150
159
|
if (this.modifier.includes('\0')) {
|
|
151
160
|
this.setAttribute('modifier', this.buildFromStr(this.modifier, constants_1.BuildMethod.String));
|
|
152
161
|
}
|
|
162
|
+
/* NOT FOR BROWSER */
|
|
153
163
|
if (this.isTemplate()) {
|
|
154
164
|
const isTemplate = this.type === 'template';
|
|
155
165
|
if (isTemplate || this.length > 1) {
|
|
@@ -184,13 +194,10 @@ class TranscludeToken extends index_1.Token {
|
|
|
184
194
|
}
|
|
185
195
|
}
|
|
186
196
|
/** @private */
|
|
187
|
-
toString(
|
|
188
|
-
if (omit && this.matchesTypes(omit)) {
|
|
189
|
-
return '';
|
|
190
|
-
}
|
|
197
|
+
toString() {
|
|
191
198
|
return `{{${this.modifier}${this.type === 'magic-word'
|
|
192
|
-
? `${this.firstChild
|
|
193
|
-
: super.toString(
|
|
199
|
+
? `${String(this.firstChild)}${this.length === 1 ? '' : ':'}${this.childNodes.slice(1).map(String).join('|')}`
|
|
200
|
+
: super.toString('|')}}}`;
|
|
194
201
|
}
|
|
195
202
|
/** @override */
|
|
196
203
|
text() {
|
|
@@ -206,10 +213,12 @@ class TranscludeToken extends index_1.Token {
|
|
|
206
213
|
switch (key) {
|
|
207
214
|
case 'padding':
|
|
208
215
|
return this.modifier.length + 2;
|
|
216
|
+
/* NOT FOR BROWSER */
|
|
209
217
|
case 'args':
|
|
210
218
|
return new Map(this.#args);
|
|
211
219
|
case 'keys':
|
|
212
220
|
return this.#keys;
|
|
221
|
+
/* NOT FOR BROWSER END */
|
|
213
222
|
default:
|
|
214
223
|
return super.getAttribute(key);
|
|
215
224
|
}
|
|
@@ -252,6 +261,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
252
261
|
*/
|
|
253
262
|
#handleAnonArgChange(addedToken) {
|
|
254
263
|
const args = this.getAnonArgs(), added = typeof addedToken !== 'number';
|
|
264
|
+
/* NOT FOR BROWSER */
|
|
255
265
|
const maxAnon = String(args.length + (added ? 0 : 1));
|
|
256
266
|
if (added) {
|
|
257
267
|
this.#keys.add(maxAnon);
|
|
@@ -259,11 +269,13 @@ class TranscludeToken extends index_1.Token {
|
|
|
259
269
|
else if (!this.hasArg(maxAnon, true)) {
|
|
260
270
|
this.#keys.delete(maxAnon);
|
|
261
271
|
}
|
|
272
|
+
/* NOT FOR BROWSER END */
|
|
262
273
|
for (let i = added ? args.indexOf(addedToken) : addedToken - 1; i < args.length; i++) {
|
|
263
274
|
const token = args[i], { name } = token, newName = String(i + 1);
|
|
264
275
|
if (name !== newName) {
|
|
265
276
|
token.setAttribute('name', newName);
|
|
266
277
|
this.getArgs(newName, false, false).add(token);
|
|
278
|
+
/* NOT FOR BROWSER */
|
|
267
279
|
if (name) {
|
|
268
280
|
this.getArgs(name, false, false).delete(token);
|
|
269
281
|
}
|
|
@@ -282,6 +294,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
282
294
|
}
|
|
283
295
|
else if (token.name) {
|
|
284
296
|
this.getArgs(token.name, false, false).add(token);
|
|
297
|
+
/* NOT FOR BROWSER */
|
|
285
298
|
this.#keys.add(token.name);
|
|
286
299
|
}
|
|
287
300
|
return token;
|
|
@@ -310,12 +323,14 @@ class TranscludeToken extends index_1.Token {
|
|
|
310
323
|
args = new Set(this.getAllArgs().filter(({ name }) => keyStr === name));
|
|
311
324
|
this.#args.set(keyStr, args);
|
|
312
325
|
}
|
|
326
|
+
/* NOT FOR BROWSER */
|
|
313
327
|
if (exact && !Number.isNaN(Number(keyStr))) {
|
|
314
328
|
args = new Set([...args].filter(({ anon }) => typeof key === 'number' === anon));
|
|
315
329
|
}
|
|
316
330
|
else if (copy) {
|
|
317
331
|
args = new Set(args);
|
|
318
332
|
}
|
|
333
|
+
/* NOT FOR BROWSER END */
|
|
319
334
|
return args;
|
|
320
335
|
}
|
|
321
336
|
/**
|
|
@@ -485,7 +500,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
485
500
|
* @param val 参数值
|
|
486
501
|
*/
|
|
487
502
|
newAnonArg(val) {
|
|
488
|
-
const config = this.getAttribute('config'), { childNodes } =
|
|
503
|
+
const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(val, this.getAttribute('include'), undefined, config),
|
|
489
504
|
// @ts-expect-error abstract class
|
|
490
505
|
token = debug_1.Shadow.run(() => new parameter_1.ParameterToken(undefined, undefined, config));
|
|
491
506
|
token.lastChild.append(...childNodes);
|
|
@@ -507,7 +522,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
507
522
|
arg.setValue(value);
|
|
508
523
|
return;
|
|
509
524
|
}
|
|
510
|
-
const include = this.getAttribute('include'), config = this.getAttribute('config'), k =
|
|
525
|
+
const include = this.getAttribute('include'), config = this.getAttribute('config'), k = index_1.default.parse(key, include, undefined, config), v = index_1.default.parse(value, include, undefined, config),
|
|
511
526
|
// @ts-expect-error abstract class
|
|
512
527
|
token = debug_1.Shadow.run(() => new parameter_1.ParameterToken(undefined, undefined, config));
|
|
513
528
|
token.firstChild.append(...k.childNodes);
|
|
@@ -536,7 +551,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
536
551
|
if (this.type === 'magic-word') {
|
|
537
552
|
throw new Error('replaceTemplate 方法仅用于更换模板!');
|
|
538
553
|
}
|
|
539
|
-
const { childNodes } =
|
|
554
|
+
const { childNodes } = index_1.default.parse(title, this.getAttribute('include'), 2, this.getAttribute('config'));
|
|
540
555
|
this.firstChild.replaceChildren(...childNodes);
|
|
541
556
|
}
|
|
542
557
|
/**
|
|
@@ -555,7 +570,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
555
570
|
}));
|
|
556
571
|
return;
|
|
557
572
|
}
|
|
558
|
-
const { childNodes } =
|
|
573
|
+
const { childNodes } = index_1.default.parse(title, this.getAttribute('include'), 2, config);
|
|
559
574
|
this.childNodes[1].replaceChildren(...childNodes);
|
|
560
575
|
}
|
|
561
576
|
/**
|
|
@@ -578,7 +593,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
578
593
|
}));
|
|
579
594
|
return;
|
|
580
595
|
}
|
|
581
|
-
const { childNodes } =
|
|
596
|
+
const { childNodes } = index_1.default.parse(func, this.getAttribute('include'), 2, config);
|
|
582
597
|
this.childNodes[2].replaceChildren(...childNodes);
|
|
583
598
|
}
|
|
584
599
|
/**
|
|
@@ -602,7 +617,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
602
617
|
return [];
|
|
603
618
|
}
|
|
604
619
|
const duplicatedKeys = [];
|
|
605
|
-
let
|
|
620
|
+
let anonCount = this.getAnonArgs().length;
|
|
606
621
|
for (const [key, args] of this.getDuplicatedArgs()) {
|
|
607
622
|
if (args.length <= 1) {
|
|
608
623
|
continue;
|
|
@@ -661,7 +676,7 @@ class TranscludeToken extends index_1.Token {
|
|
|
661
676
|
}
|
|
662
677
|
}
|
|
663
678
|
if (remaining > 1) {
|
|
664
|
-
|
|
679
|
+
index_1.default.error(`${this.type === 'template'
|
|
665
680
|
? this.name
|
|
666
681
|
: this.normalizeTitle(this.childNodes[1].text(), 828)
|
|
667
682
|
.title} 还留有 ${remaining} 个重复的 ${key} 参数:${[...this.getArgs(key)].map(arg => {
|
|
@@ -682,13 +697,13 @@ class TranscludeToken extends index_1.Token {
|
|
|
682
697
|
if (!/\n[^\S\n]*(?::+[^\S\n]*)?\{\|/u.test(this.text())) {
|
|
683
698
|
return this;
|
|
684
699
|
}
|
|
685
|
-
const stripped = String(this).slice(2, -2), include = this.getAttribute('include'), config = this.getAttribute('config'), parsed =
|
|
700
|
+
const stripped = String(this).slice(2, -2), include = this.getAttribute('include'), config = this.getAttribute('config'), parsed = index_1.default.parse(stripped, include, 4, config), isTable = (0, debug_1.isToken)('table');
|
|
686
701
|
for (const table of parsed.childNodes) {
|
|
687
702
|
if (isTable(table)) {
|
|
688
703
|
table.escape();
|
|
689
704
|
}
|
|
690
705
|
}
|
|
691
|
-
const { firstChild, length } =
|
|
706
|
+
const { firstChild, length } = index_1.default.parse(`{{${String(parsed)}}}`, include, undefined, config);
|
|
692
707
|
if (length !== 1 || !(firstChild instanceof TranscludeToken)) {
|
|
693
708
|
throw new Error('转义表格失败!');
|
|
694
709
|
}
|
package/dist/util/debug.js
CHANGED
|
@@ -7,12 +7,17 @@ exports.Shadow = {
|
|
|
7
7
|
/* NOT FOR BROWSER END */
|
|
8
8
|
/** @private */
|
|
9
9
|
run(callback) {
|
|
10
|
+
/* NOT FOR BROWSER */
|
|
10
11
|
const { running } = this;
|
|
11
12
|
this.running = true;
|
|
12
13
|
try {
|
|
14
|
+
/* NOT FOR BROWSER END */
|
|
13
15
|
const result = callback();
|
|
16
|
+
/* NOT FOR BROWSER */
|
|
14
17
|
this.running = running;
|
|
18
|
+
/* NOT FOR BROWSER END */
|
|
15
19
|
return result;
|
|
20
|
+
/* NOT FOR BROWSER */
|
|
16
21
|
}
|
|
17
22
|
catch (e) {
|
|
18
23
|
this.running = running;
|
|
@@ -39,9 +44,11 @@ const setChildNodes = (parent, position, deleteCount, inserted = []) => {
|
|
|
39
44
|
for (const node of inserted) {
|
|
40
45
|
node.setAttribute('parentNode', parent);
|
|
41
46
|
}
|
|
47
|
+
/* NOT FOR BROWSER */
|
|
42
48
|
for (const node of removed) {
|
|
43
49
|
node.setAttribute('parentNode', undefined);
|
|
44
50
|
}
|
|
51
|
+
/* NOT FOR BROWSER END */
|
|
45
52
|
return removed;
|
|
46
53
|
};
|
|
47
54
|
exports.setChildNodes = setChildNodes;
|
package/dist/util/diff.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.diff = exports.cmd = void 0;
|
|
3
|
+
exports.info = exports.error = exports.diff = exports.cmd = void 0;
|
|
4
4
|
const fs = require("fs/promises");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
process.on('unhandledRejection', e => {
|
|
@@ -70,3 +70,13 @@ const diff = async (oldStr, newStr, uid = -1) => {
|
|
|
70
70
|
console.log(stdout?.split('\n').slice(4).join('\n'));
|
|
71
71
|
};
|
|
72
72
|
exports.diff = diff;
|
|
73
|
+
/** @implements */
|
|
74
|
+
const error = (msg, ...args) => {
|
|
75
|
+
console.error('\x1B[31m%s\x1B[0m', msg, ...args);
|
|
76
|
+
};
|
|
77
|
+
exports.error = error;
|
|
78
|
+
/** @implements */
|
|
79
|
+
const info = (msg, ...args) => {
|
|
80
|
+
console.info('\x1B[32m%s\x1B[0m', msg, ...args);
|
|
81
|
+
};
|
|
82
|
+
exports.info = info;
|
package/dist/util/lint.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateForSelf = exports.generateForChild = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
/**
|
|
6
6
|
* 生成lint函数
|
|
7
7
|
* @param func lint函数
|
|
@@ -9,7 +9,7 @@ const Parser = require("../index");
|
|
|
9
9
|
const factory = (func) => (token, boundingRect, msg, severity = 'error') => {
|
|
10
10
|
const { start } = boundingRect, { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start), { offsetHeight, offsetWidth } = token, { startIndex, startLine, startCol } = func(token, start, top, left);
|
|
11
11
|
return {
|
|
12
|
-
message:
|
|
12
|
+
message: index_1.default.msg(msg),
|
|
13
13
|
severity,
|
|
14
14
|
startIndex,
|
|
15
15
|
endIndex: startIndex + String(token).length,
|