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