wikiparser-node 1.21.2 → 1.22.0
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 +9 -5
- package/bundle/bundle-es8.min.js +25 -25
- package/bundle/bundle-lsp.min.js +26 -26
- package/bundle/bundle.min.js +25 -25
- package/config/default.json +15 -11
- package/config/enwiki.json +1 -1
- package/config/jawiki.json +1 -1
- package/config/minimum.json +2 -3
- package/config/moegirl.json +152 -15
- package/config/zhwiki.json +1 -1
- package/dist/addon/token.js +3 -0
- package/dist/base.d.mts +16 -9
- package/dist/base.d.ts +16 -9
- package/dist/bin/config.js +23 -11
- package/dist/index.d.ts +33 -4
- package/dist/index.js +37 -2
- package/dist/lib/element.d.ts +4 -4
- package/dist/lib/element.js +6 -5
- package/dist/lib/lintConfig.d.ts +13 -0
- package/dist/lib/lintConfig.js +278 -0
- package/dist/lib/lsp.d.ts +7 -7
- package/dist/lib/lsp.js +18 -20
- package/dist/lib/node.d.ts +1 -1
- package/dist/lib/node.js +646 -606
- package/dist/lib/range.d.ts +2 -2
- package/dist/lib/range.js +2 -2
- package/dist/lib/text.js +76 -62
- package/dist/lib/title.d.ts +11 -4
- package/dist/lib/title.js +16 -6
- package/dist/mixin/attributesParent.d.ts +6 -6
- package/dist/mixin/attributesParent.js +4 -4
- package/dist/mixin/cached.d.ts +5 -0
- package/dist/mixin/cached.js +22 -0
- package/dist/mixin/clone.d.ts +5 -0
- package/dist/mixin/clone.js +23 -0
- package/dist/mixin/hidden.js +68 -18
- package/dist/mixin/sol.js +1 -1
- package/dist/parser/commentAndExt.js +6 -4
- package/dist/parser/converter.js +1 -1
- package/dist/parser/html.js +3 -3
- package/dist/parser/table.js +2 -2
- package/dist/src/arg.js +24 -17
- package/dist/src/atom.js +76 -31
- package/dist/src/attribute.js +79 -39
- package/dist/src/attributes.d.ts +7 -7
- package/dist/src/attributes.js +417 -366
- package/dist/src/commented.js +81 -35
- package/dist/src/converter.js +13 -7
- package/dist/src/converterFlags.js +33 -22
- package/dist/src/converterRule.js +263 -216
- package/dist/src/extLink.js +21 -16
- package/dist/src/gallery.js +44 -27
- package/dist/src/heading.js +48 -43
- package/dist/src/hidden.js +14 -9
- package/dist/src/html.js +92 -60
- package/dist/src/imageParameter.js +13 -6
- package/dist/src/imagemap.js +32 -25
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +61 -50
- package/dist/src/link/base.d.ts +1 -1
- package/dist/src/link/base.js +35 -23
- package/dist/src/link/file.js +409 -354
- package/dist/src/link/galleryImage.js +9 -5
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/link/index.js +8 -4
- package/dist/src/link/redirectTarget.js +7 -3
- package/dist/src/magicLink.js +39 -26
- package/dist/src/nested.js +122 -74
- package/dist/src/nowiki/base.js +5 -2
- package/dist/src/nowiki/comment.js +5 -1
- package/dist/src/nowiki/index.js +4 -4
- package/dist/src/nowiki/quote.js +32 -46
- package/dist/src/onlyinclude.js +17 -9
- package/dist/src/paramTag/index.js +21 -14
- package/dist/src/parameter.js +26 -20
- package/dist/src/pre.js +91 -45
- package/dist/src/syntax.js +14 -10
- package/dist/src/table/index.js +554 -501
- package/dist/src/table/td.d.ts +1 -1
- package/dist/src/table/td.js +91 -82
- package/dist/src/table/trBase.js +183 -130
- package/dist/src/tagPair/ext.js +38 -23
- package/dist/src/tagPair/include.js +5 -5
- package/dist/src/tagPair/index.js +2 -3
- package/dist/src/tagPair/translate.js +150 -103
- package/dist/src/transclude.d.ts +15 -1
- package/dist/src/transclude.js +56 -21
- package/dist/util/html.js +46 -41
- package/dist/util/lint.js +7 -9
- package/dist/util/sharable.js +1 -1
- package/dist/util/sharable.mjs +2 -2
- package/dist/util/string.js +13 -7
- package/extensions/dist/base.js +9 -2
- package/extensions/typings.d.ts +2 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +20 -15
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
2
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
38
|
};
|
|
@@ -11,6 +45,7 @@ const atom_1 = require("./atom");
|
|
|
11
45
|
const debug_1 = require("../util/debug");
|
|
12
46
|
const constants_1 = require("../util/constants");
|
|
13
47
|
const html_1 = require("../util/html");
|
|
48
|
+
const cached_1 = require("../mixin/cached");
|
|
14
49
|
/* NOT FOR BROWSER END */
|
|
15
50
|
/**
|
|
16
51
|
* language conversion rule
|
|
@@ -18,234 +53,246 @@ const html_1 = require("../util/html");
|
|
|
18
53
|
* 转换规则
|
|
19
54
|
* @classdesc `{childNodes: AtomToken[]}`
|
|
20
55
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/* PRINT ONLY END */
|
|
32
|
-
/* NOT FOR BROWSER */
|
|
33
|
-
set variant(variant) {
|
|
34
|
-
this.setVariant(variant);
|
|
35
|
-
}
|
|
36
|
-
/** whether to be unidirectional conversion / 是否是单向转换 */
|
|
37
|
-
get unidirectional() {
|
|
38
|
-
return this.length === 3;
|
|
39
|
-
}
|
|
40
|
-
/** @throws `Error` 不能用于将双向转换或不转换更改为单向转换 */
|
|
41
|
-
set unidirectional(flag) {
|
|
42
|
-
const { length } = this;
|
|
43
|
-
if (length === 3 && !flag) {
|
|
44
|
-
this.makeBidirectional();
|
|
56
|
+
let ConverterRuleToken = (() => {
|
|
57
|
+
let _classSuper = index_2.Token;
|
|
58
|
+
let _instanceExtraInitializers = [];
|
|
59
|
+
let _toHtmlInternal_decorators;
|
|
60
|
+
return class ConverterRuleToken extends _classSuper {
|
|
61
|
+
static {
|
|
62
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
63
|
+
_toHtmlInternal_decorators = [(0, cached_1.cached)()];
|
|
64
|
+
__esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
65
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
45
66
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
/* NOT FOR BROWSER END */
|
|
68
|
+
get type() {
|
|
69
|
+
return 'converter-rule';
|
|
49
70
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
71
|
+
/* PRINT ONLY */
|
|
72
|
+
/** language variant / 语言变体 */
|
|
73
|
+
get variant() {
|
|
74
|
+
return this.childNodes[this.length - 2]?.text().trim().toLowerCase() ?? '';
|
|
53
75
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
/* PRINT ONLY END */
|
|
77
|
+
/* NOT FOR BROWSER */
|
|
78
|
+
set variant(variant) {
|
|
79
|
+
this.setVariant(variant);
|
|
80
|
+
}
|
|
81
|
+
/** whether to be unidirectional conversion / 是否是单向转换 */
|
|
82
|
+
get unidirectional() {
|
|
83
|
+
return this.length === 3;
|
|
84
|
+
}
|
|
85
|
+
/** @throws `Error` 不能用于将双向转换或不转换更改为单向转换 */
|
|
86
|
+
set unidirectional(flag) {
|
|
87
|
+
const { length } = this;
|
|
88
|
+
if (length === 3 && !flag) {
|
|
89
|
+
this.makeBidirectional();
|
|
90
|
+
}
|
|
91
|
+
else if (length === 2 && flag) {
|
|
92
|
+
throw new Error('If you want to change to unidirectional, '
|
|
93
|
+
+ 'please use ConverterRuleToken.makeUnidirectional method!');
|
|
94
|
+
}
|
|
95
|
+
else if (length === 1 && flag) {
|
|
96
|
+
throw new Error('If you want to change to unidirectional, '
|
|
97
|
+
+ 'please use ConverterRuleToken.setVariant method to specify the language variant first!');
|
|
98
|
+
}
|
|
64
99
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
100
|
+
/** whether to be bidirectional conversion / 是否是双向转换 */
|
|
101
|
+
get bidirectional() {
|
|
102
|
+
return this.length === 2;
|
|
68
103
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
/** @throws `Error` 不能用于将双向转换更改为单向转换或将不转换更改为双向转换 */
|
|
105
|
+
set bidirectional(flag) {
|
|
106
|
+
const { length } = this;
|
|
107
|
+
if (length === 3 && flag) {
|
|
108
|
+
this.makeBidirectional();
|
|
109
|
+
}
|
|
110
|
+
else if (length === 2 && !flag) {
|
|
111
|
+
throw new Error('If you want to change to unidirectional, '
|
|
112
|
+
+ 'please use ConverterRuleToken.makeUnidirectional method!');
|
|
113
|
+
}
|
|
114
|
+
else if (length === 1 && flag) {
|
|
115
|
+
throw new Error('If you want to change to bidirectional, '
|
|
116
|
+
+ 'please use ConverterRuleToken.setVariant method!');
|
|
117
|
+
}
|
|
72
118
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
119
|
+
/* NOT FOR BROWSER END */
|
|
120
|
+
/**
|
|
121
|
+
* @param rule 转换规则
|
|
122
|
+
* @param hasColon 是否带有":"
|
|
123
|
+
*/
|
|
124
|
+
constructor(rule, hasColon = true, config = index_1.default.getConfig(), accum = []) {
|
|
125
|
+
super(undefined, config, accum);
|
|
126
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
127
|
+
const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
|
|
128
|
+
if (hasColon && config.variants.includes(v.trim().toLowerCase())) {
|
|
129
|
+
super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
|
|
130
|
+
super.insertAt(new atom_1.AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
|
|
131
|
+
if (j !== -1) {
|
|
132
|
+
super.insertAt(new atom_1.AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-to', config, accum));
|
|
137
|
+
}
|
|
138
|
+
/* NOT FOR BROWSER */
|
|
139
|
+
this.protectChildren('1:');
|
|
140
|
+
}
|
|
141
|
+
/** @private */
|
|
142
|
+
toString(skip) {
|
|
143
|
+
const { childNodes, firstChild, lastChild } = this;
|
|
144
|
+
return childNodes.length === 3
|
|
145
|
+
? `${firstChild.toString(skip)}=>${childNodes[1].toString(skip)}:${lastChild.toString(skip)}`
|
|
146
|
+
: super.toString(skip, ':');
|
|
147
|
+
}
|
|
148
|
+
/** @private */
|
|
149
|
+
text() {
|
|
150
|
+
const { childNodes, firstChild, lastChild } = this;
|
|
151
|
+
return childNodes.length === 3
|
|
152
|
+
? `${firstChild.text()}=>${childNodes[1].text()}:${lastChild.text()}`
|
|
153
|
+
: super.text(':');
|
|
154
|
+
}
|
|
155
|
+
/** @private */
|
|
156
|
+
getGaps(i) {
|
|
157
|
+
return i === 0 && this.length === 3 ? 2 : 1;
|
|
158
|
+
}
|
|
159
|
+
/** @private */
|
|
160
|
+
print() {
|
|
161
|
+
const { childNodes } = this;
|
|
162
|
+
if (childNodes.length === 3) {
|
|
163
|
+
const [from, variant, to] = childNodes;
|
|
164
|
+
return `<span class="wpb-converter-rule">${from.print()}=>${variant.print()}:${to.print()}</span>`;
|
|
165
|
+
}
|
|
166
|
+
return super.print({ sep: ':' });
|
|
167
|
+
}
|
|
168
|
+
/** @private */
|
|
169
|
+
json(_, start = this.getAbsoluteIndex()) {
|
|
170
|
+
const json = super.json(undefined, start);
|
|
171
|
+
json['variant'] = this.variant;
|
|
172
|
+
return json;
|
|
91
173
|
}
|
|
92
174
|
/* NOT FOR BROWSER */
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const { childNodes } = this;
|
|
116
|
-
if (childNodes.length === 3) {
|
|
117
|
-
const [from, variant, to] = childNodes;
|
|
118
|
-
return `<span class="wpb-converter-rule">${from.print()}=>${variant.print()}:${to.print()}</span>`;
|
|
119
|
-
}
|
|
120
|
-
return super.print({ sep: ':' });
|
|
121
|
-
}
|
|
122
|
-
/** @private */
|
|
123
|
-
json(_, start = this.getAbsoluteIndex()) {
|
|
124
|
-
const json = super.json(undefined, start);
|
|
125
|
-
json['variant'] = this.variant;
|
|
126
|
-
return json;
|
|
127
|
-
}
|
|
128
|
-
/* NOT FOR BROWSER */
|
|
129
|
-
cloneNode() {
|
|
130
|
-
const cloned = this.cloneChildNodes(), placeholders = ['', 'zh:', '=>zh:'], placeholder = placeholders[cloned.length - 1];
|
|
131
|
-
return debug_1.Shadow.run(() => {
|
|
132
|
-
// @ts-expect-error abstract class
|
|
133
|
-
const token = new ConverterRuleToken(placeholder, Boolean(placeholder), this.getAttribute('config'));
|
|
134
|
-
for (let i = 0; i < cloned.length; i++) {
|
|
135
|
-
token.childNodes[i].safeReplaceWith(cloned[i]);
|
|
136
|
-
}
|
|
137
|
-
return token;
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/** @private */
|
|
141
|
-
afterBuild() {
|
|
142
|
-
super.afterBuild();
|
|
143
|
-
const /** @implements */ converterRuleListener = (e, data) => {
|
|
144
|
-
const { prevTarget } = e;
|
|
145
|
-
if (this.length > 1 && this.childNodes[this.length - 2] === prevTarget) {
|
|
146
|
-
const { variant } = this;
|
|
147
|
-
if (!this.getAttribute('config').variants.includes(variant)) {
|
|
148
|
-
(0, debug_1.undo)(e, data);
|
|
149
|
-
throw new Error(`Invalid language variant: ${variant}`);
|
|
175
|
+
cloneNode() {
|
|
176
|
+
const cloned = this.cloneChildNodes(), placeholders = ['', 'zh:', '=>zh:'], placeholder = placeholders[cloned.length - 1];
|
|
177
|
+
return debug_1.Shadow.run(() => {
|
|
178
|
+
// @ts-expect-error abstract class
|
|
179
|
+
const token = new ConverterRuleToken(placeholder, Boolean(placeholder), this.getAttribute('config'));
|
|
180
|
+
for (let i = 0; i < cloned.length; i++) {
|
|
181
|
+
token.childNodes[i].safeReplaceWith(cloned[i]);
|
|
182
|
+
}
|
|
183
|
+
return token;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/** @private */
|
|
187
|
+
afterBuild() {
|
|
188
|
+
super.afterBuild();
|
|
189
|
+
const /** @implements */ converterRuleListener = (e, data) => {
|
|
190
|
+
const { prevTarget } = e;
|
|
191
|
+
if (this.length > 1 && this.childNodes[this.length - 2] === prevTarget) {
|
|
192
|
+
const { variant } = this;
|
|
193
|
+
if (!this.getAttribute('config').variants.includes(variant)) {
|
|
194
|
+
(0, debug_1.undo)(e, data);
|
|
195
|
+
throw new Error(`Invalid language variant: ${variant}`);
|
|
196
|
+
}
|
|
150
197
|
}
|
|
198
|
+
};
|
|
199
|
+
this.addEventListener(['remove', 'insert', 'text', 'replace'], converterRuleListener);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* @override
|
|
203
|
+
* @param i position of the child node / 移除位置
|
|
204
|
+
*/
|
|
205
|
+
removeAt(i) {
|
|
206
|
+
if (this.length === 1) {
|
|
207
|
+
this.constructorError('needs at least 1 child node');
|
|
151
208
|
}
|
|
152
|
-
|
|
153
|
-
this.addEventListener(['remove', 'insert', 'text', 'replace'], converterRuleListener);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* @override
|
|
157
|
-
* @param i position of the child node / 移除位置
|
|
158
|
-
*/
|
|
159
|
-
removeAt(i) {
|
|
160
|
-
if (this.length === 1) {
|
|
161
|
-
this.constructorError('needs at least 1 child node');
|
|
162
|
-
}
|
|
163
|
-
return super.removeAt(i);
|
|
164
|
-
}
|
|
165
|
-
insertAt() {
|
|
166
|
-
this.constructorError('has complex syntax. Do not try to insert child nodes manually');
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Prevent language conversion
|
|
170
|
-
*
|
|
171
|
-
* 修改为不转换
|
|
172
|
-
*/
|
|
173
|
-
noConvert() {
|
|
174
|
-
const { length } = this;
|
|
175
|
-
for (let i = 0; i < length - 1; i++) { // ConverterRuleToken只能从前往后删除子节点
|
|
176
|
-
this.removeAt(0);
|
|
209
|
+
return super.removeAt(i);
|
|
177
210
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
* Set the target of language conversion
|
|
181
|
-
*
|
|
182
|
-
* 设置转换目标
|
|
183
|
-
* @param to target of language conversion / 转换目标
|
|
184
|
-
*/
|
|
185
|
-
setTo(to) {
|
|
186
|
-
const { childNodes } = index_1.default
|
|
187
|
-
.parse(to, this.getAttribute('include'), undefined, this.getAttribute('config'));
|
|
188
|
-
this.lastChild.safeReplaceChildren(childNodes);
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Set the language variant
|
|
192
|
-
*
|
|
193
|
-
* 设置语言变体
|
|
194
|
-
* @param variant language variant / 语言变体
|
|
195
|
-
*/
|
|
196
|
-
setVariant(variant) {
|
|
197
|
-
const config = this.getAttribute('config');
|
|
198
|
-
if (this.length === 1) {
|
|
199
|
-
super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(variant, 'converter-rule-variant', config)), 0);
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
this.childNodes[this.length - 2].setText(variant);
|
|
211
|
+
insertAt() {
|
|
212
|
+
this.constructorError('has complex syntax. Do not try to insert child nodes manually');
|
|
203
213
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (!variant) {
|
|
215
|
-
throw new Error('Please specify the language variant first!');
|
|
216
|
-
}
|
|
217
|
-
const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(from, this.getAttribute('include'), undefined, config);
|
|
218
|
-
if (!unidirectional) {
|
|
219
|
-
super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'converter-rule-from', config)), 0);
|
|
220
|
-
}
|
|
221
|
-
this.firstChild.safeReplaceChildren(childNodes);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Make the language conversion unidirectional
|
|
225
|
-
*
|
|
226
|
-
* 修改为单向转换
|
|
227
|
-
* @param from source of language conversion / 转换原文
|
|
228
|
-
*/
|
|
229
|
-
makeUnidirectional(from) {
|
|
230
|
-
this.setFrom(from);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Make the language conversion bidirectional
|
|
234
|
-
*
|
|
235
|
-
* 修改为双向转换
|
|
236
|
-
*/
|
|
237
|
-
makeBidirectional() {
|
|
238
|
-
if (this.unidirectional) {
|
|
239
|
-
this.removeAt(0);
|
|
214
|
+
/**
|
|
215
|
+
* Prevent language conversion
|
|
216
|
+
*
|
|
217
|
+
* 修改为不转换
|
|
218
|
+
*/
|
|
219
|
+
noConvert() {
|
|
220
|
+
const { length } = this;
|
|
221
|
+
for (let i = 0; i < length - 1; i++) { // ConverterRuleToken只能从前往后删除子节点
|
|
222
|
+
this.removeAt(0);
|
|
223
|
+
}
|
|
240
224
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Set the target of language conversion
|
|
227
|
+
*
|
|
228
|
+
* 设置转换目标
|
|
229
|
+
* @param to target of language conversion / 转换目标
|
|
230
|
+
*/
|
|
231
|
+
setTo(to) {
|
|
232
|
+
const { childNodes } = index_1.default
|
|
233
|
+
.parse(to, this.getAttribute('include'), undefined, this.getAttribute('config'));
|
|
234
|
+
this.lastChild.safeReplaceChildren(childNodes);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Set the language variant
|
|
238
|
+
*
|
|
239
|
+
* 设置语言变体
|
|
240
|
+
* @param variant language variant / 语言变体
|
|
241
|
+
*/
|
|
242
|
+
setVariant(variant) {
|
|
243
|
+
const config = this.getAttribute('config');
|
|
244
|
+
if (this.length === 1) {
|
|
245
|
+
super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(variant, 'converter-rule-variant', config)), 0);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
this.childNodes[this.length - 2].setText(variant);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Set the source of language conversion
|
|
253
|
+
*
|
|
254
|
+
* 设置转换原文
|
|
255
|
+
* @param from source of language conversion / 转换原文
|
|
256
|
+
* @throws `Error` 尚未指定语言变体
|
|
257
|
+
*/
|
|
258
|
+
setFrom(from) {
|
|
259
|
+
const { variant, unidirectional } = this;
|
|
260
|
+
if (!variant) {
|
|
261
|
+
throw new Error('Please specify the language variant first!');
|
|
262
|
+
}
|
|
263
|
+
const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(from, this.getAttribute('include'), undefined, config);
|
|
264
|
+
if (!unidirectional) {
|
|
265
|
+
super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'converter-rule-from', config)), 0);
|
|
266
|
+
}
|
|
267
|
+
this.firstChild.safeReplaceChildren(childNodes);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Make the language conversion unidirectional
|
|
271
|
+
*
|
|
272
|
+
* 修改为单向转换
|
|
273
|
+
* @param from source of language conversion / 转换原文
|
|
274
|
+
*/
|
|
275
|
+
makeUnidirectional(from) {
|
|
276
|
+
this.setFrom(from);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Make the language conversion bidirectional
|
|
280
|
+
*
|
|
281
|
+
* 修改为双向转换
|
|
282
|
+
*/
|
|
283
|
+
makeBidirectional() {
|
|
284
|
+
if (this.unidirectional) {
|
|
285
|
+
this.removeAt(0);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** @private */
|
|
289
|
+
toHtmlInternal(opt) {
|
|
290
|
+
const { childNodes, firstChild, lastChild } = this;
|
|
291
|
+
return childNodes.length === 3
|
|
292
|
+
? `${firstChild.toHtmlInternal(opt)}=>${childNodes[1].text()}:${lastChild.toHtmlInternal(opt)}`
|
|
293
|
+
: (0, html_1.html)(childNodes, ':', opt);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
})();
|
|
250
297
|
exports.ConverterRuleToken = ConverterRuleToken;
|
|
251
298
|
constants_1.classes['ConverterRuleToken'] = __filename;
|
package/dist/src/extLink.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
2
9
|
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
10
|
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
11
|
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
@@ -26,13 +33,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
26
33
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
34
|
done = true;
|
|
28
35
|
};
|
|
29
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
-
var useValue = arguments.length > 2;
|
|
31
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
35
|
-
};
|
|
36
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
@@ -41,12 +41,13 @@ exports.ExtLinkToken = void 0;
|
|
|
41
41
|
const constants_1 = require("../util/constants");
|
|
42
42
|
const lint_1 = require("../util/lint");
|
|
43
43
|
const padded_1 = require("../mixin/padded");
|
|
44
|
-
const index_1 = require("
|
|
44
|
+
const index_1 = __importDefault(require("../index"));
|
|
45
|
+
const index_2 = require("./index");
|
|
45
46
|
const magicLink_1 = require("./magicLink");
|
|
46
47
|
/* NOT FOR BROWSER */
|
|
47
48
|
const string_1 = require("../util/string");
|
|
48
49
|
const debug_1 = require("../util/debug");
|
|
49
|
-
const
|
|
50
|
+
const cached_1 = require("../mixin/cached");
|
|
50
51
|
/* NOT FOR BROWSER END */
|
|
51
52
|
/**
|
|
52
53
|
* external link
|
|
@@ -59,17 +60,21 @@ let ExtLinkToken = (() => {
|
|
|
59
60
|
let _classDescriptor;
|
|
60
61
|
let _classExtraInitializers = [];
|
|
61
62
|
let _classThis;
|
|
62
|
-
let _classSuper =
|
|
63
|
+
let _classSuper = index_2.Token;
|
|
64
|
+
let _instanceExtraInitializers = [];
|
|
65
|
+
let _toHtmlInternal_decorators;
|
|
63
66
|
var ExtLinkToken = class extends _classSuper {
|
|
64
67
|
static { _classThis = this; }
|
|
65
68
|
static {
|
|
66
69
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
70
|
+
_toHtmlInternal_decorators = [(0, cached_1.cached)()];
|
|
71
|
+
__esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
67
72
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
68
73
|
ExtLinkToken = _classThis = _classDescriptor.value;
|
|
69
74
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
70
75
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
71
76
|
}
|
|
72
|
-
#space;
|
|
77
|
+
#space = __runInitializers(this, _instanceExtraInitializers);
|
|
73
78
|
/* NOT FOR BROWSER END */
|
|
74
79
|
get type() {
|
|
75
80
|
return 'ext-link';
|
|
@@ -115,7 +120,7 @@ let ExtLinkToken = (() => {
|
|
|
115
120
|
this.insertAt(link);
|
|
116
121
|
this.#space = space;
|
|
117
122
|
if (text) {
|
|
118
|
-
const inner = new
|
|
123
|
+
const inner = new index_2.Token(text, config, accum, {
|
|
119
124
|
'Stage-7': ':', ConverterToken: ':',
|
|
120
125
|
});
|
|
121
126
|
inner.type = 'ext-link-text';
|
|
@@ -152,9 +157,9 @@ let ExtLinkToken = (() => {
|
|
|
152
157
|
}
|
|
153
158
|
/** @private */
|
|
154
159
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
155
|
-
const errors = super.lint(start, re);
|
|
156
|
-
if (this.length === 1 && this.closest('heading-title')) {
|
|
157
|
-
errors.push((0, lint_1.generateForSelf)(this, { start },
|
|
160
|
+
const errors = super.lint(start, re), rule = 'var-anchor', s = index_1.default.lintConfig.getSeverity(rule, 'extLink');
|
|
161
|
+
if (s && this.length === 1 && this.closest('heading-title')) {
|
|
162
|
+
errors.push((0, lint_1.generateForSelf)(this, { start }, rule, 'variable anchor in a section header', s));
|
|
158
163
|
}
|
|
159
164
|
return errors;
|
|
160
165
|
}
|
|
@@ -194,7 +199,7 @@ let ExtLinkToken = (() => {
|
|
|
194
199
|
* @param str text of the link / 链接显示文字
|
|
195
200
|
*/
|
|
196
201
|
setLinkText(str) {
|
|
197
|
-
const root =
|
|
202
|
+
const root = index_1.default
|
|
198
203
|
.parse(str, this.getAttribute('include'), 7, this.getAttribute('config'));
|
|
199
204
|
if (this.length === 1) {
|
|
200
205
|
root.type = 'ext-link-text';
|