wikiparser-node 1.12.5-b → 1.12.6

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