wikiparser-node 1.0.0-beta.3 → 1.0.1-b
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 +10 -9
- package/bundle/bundle.min.js +37 -0
- package/config/llwiki.json +1 -35
- package/config/minimum.json +136 -0
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +105 -0
- package/extensions/dist/editor.js +172 -0
- package/extensions/dist/highlight.js +46 -0
- package/extensions/dist/lint.js +43 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +119 -0
- package/package.json +35 -20
- package/config/.schema.json +0 -160
- package/dist/index.d.ts +0 -62
- package/dist/index.js +0 -305
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -186
- package/dist/lib/element.js +0 -659
- package/dist/lib/node.d.ts +0 -178
- package/dist/lib/node.js +0 -458
- package/dist/lib/range.d.ts +0 -132
- package/dist/lib/range.js +0 -387
- package/dist/lib/ranges.d.ts +0 -28
- package/dist/lib/ranges.js +0 -125
- package/dist/lib/text.d.ts +0 -78
- package/dist/lib/text.js +0 -227
- package/dist/lib/title.d.ts +0 -33
- package/dist/lib/title.js +0 -110
- package/dist/mixin/attributesParent.js +0 -93
- package/dist/mixin/fixed.js +0 -32
- package/dist/mixin/hidden.js +0 -23
- package/dist/mixin/singleLine.js +0 -26
- package/dist/mixin/sol.js +0 -44
- package/dist/parser/braces.js +0 -125
- package/dist/parser/commentAndExt.js +0 -58
- package/dist/parser/converter.js +0 -38
- package/dist/parser/externalLinks.js +0 -28
- package/dist/parser/hrAndDoubleUnderscore.js +0 -40
- package/dist/parser/html.js +0 -38
- package/dist/parser/links.js +0 -94
- package/dist/parser/list.js +0 -61
- package/dist/parser/magicLinks.js +0 -39
- package/dist/parser/quotes.js +0 -67
- package/dist/parser/selector.js +0 -165
- package/dist/parser/table.js +0 -117
- package/dist/src/arg.d.ts +0 -77
- package/dist/src/arg.js +0 -199
- package/dist/src/atom.d.ts +0 -11
- package/dist/src/atom.js +0 -24
- package/dist/src/attribute.d.ts +0 -106
- package/dist/src/attribute.js +0 -436
- package/dist/src/attributes.d.ts +0 -119
- package/dist/src/attributes.js +0 -366
- package/dist/src/converter.d.ts +0 -75
- package/dist/src/converter.js +0 -141
- package/dist/src/converterFlags.d.ts +0 -107
- package/dist/src/converterFlags.js +0 -238
- package/dist/src/converterRule.d.ts +0 -96
- package/dist/src/converterRule.js +0 -255
- package/dist/src/extLink.d.ts +0 -63
- package/dist/src/extLink.js +0 -157
- package/dist/src/gallery.d.ts +0 -70
- package/dist/src/gallery.js +0 -137
- package/dist/src/heading.d.ts +0 -82
- package/dist/src/heading.js +0 -135
- package/dist/src/hidden.d.ts +0 -19
- package/dist/src/hidden.js +0 -26
- package/dist/src/html.d.ts +0 -113
- package/dist/src/html.js +0 -245
- package/dist/src/imageParameter.d.ts +0 -82
- package/dist/src/imageParameter.js +0 -256
- package/dist/src/imagemap.d.ts +0 -77
- package/dist/src/imagemap.js +0 -169
- package/dist/src/imagemapLink.d.ts +0 -48
- package/dist/src/imagemapLink.js +0 -43
- package/dist/src/index.d.ts +0 -156
- package/dist/src/index.js +0 -819
- package/dist/src/link/base.d.ts +0 -69
- package/dist/src/link/base.js +0 -231
- package/dist/src/link/category.d.ts +0 -14
- package/dist/src/link/category.js +0 -28
- package/dist/src/link/file.d.ts +0 -105
- package/dist/src/link/file.js +0 -269
- package/dist/src/link/galleryImage.d.ts +0 -37
- package/dist/src/link/galleryImage.js +0 -100
- package/dist/src/link/index.d.ts +0 -50
- package/dist/src/link/index.js +0 -134
- package/dist/src/magicLink.d.ts +0 -46
- package/dist/src/magicLink.js +0 -131
- package/dist/src/nested.d.ts +0 -47
- package/dist/src/nested.js +0 -92
- package/dist/src/nowiki/base.d.ts +0 -38
- package/dist/src/nowiki/base.js +0 -31
- package/dist/src/nowiki/comment.d.ts +0 -42
- package/dist/src/nowiki/comment.js +0 -64
- package/dist/src/nowiki/dd.d.ts +0 -22
- package/dist/src/nowiki/dd.js +0 -46
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -35
- package/dist/src/nowiki/doubleUnderscore.js +0 -48
- package/dist/src/nowiki/hr.d.ts +0 -30
- package/dist/src/nowiki/hr.js +0 -36
- package/dist/src/nowiki/index.d.ts +0 -19
- package/dist/src/nowiki/index.js +0 -23
- package/dist/src/nowiki/list.d.ts +0 -16
- package/dist/src/nowiki/list.js +0 -13
- package/dist/src/nowiki/noinclude.d.ts +0 -21
- package/dist/src/nowiki/noinclude.js +0 -24
- package/dist/src/nowiki/quote.d.ts +0 -27
- package/dist/src/nowiki/quote.js +0 -58
- package/dist/src/onlyinclude.d.ts +0 -38
- package/dist/src/onlyinclude.js +0 -66
- package/dist/src/paramTag/index.d.ts +0 -50
- package/dist/src/paramTag/index.js +0 -78
- package/dist/src/paramTag/inputbox.d.ts +0 -7
- package/dist/src/paramTag/inputbox.js +0 -21
- package/dist/src/parameter.d.ts +0 -95
- package/dist/src/parameter.js +0 -204
- package/dist/src/pre.d.ts +0 -27
- package/dist/src/pre.js +0 -44
- package/dist/src/syntax.d.ts +0 -22
- package/dist/src/syntax.js +0 -67
- package/dist/src/table/base.d.ts +0 -60
- package/dist/src/table/base.js +0 -80
- package/dist/src/table/index.d.ts +0 -247
- package/dist/src/table/index.js +0 -783
- package/dist/src/table/td.d.ts +0 -119
- package/dist/src/table/td.js +0 -268
- package/dist/src/table/tr.d.ts +0 -31
- package/dist/src/table/tr.js +0 -50
- package/dist/src/table/trBase.d.ts +0 -62
- package/dist/src/table/trBase.js +0 -157
- package/dist/src/tagPair/ext.d.ts +0 -54
- package/dist/src/tagPair/ext.js +0 -150
- package/dist/src/tagPair/include.d.ts +0 -43
- package/dist/src/tagPair/include.js +0 -43
- package/dist/src/tagPair/index.d.ts +0 -57
- package/dist/src/tagPair/index.js +0 -113
- package/dist/src/transclude.d.ts +0 -200
- package/dist/src/transclude.js +0 -732
- package/dist/util/debug.js +0 -42
- package/dist/util/diff.js +0 -71
- package/dist/util/lint.js +0 -38
- package/dist/util/string.js +0 -74
- package/errors/README +0 -1
- package/printed/README +0 -1
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConverterFlagsToken = void 0;
|
|
4
|
-
const lint_1 = require("../util/lint");
|
|
5
|
-
const index_1 = require("../index");
|
|
6
|
-
const _1 = require(".");
|
|
7
|
-
const atom_1 = require("./atom");
|
|
8
|
-
const definedFlags = new Set(['A', 'T', 'R', 'D', '-', 'H', 'N']);
|
|
9
|
-
/**
|
|
10
|
-
* 转换flags
|
|
11
|
-
* @classdesc `{childNodes: ...AtomToken}`
|
|
12
|
-
*/
|
|
13
|
-
class ConverterFlagsToken extends _1.Token {
|
|
14
|
-
/** @browser */
|
|
15
|
-
type = 'converter-flags';
|
|
16
|
-
/** @browser */
|
|
17
|
-
#flags;
|
|
18
|
-
/**
|
|
19
|
-
* @browser
|
|
20
|
-
* @param flags 转换类型标记
|
|
21
|
-
*/
|
|
22
|
-
constructor(flags, config = index_1.default.getConfig(), accum = []) {
|
|
23
|
-
super(undefined, config, true, accum, {
|
|
24
|
-
AtomToken: ':',
|
|
25
|
-
});
|
|
26
|
-
this.append(...flags.map(flag => new atom_1.AtomToken(flag, 'converter-flag', config, accum)));
|
|
27
|
-
}
|
|
28
|
-
/** @private */
|
|
29
|
-
afterBuild() {
|
|
30
|
-
this.#flags = this.childNodes.map(child => child.text().trim());
|
|
31
|
-
const /** @implements */ converterFlagsListener = ({ prevTarget }) => {
|
|
32
|
-
if (prevTarget) {
|
|
33
|
-
this.#flags[this.childNodes.indexOf(prevTarget)] = prevTarget.text().trim();
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
this.addEventListener(['remove', 'insert', 'text', 'replace'], converterFlagsListener);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @override
|
|
40
|
-
* @browser
|
|
41
|
-
*/
|
|
42
|
-
toString(selector) {
|
|
43
|
-
return super.toString(selector, ';');
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* @override
|
|
47
|
-
* @browser
|
|
48
|
-
*/
|
|
49
|
-
text() {
|
|
50
|
-
return super.text(';');
|
|
51
|
-
}
|
|
52
|
-
/** @private */
|
|
53
|
-
getGaps(i) {
|
|
54
|
-
return i < this.length - 1 ? 1 : 0;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* @override
|
|
58
|
-
* @browser
|
|
59
|
-
*/
|
|
60
|
-
print() {
|
|
61
|
-
return super.print({ sep: ';' });
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* 获取未知的转换类型标记
|
|
65
|
-
* @browser
|
|
66
|
-
*/
|
|
67
|
-
getUnknownFlags() {
|
|
68
|
-
return new Set(this.#flags.filter(flag => /\{{3}[^{}]+\}{3}/u.test(flag)));
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* 获取指定语言变体的转换标记
|
|
72
|
-
* @browser
|
|
73
|
-
*/
|
|
74
|
-
getVariantFlags() {
|
|
75
|
-
const variants = new Set(this.getAttribute('config').variants);
|
|
76
|
-
return new Set(this.#flags.filter(flag => variants.has(flag)));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* @override
|
|
80
|
-
* @browser
|
|
81
|
-
*/
|
|
82
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
83
|
-
const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags(), validFlags = new Set(this.#flags.filter(flag => definedFlags.has(flag))), { length: emptyFlagCount } = this.#flags.filter(flag => !flag), knownFlagCount = this.#flags.length - unknownFlags.size - emptyFlagCount, errors = super.lint(start);
|
|
84
|
-
if (variantFlags.size === knownFlagCount || validFlags.size === knownFlagCount) {
|
|
85
|
-
return errors;
|
|
86
|
-
}
|
|
87
|
-
const rect = { start, ...this.getRootNode().posFromIndex(start) }, { childNodes, length } = this;
|
|
88
|
-
for (let i = 0; i < length; i++) {
|
|
89
|
-
const child = childNodes[i], flag = child.text().trim();
|
|
90
|
-
if (flag && !variantFlags.has(flag) && !unknownFlags.has(flag)
|
|
91
|
-
&& (variantFlags.size > 0 || !validFlags.has(flag))) {
|
|
92
|
-
const error = (0, lint_1.generateForChild)(child, rect, 'invalid conversion flag');
|
|
93
|
-
errors.push({ ...error, excerpt: childNodes.slice(0, i + 1).map(String).join(';').slice(-50) });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return errors;
|
|
97
|
-
}
|
|
98
|
-
/** @override */
|
|
99
|
-
cloneNode() {
|
|
100
|
-
const cloned = this.cloneChildNodes();
|
|
101
|
-
return index_1.default.run(() => {
|
|
102
|
-
// @ts-expect-error abstract class
|
|
103
|
-
const token = new ConverterFlagsToken([], this.getAttribute('config'));
|
|
104
|
-
token.append(...cloned);
|
|
105
|
-
token.afterBuild();
|
|
106
|
-
return token;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/** @private */
|
|
110
|
-
getAttribute(key) {
|
|
111
|
-
return key === 'flags' ? this.#flags : super.getAttribute(key);
|
|
112
|
-
}
|
|
113
|
-
/** @private */
|
|
114
|
-
hasAttribute(key) {
|
|
115
|
-
return key === 'flags' || super.hasAttribute(key);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @override
|
|
119
|
-
* @param i 移除位置
|
|
120
|
-
*/
|
|
121
|
-
removeAt(i) {
|
|
122
|
-
const token = super.removeAt(i);
|
|
123
|
-
this.#flags?.splice(i, 1);
|
|
124
|
-
return token;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* @override
|
|
128
|
-
* @param token 待插入的子节点
|
|
129
|
-
* @param i 插入位置
|
|
130
|
-
*/
|
|
131
|
-
insertAt(token, i = this.length) {
|
|
132
|
-
super.insertAt(token, i);
|
|
133
|
-
this.#flags?.splice(i, 0, token.text().trim());
|
|
134
|
-
return token;
|
|
135
|
-
}
|
|
136
|
-
/** 获取所有转换类型标记 */
|
|
137
|
-
getAllFlags() {
|
|
138
|
-
return new Set(this.#flags);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* 获取转换类型标记节点
|
|
142
|
-
* @param flag 转换类型标记
|
|
143
|
-
*/
|
|
144
|
-
getFlagToken(flag) {
|
|
145
|
-
return this.#flags.includes(flag) ? this.childNodes.filter(child => child.text().trim() === flag) : [];
|
|
146
|
-
}
|
|
147
|
-
/** 获取有效的转换类型标记 */
|
|
148
|
-
getEffectiveFlags() {
|
|
149
|
-
const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags();
|
|
150
|
-
if (variantFlags.size > 0) {
|
|
151
|
-
return new Set([...variantFlags, ...unknownFlags]);
|
|
152
|
-
}
|
|
153
|
-
const flags = new Set([...this.#flags.filter(flag => definedFlags.has(flag)), ...unknownFlags]);
|
|
154
|
-
if (flags.size === 0) {
|
|
155
|
-
return new Set('S');
|
|
156
|
-
}
|
|
157
|
-
else if (flags.has('R')) {
|
|
158
|
-
return new Set('R');
|
|
159
|
-
}
|
|
160
|
-
else if (flags.has('N')) {
|
|
161
|
-
return new Set('N');
|
|
162
|
-
}
|
|
163
|
-
else if (flags.has('-')) {
|
|
164
|
-
return new Set('-');
|
|
165
|
-
}
|
|
166
|
-
else if (flags.has('H')) {
|
|
167
|
-
const hasT = flags.has('T'), hasD = flags.has('D');
|
|
168
|
-
return hasT && hasD
|
|
169
|
-
? new Set(['+', 'H', 'T', 'D'])
|
|
170
|
-
: new Set(['+', 'H', ...hasT ? ['T'] : [], ...hasD ? ['D'] : [], ...unknownFlags]);
|
|
171
|
-
}
|
|
172
|
-
if (flags.size === 1 && flags.has('T')) {
|
|
173
|
-
flags.add('H');
|
|
174
|
-
}
|
|
175
|
-
if (flags.has('A')) {
|
|
176
|
-
flags.add('+');
|
|
177
|
-
flags.add('S');
|
|
178
|
-
}
|
|
179
|
-
if (flags.has('D')) {
|
|
180
|
-
flags.delete('S');
|
|
181
|
-
}
|
|
182
|
-
return flags;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* 是否具有某转换类型标记
|
|
186
|
-
* @param flag 转换类型标记
|
|
187
|
-
*/
|
|
188
|
-
hasFlag(flag) {
|
|
189
|
-
return this.#flags.includes(flag);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* 是否具有某有效的转换类型标记
|
|
193
|
-
* @param flag 转换类型标记
|
|
194
|
-
*/
|
|
195
|
-
hasEffectiveFlag(flag) {
|
|
196
|
-
return this.getEffectiveFlags().has(flag);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* 移除某转换类型标记
|
|
200
|
-
* @param flag 转换类型标记
|
|
201
|
-
*/
|
|
202
|
-
removeFlag(flag) {
|
|
203
|
-
for (const token of this.getFlagToken(flag)) {
|
|
204
|
-
token.remove();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* 添加转换类型标记
|
|
209
|
-
* @param flag 转换类型标记
|
|
210
|
-
*/
|
|
211
|
-
#newFlag(flag) {
|
|
212
|
-
const token = index_1.default.run(() => new atom_1.AtomToken(flag, 'converter-flag', this.getAttribute('config')));
|
|
213
|
-
this.insertAt(token);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* 设置转换类型标记
|
|
217
|
-
* @param flag 转换类型标记
|
|
218
|
-
*/
|
|
219
|
-
setFlag(flag) {
|
|
220
|
-
if (!this.#flags.includes(flag)) {
|
|
221
|
-
this.#newFlag(flag);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* 开关转换类型标记
|
|
226
|
-
* @param flag 转换类型标记
|
|
227
|
-
*/
|
|
228
|
-
toggleFlag(flag) {
|
|
229
|
-
if (this.#flags.includes(flag)) {
|
|
230
|
-
this.removeFlag(flag);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
this.#newFlag(flag);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
exports.ConverterFlagsToken = ConverterFlagsToken;
|
|
238
|
-
index_1.default.classes['ConverterFlagsToken'] = __filename;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Token } from '.';
|
|
2
|
-
import { AtomToken } from './atom';
|
|
3
|
-
import type { ConverterToken, ConverterFlagsToken } from '../internal';
|
|
4
|
-
/**
|
|
5
|
-
* 转换规则
|
|
6
|
-
* @classdesc `{childNodes: ...AtomToken}`
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class ConverterRuleToken extends Token {
|
|
9
|
-
/** @browser */
|
|
10
|
-
readonly type = "converter-rule";
|
|
11
|
-
childNodes: [AtomToken] | [AtomToken, AtomToken] | [AtomToken, AtomToken, AtomToken];
|
|
12
|
-
abstract get children(): [AtomToken] | [AtomToken, AtomToken] | [AtomToken, AtomToken, AtomToken];
|
|
13
|
-
abstract get firstChild(): AtomToken;
|
|
14
|
-
abstract get firstElementChild(): AtomToken;
|
|
15
|
-
abstract get lastChild(): AtomToken;
|
|
16
|
-
abstract get lastElementChild(): AtomToken;
|
|
17
|
-
abstract get parentNode(): ConverterToken | undefined;
|
|
18
|
-
abstract get parentElement(): ConverterToken | undefined;
|
|
19
|
-
abstract get previousSibling(): ConverterFlagsToken | this;
|
|
20
|
-
abstract get previousElementSibling(): ConverterFlagsToken | this;
|
|
21
|
-
abstract get nextSibling(): this | undefined;
|
|
22
|
-
abstract get nextElementSibling(): this | undefined;
|
|
23
|
-
/** 语言变体 */
|
|
24
|
-
get variant(): string;
|
|
25
|
-
set variant(variant: string);
|
|
26
|
-
/** 是否是单向转换 */
|
|
27
|
-
get unidirectional(): boolean;
|
|
28
|
-
/** @throws `Error` 不能用于将双向转换或不转换更改为单向转换 */
|
|
29
|
-
set unidirectional(flag: boolean);
|
|
30
|
-
/** 是否是双向转换 */
|
|
31
|
-
get bidirectional(): boolean;
|
|
32
|
-
/** @throws `Error` 不能用于将双向转换更改为单向转换或将不转换更改为双向转换 */
|
|
33
|
-
set bidirectional(flag: boolean);
|
|
34
|
-
/**
|
|
35
|
-
* @browser
|
|
36
|
-
* @param rule 转换规则
|
|
37
|
-
* @param hasColon 是否带有":"
|
|
38
|
-
*/
|
|
39
|
-
constructor(rule: string, hasColon?: boolean, config?: import("../index").Config, accum?: Token[]);
|
|
40
|
-
/**
|
|
41
|
-
* @override
|
|
42
|
-
* @browser
|
|
43
|
-
*/
|
|
44
|
-
toString(selector?: string): string;
|
|
45
|
-
/**
|
|
46
|
-
* @override
|
|
47
|
-
* @browser
|
|
48
|
-
*/
|
|
49
|
-
text(): string;
|
|
50
|
-
/**
|
|
51
|
-
* @override
|
|
52
|
-
* @browser
|
|
53
|
-
*/
|
|
54
|
-
print(): string;
|
|
55
|
-
/** @override */
|
|
56
|
-
cloneNode(): this;
|
|
57
|
-
/**
|
|
58
|
-
* @override
|
|
59
|
-
* @param i 移除位置
|
|
60
|
-
* @throws `Error` 至少保留1个子节点
|
|
61
|
-
*/
|
|
62
|
-
removeAt(i: number): AtomToken;
|
|
63
|
-
/**
|
|
64
|
-
* @override
|
|
65
|
-
* @throws `Error` 请勿手动插入子节点
|
|
66
|
-
*/
|
|
67
|
-
insertAt(): never;
|
|
68
|
-
/** 修改为不转换 */
|
|
69
|
-
noConvert(): void;
|
|
70
|
-
/**
|
|
71
|
-
* 设置转换目标
|
|
72
|
-
* @param to 转换目标
|
|
73
|
-
* @throws `SyntaxError` 非法的转换目标
|
|
74
|
-
*/
|
|
75
|
-
setTo(to: string): void;
|
|
76
|
-
/**
|
|
77
|
-
* 设置语言变体
|
|
78
|
-
* @param variant 语言变体
|
|
79
|
-
* @throws `RangeError` 无效的语言变体
|
|
80
|
-
*/
|
|
81
|
-
setVariant(variant: string): void;
|
|
82
|
-
/**
|
|
83
|
-
* 设置转换原文
|
|
84
|
-
* @param from 转换原文
|
|
85
|
-
* @throws `Error` 尚未指定语言变体
|
|
86
|
-
* @throws `SyntaxError` 非法的转换原文
|
|
87
|
-
*/
|
|
88
|
-
setFrom(from: string): void;
|
|
89
|
-
/**
|
|
90
|
-
* 修改为单向转换
|
|
91
|
-
* @param from 转换原文
|
|
92
|
-
*/
|
|
93
|
-
makeUnidirectional(from: string): void;
|
|
94
|
-
/** 修改为双向转换 */
|
|
95
|
-
makeBidirectional(): void;
|
|
96
|
-
}
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConverterRuleToken = void 0;
|
|
4
|
-
const debug_1 = require("../util/debug");
|
|
5
|
-
const string_1 = require("../util/string");
|
|
6
|
-
const index_1 = require("../index");
|
|
7
|
-
const _1 = require(".");
|
|
8
|
-
const atom_1 = require("./atom");
|
|
9
|
-
/**
|
|
10
|
-
* 转换规则
|
|
11
|
-
* @classdesc `{childNodes: ...AtomToken}`
|
|
12
|
-
*/
|
|
13
|
-
class ConverterRuleToken extends _1.Token {
|
|
14
|
-
/** @browser */
|
|
15
|
-
type = 'converter-rule';
|
|
16
|
-
/** 语言变体 */
|
|
17
|
-
get variant() {
|
|
18
|
-
return this.childNodes.at(-2)?.text()?.trim() ?? '';
|
|
19
|
-
}
|
|
20
|
-
set variant(variant) {
|
|
21
|
-
this.setVariant(variant);
|
|
22
|
-
}
|
|
23
|
-
/** 是否是单向转换 */
|
|
24
|
-
get unidirectional() {
|
|
25
|
-
return this.length === 3;
|
|
26
|
-
}
|
|
27
|
-
/** @throws `Error` 不能用于将双向转换或不转换更改为单向转换 */
|
|
28
|
-
set unidirectional(flag) {
|
|
29
|
-
const { length } = this;
|
|
30
|
-
if (length === 3 && !flag) {
|
|
31
|
-
this.makeBidirectional();
|
|
32
|
-
}
|
|
33
|
-
else if (length === 2 && flag) {
|
|
34
|
-
throw new Error('想更改为单向转换请使用 makeUnidirectional 方法!');
|
|
35
|
-
}
|
|
36
|
-
else if (length === 1 && flag) {
|
|
37
|
-
throw new Error('想更改为单向转换请先使用 setVariant 方法指定语言变体!');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/** 是否是双向转换 */
|
|
41
|
-
get bidirectional() {
|
|
42
|
-
return this.length === 2;
|
|
43
|
-
}
|
|
44
|
-
/** @throws `Error` 不能用于将双向转换更改为单向转换或将不转换更改为双向转换 */
|
|
45
|
-
set bidirectional(flag) {
|
|
46
|
-
const { length } = this;
|
|
47
|
-
if (length === 3 && flag) {
|
|
48
|
-
this.makeBidirectional();
|
|
49
|
-
}
|
|
50
|
-
else if (length === 2 && !flag) {
|
|
51
|
-
throw new Error('想更改为单向转换请使用 makeUnidirectional 方法!');
|
|
52
|
-
}
|
|
53
|
-
else if (length === 1 && flag) {
|
|
54
|
-
throw new Error('想更改为双向转换请使用 setVariant 方法!');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @browser
|
|
59
|
-
* @param rule 转换规则
|
|
60
|
-
* @param hasColon 是否带有":"
|
|
61
|
-
*/
|
|
62
|
-
constructor(rule, hasColon = true, config = index_1.default.getConfig(), accum = []) {
|
|
63
|
-
super(undefined, config, true, accum);
|
|
64
|
-
if (hasColon) {
|
|
65
|
-
const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
|
|
66
|
-
if (config.variants.includes(v.trim())) {
|
|
67
|
-
super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
|
|
68
|
-
super.insertAt(new atom_1.AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
|
|
69
|
-
if (j !== -1) {
|
|
70
|
-
super.insertAt(new atom_1.AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-noconvert', config, accum));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-noconvert', config, accum));
|
|
79
|
-
}
|
|
80
|
-
this.protectChildren('1:');
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* @override
|
|
84
|
-
* @browser
|
|
85
|
-
*/
|
|
86
|
-
toString(selector) {
|
|
87
|
-
const { childNodes } = this;
|
|
88
|
-
if (childNodes.length === 3 && !(selector && this.matches(selector))) {
|
|
89
|
-
const [from, variant, to] = childNodes;
|
|
90
|
-
return `${from.toString(selector)}=>${variant.toString(selector)}:${to.toString(selector)}`;
|
|
91
|
-
}
|
|
92
|
-
return super.toString(selector, ':');
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @override
|
|
96
|
-
* @browser
|
|
97
|
-
*/
|
|
98
|
-
text() {
|
|
99
|
-
const { childNodes } = this;
|
|
100
|
-
if (childNodes.length === 3) {
|
|
101
|
-
const [from, variant, to] = childNodes;
|
|
102
|
-
return `${from.text()}=>${variant.text()}:${to.text()}`;
|
|
103
|
-
}
|
|
104
|
-
return super.text(':');
|
|
105
|
-
}
|
|
106
|
-
/** @private */
|
|
107
|
-
getGaps(i) {
|
|
108
|
-
const { length } = this;
|
|
109
|
-
return i === 0 && length === 3 ? 2 : 1;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* @override
|
|
113
|
-
* @browser
|
|
114
|
-
*/
|
|
115
|
-
print() {
|
|
116
|
-
const { childNodes } = this;
|
|
117
|
-
if (childNodes.length === 3) {
|
|
118
|
-
const [from, variant, to] = childNodes;
|
|
119
|
-
return `<span class="wpb-converter-rule">${from.print()}=>${variant.print()}:${to.print()}</span>`;
|
|
120
|
-
}
|
|
121
|
-
return super.print({ sep: ':' });
|
|
122
|
-
}
|
|
123
|
-
/** @override */
|
|
124
|
-
cloneNode() {
|
|
125
|
-
const cloned = this.cloneChildNodes(), placeholders = ['', 'zh:', '=>zh:'], placeholder = placeholders[cloned.length - 1];
|
|
126
|
-
return index_1.default.run(() => {
|
|
127
|
-
// @ts-expect-error abstract class
|
|
128
|
-
const token = new ConverterRuleToken(placeholder, placeholder, this.getAttribute('config'));
|
|
129
|
-
for (let i = 0; i < cloned.length; i++) {
|
|
130
|
-
token.childNodes[i].safeReplaceWith(cloned[i]);
|
|
131
|
-
}
|
|
132
|
-
token.afterBuild();
|
|
133
|
-
return token;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
/** @private */
|
|
137
|
-
afterBuild() {
|
|
138
|
-
const /** @implements */ converterRuleListener = (e, data) => {
|
|
139
|
-
const { prevTarget } = e;
|
|
140
|
-
if (this.length > 1 && this.childNodes.at(-2) === prevTarget) {
|
|
141
|
-
const v = prevTarget.text().trim(), { variants } = this.getAttribute('config');
|
|
142
|
-
if (!variants.includes(v)) {
|
|
143
|
-
(0, debug_1.undo)(e, data);
|
|
144
|
-
throw new Error(`无效的语言变体:${v}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
this.addEventListener(['remove', 'insert', 'text', 'replace'], converterRuleListener);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* @override
|
|
152
|
-
* @param i 移除位置
|
|
153
|
-
* @throws `Error` 至少保留1个子节点
|
|
154
|
-
*/
|
|
155
|
-
removeAt(i) {
|
|
156
|
-
if (this.length === 1) {
|
|
157
|
-
throw new Error(`${this.constructor.name} 需至少保留 1 个子节点!`);
|
|
158
|
-
}
|
|
159
|
-
const removed = super.removeAt(i);
|
|
160
|
-
if (this.length === 1) {
|
|
161
|
-
this.firstChild.type = 'converter-rule-noconvert';
|
|
162
|
-
}
|
|
163
|
-
return removed;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* @override
|
|
167
|
-
* @throws `Error` 请勿手动插入子节点
|
|
168
|
-
*/
|
|
169
|
-
insertAt() {
|
|
170
|
-
throw new Error(`转换规则语法复杂,请勿尝试对 ${this.constructor.name} 手动插入子节点!`);
|
|
171
|
-
}
|
|
172
|
-
/** 修改为不转换 */
|
|
173
|
-
noConvert() {
|
|
174
|
-
const { length } = this;
|
|
175
|
-
for (let i = 0; i < length - 1; i++) { // ConverterRuleToken只能从前往后删除子节点
|
|
176
|
-
this.removeAt(0);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* 设置转换目标
|
|
181
|
-
* @param to 转换目标
|
|
182
|
-
* @throws `SyntaxError` 非法的转换目标
|
|
183
|
-
*/
|
|
184
|
-
setTo(to) {
|
|
185
|
-
const config = this.getAttribute('config'), include = this.getAttribute('include'), root = index_1.default.parse(`-{|${config.variants[0] ?? 'zh'}:${to}}-`, include, undefined, config), { length, firstChild: converter } = root;
|
|
186
|
-
if (length !== 1 || converter.type !== 'converter') {
|
|
187
|
-
throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
|
|
188
|
-
}
|
|
189
|
-
const { lastChild: converterRule } = converter;
|
|
190
|
-
if (converter.length !== 2 || converterRule.length !== 2) {
|
|
191
|
-
throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
|
|
192
|
-
}
|
|
193
|
-
const { lastChild } = converterRule;
|
|
194
|
-
converterRule.destroy();
|
|
195
|
-
this.lastChild.safeReplaceWith(lastChild);
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* 设置语言变体
|
|
199
|
-
* @param variant 语言变体
|
|
200
|
-
* @throws `RangeError` 无效的语言变体
|
|
201
|
-
*/
|
|
202
|
-
setVariant(variant) {
|
|
203
|
-
const config = this.getAttribute('config'), v = variant.trim();
|
|
204
|
-
if (!config.variants.includes(v)) {
|
|
205
|
-
throw new RangeError(`无效的语言变体:${v}`);
|
|
206
|
-
}
|
|
207
|
-
else if (this.length === 1) {
|
|
208
|
-
super.insertAt(index_1.default.run(() => new atom_1.AtomToken(variant, 'converter-rule-variant', config)), 0);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
this.childNodes.at(-2).setText(variant);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* 设置转换原文
|
|
216
|
-
* @param from 转换原文
|
|
217
|
-
* @throws `Error` 尚未指定语言变体
|
|
218
|
-
* @throws `SyntaxError` 非法的转换原文
|
|
219
|
-
*/
|
|
220
|
-
setFrom(from) {
|
|
221
|
-
const { variant, unidirectional } = this;
|
|
222
|
-
if (!variant) {
|
|
223
|
-
throw new Error('请先指定语言变体!');
|
|
224
|
-
}
|
|
225
|
-
const config = this.getAttribute('config'), root = index_1.default.parse(`-{|${from}=>${variant}:}-`, this.getAttribute('include'), undefined, config), { length, firstChild: converter } = root;
|
|
226
|
-
if (length !== 1 || converter.type !== 'converter') {
|
|
227
|
-
throw new SyntaxError(`非法的转换原文:${(0, string_1.noWrap)(from)}`);
|
|
228
|
-
}
|
|
229
|
-
const { lastChild: converterRule } = converter;
|
|
230
|
-
if (converter.length !== 2 || converterRule.length !== 3) {
|
|
231
|
-
throw new SyntaxError(`非法的转换原文:${(0, string_1.noWrap)(from)}`);
|
|
232
|
-
}
|
|
233
|
-
else if (unidirectional) {
|
|
234
|
-
this.firstChild.safeReplaceWith(converterRule.firstChild);
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
super.insertAt(converterRule.firstChild, 0);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* 修改为单向转换
|
|
242
|
-
* @param from 转换原文
|
|
243
|
-
*/
|
|
244
|
-
makeUnidirectional(from) {
|
|
245
|
-
this.setFrom(from);
|
|
246
|
-
}
|
|
247
|
-
/** 修改为双向转换 */
|
|
248
|
-
makeBidirectional() {
|
|
249
|
-
if (this.unidirectional) {
|
|
250
|
-
this.removeAt(0);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
exports.ConverterRuleToken = ConverterRuleToken;
|
|
255
|
-
index_1.default.classes['ConverterRuleToken'] = __filename;
|
package/dist/src/extLink.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Token } from '.';
|
|
2
|
-
import { MagicLinkToken } from './magicLink';
|
|
3
|
-
/**
|
|
4
|
-
* 外链
|
|
5
|
-
* @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
|
|
6
|
-
*/
|
|
7
|
-
export declare abstract class ExtLinkToken extends Token {
|
|
8
|
-
#private;
|
|
9
|
-
/** @browser */
|
|
10
|
-
readonly type = "ext-link";
|
|
11
|
-
childNodes: [MagicLinkToken] | [MagicLinkToken, Token];
|
|
12
|
-
abstract get children(): [MagicLinkToken] | [MagicLinkToken, Token];
|
|
13
|
-
abstract get firstChild(): MagicLinkToken;
|
|
14
|
-
abstract get firstElementChild(): MagicLinkToken;
|
|
15
|
-
abstract get lastChild(): Token;
|
|
16
|
-
abstract get lastElementChild(): Token;
|
|
17
|
-
/** 协议 */
|
|
18
|
-
get protocol(): string | undefined;
|
|
19
|
-
set protocol(value: string | undefined);
|
|
20
|
-
/** 和内链保持一致 */
|
|
21
|
-
get link(): string;
|
|
22
|
-
set link(url: string);
|
|
23
|
-
/** 链接显示文字 */
|
|
24
|
-
get innerText(): string;
|
|
25
|
-
/**
|
|
26
|
-
* @browser
|
|
27
|
-
* @param url 网址
|
|
28
|
-
* @param space 空白字符
|
|
29
|
-
* @param text 链接文字
|
|
30
|
-
*/
|
|
31
|
-
constructor(url: string, space?: string, text?: string, config?: import("../index").Config, accum?: Token[]);
|
|
32
|
-
/**
|
|
33
|
-
* @override
|
|
34
|
-
* @browser
|
|
35
|
-
*/
|
|
36
|
-
toString(selector?: string): string;
|
|
37
|
-
/**
|
|
38
|
-
* @override
|
|
39
|
-
* @browser
|
|
40
|
-
*/
|
|
41
|
-
text(): string;
|
|
42
|
-
/**
|
|
43
|
-
* @override
|
|
44
|
-
* @browser
|
|
45
|
-
*/
|
|
46
|
-
print(): string;
|
|
47
|
-
/** @override */
|
|
48
|
-
cloneNode(): this;
|
|
49
|
-
/** 获取网址 */
|
|
50
|
-
getUrl(): URL;
|
|
51
|
-
/**
|
|
52
|
-
* 设置链接目标
|
|
53
|
-
* @param url 网址
|
|
54
|
-
* @throws `SyntaxError` 非法的外链目标
|
|
55
|
-
*/
|
|
56
|
-
setTarget(url: string | URL): void;
|
|
57
|
-
/**
|
|
58
|
-
* 设置链接显示文字
|
|
59
|
-
* @param str 链接显示文字
|
|
60
|
-
* @throws `SyntaxError` 非法的链接显示文字
|
|
61
|
-
*/
|
|
62
|
-
setLinkText(str: string): void;
|
|
63
|
-
}
|