wikiparser-node 1.4.3 → 1.4.4-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 (166) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/bundle/bundle.min.js +36 -0
  4. package/config/enwiki.json +1 -814
  5. package/config/llwiki.json +1 -35
  6. package/config/moegirl.json +1 -44
  7. package/config/zhwiki.json +1 -466
  8. package/extensions/dist/base.js +64 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +59 -0
  11. package/extensions/dist/lint.js +48 -0
  12. package/extensions/editor.css +63 -0
  13. package/extensions/ui.css +141 -0
  14. package/i18n/zh-hans.json +1 -0
  15. package/i18n/zh-hant.json +1 -0
  16. package/package.json +28 -15
  17. package/config/.schema.json +0 -172
  18. package/dist/addon/table.d.ts +0 -6
  19. package/dist/addon/table.js +0 -564
  20. package/dist/base.d.ts +0 -58
  21. package/dist/index.d.ts +0 -30
  22. package/dist/index.js +0 -211
  23. package/dist/internal.d.ts +0 -44
  24. package/dist/lib/element.d.ts +0 -155
  25. package/dist/lib/element.js +0 -650
  26. package/dist/lib/node.d.ts +0 -146
  27. package/dist/lib/node.js +0 -428
  28. package/dist/lib/range.d.ts +0 -104
  29. package/dist/lib/range.js +0 -385
  30. package/dist/lib/ranges.d.ts +0 -26
  31. package/dist/lib/ranges.js +0 -118
  32. package/dist/lib/text.d.ts +0 -62
  33. package/dist/lib/text.js +0 -306
  34. package/dist/lib/title.d.ts +0 -38
  35. package/dist/lib/title.js +0 -164
  36. package/dist/mixin/attributesParent.d.ts +0 -50
  37. package/dist/mixin/attributesParent.js +0 -78
  38. package/dist/mixin/fixed.d.ts +0 -6
  39. package/dist/mixin/fixed.js +0 -30
  40. package/dist/mixin/flagsParent.d.ts +0 -72
  41. package/dist/mixin/flagsParent.js +0 -59
  42. package/dist/mixin/hidden.d.ts +0 -5
  43. package/dist/mixin/hidden.js +0 -24
  44. package/dist/mixin/magicLinkParent.d.ts +0 -40
  45. package/dist/mixin/magicLinkParent.js +0 -42
  46. package/dist/mixin/singleLine.d.ts +0 -6
  47. package/dist/mixin/singleLine.js +0 -26
  48. package/dist/mixin/sol.d.ts +0 -6
  49. package/dist/mixin/sol.js +0 -43
  50. package/dist/mixin/syntax.d.ts +0 -9
  51. package/dist/mixin/syntax.js +0 -50
  52. package/dist/parser/braces.js +0 -131
  53. package/dist/parser/commentAndExt.js +0 -90
  54. package/dist/parser/converter.js +0 -41
  55. package/dist/parser/externalLinks.js +0 -32
  56. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  57. package/dist/parser/html.js +0 -39
  58. package/dist/parser/links.js +0 -95
  59. package/dist/parser/list.js +0 -68
  60. package/dist/parser/magicLinks.js +0 -43
  61. package/dist/parser/quotes.js +0 -68
  62. package/dist/parser/selector.js +0 -162
  63. package/dist/parser/table.js +0 -124
  64. package/dist/src/arg.d.ts +0 -58
  65. package/dist/src/arg.js +0 -196
  66. package/dist/src/atom.d.ts +0 -12
  67. package/dist/src/atom.js +0 -27
  68. package/dist/src/attribute.d.ts +0 -69
  69. package/dist/src/attribute.js +0 -475
  70. package/dist/src/attributes.d.ts +0 -109
  71. package/dist/src/attributes.js +0 -346
  72. package/dist/src/converter.d.ts +0 -33
  73. package/dist/src/converter.js +0 -134
  74. package/dist/src/converterFlags.d.ts +0 -87
  75. package/dist/src/converterFlags.js +0 -226
  76. package/dist/src/converterRule.d.ts +0 -77
  77. package/dist/src/converterRule.js +0 -209
  78. package/dist/src/extLink.d.ts +0 -43
  79. package/dist/src/extLink.js +0 -186
  80. package/dist/src/gallery.d.ts +0 -54
  81. package/dist/src/gallery.js +0 -126
  82. package/dist/src/heading.d.ts +0 -47
  83. package/dist/src/heading.js +0 -190
  84. package/dist/src/hidden.d.ts +0 -7
  85. package/dist/src/hidden.js +0 -23
  86. package/dist/src/html.d.ts +0 -65
  87. package/dist/src/html.js +0 -335
  88. package/dist/src/imageParameter.d.ts +0 -65
  89. package/dist/src/imageParameter.js +0 -248
  90. package/dist/src/imagemap.d.ts +0 -56
  91. package/dist/src/imagemap.js +0 -150
  92. package/dist/src/imagemapLink.d.ts +0 -31
  93. package/dist/src/imagemapLink.js +0 -93
  94. package/dist/src/index.d.ts +0 -143
  95. package/dist/src/index.js +0 -803
  96. package/dist/src/link/base.d.ts +0 -52
  97. package/dist/src/link/base.js +0 -209
  98. package/dist/src/link/category.d.ts +0 -13
  99. package/dist/src/link/category.js +0 -28
  100. package/dist/src/link/file.d.ts +0 -96
  101. package/dist/src/link/file.js +0 -265
  102. package/dist/src/link/galleryImage.d.ts +0 -32
  103. package/dist/src/link/galleryImage.js +0 -157
  104. package/dist/src/link/index.d.ts +0 -56
  105. package/dist/src/link/index.js +0 -133
  106. package/dist/src/magicLink.d.ts +0 -59
  107. package/dist/src/magicLink.js +0 -199
  108. package/dist/src/nested.d.ts +0 -43
  109. package/dist/src/nested.js +0 -92
  110. package/dist/src/nowiki/base.d.ts +0 -31
  111. package/dist/src/nowiki/base.js +0 -93
  112. package/dist/src/nowiki/comment.d.ts +0 -25
  113. package/dist/src/nowiki/comment.js +0 -68
  114. package/dist/src/nowiki/dd.d.ts +0 -8
  115. package/dist/src/nowiki/dd.js +0 -24
  116. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  117. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  118. package/dist/src/nowiki/hr.d.ts +0 -5
  119. package/dist/src/nowiki/hr.js +0 -63
  120. package/dist/src/nowiki/index.d.ts +0 -16
  121. package/dist/src/nowiki/index.js +0 -21
  122. package/dist/src/nowiki/list.d.ts +0 -16
  123. package/dist/src/nowiki/list.js +0 -97
  124. package/dist/src/nowiki/listBase.d.ts +0 -5
  125. package/dist/src/nowiki/listBase.js +0 -61
  126. package/dist/src/nowiki/noinclude.d.ts +0 -10
  127. package/dist/src/nowiki/noinclude.js +0 -23
  128. package/dist/src/nowiki/quote.d.ts +0 -14
  129. package/dist/src/nowiki/quote.js +0 -116
  130. package/dist/src/onlyinclude.d.ts +0 -16
  131. package/dist/src/onlyinclude.js +0 -57
  132. package/dist/src/paramTag/index.d.ts +0 -37
  133. package/dist/src/paramTag/index.js +0 -69
  134. package/dist/src/paramTag/inputbox.d.ts +0 -8
  135. package/dist/src/paramTag/inputbox.js +0 -22
  136. package/dist/src/parameter.d.ts +0 -70
  137. package/dist/src/parameter.js +0 -262
  138. package/dist/src/pre.d.ts +0 -28
  139. package/dist/src/pre.js +0 -55
  140. package/dist/src/syntax.d.ts +0 -20
  141. package/dist/src/syntax.js +0 -86
  142. package/dist/src/table/base.d.ts +0 -30
  143. package/dist/src/table/base.js +0 -132
  144. package/dist/src/table/index.d.ts +0 -233
  145. package/dist/src/table/index.js +0 -386
  146. package/dist/src/table/td.d.ts +0 -92
  147. package/dist/src/table/td.js +0 -337
  148. package/dist/src/table/tr.d.ts +0 -32
  149. package/dist/src/table/tr.js +0 -58
  150. package/dist/src/table/trBase.d.ts +0 -53
  151. package/dist/src/table/trBase.js +0 -154
  152. package/dist/src/tagPair/ext.d.ts +0 -32
  153. package/dist/src/tagPair/ext.js +0 -203
  154. package/dist/src/tagPair/include.d.ts +0 -35
  155. package/dist/src/tagPair/include.js +0 -63
  156. package/dist/src/tagPair/index.d.ts +0 -27
  157. package/dist/src/tagPair/index.js +0 -128
  158. package/dist/src/transclude.d.ts +0 -167
  159. package/dist/src/transclude.js +0 -710
  160. package/dist/util/constants.js +0 -113
  161. package/dist/util/debug.js +0 -88
  162. package/dist/util/diff.js +0 -82
  163. package/dist/util/lint.js +0 -30
  164. package/dist/util/string.js +0 -53
  165. package/errors/README +0 -1
  166. package/printed/README +0 -1
@@ -1,226 +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()) {
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);
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
- errors.push((0, lint_1.generateForChild)(child, rect, 'invalid conversion flag'));
82
- }
83
- }
84
- return errors;
85
- }
86
- /** @override */
87
- print() {
88
- return super.print({ sep: ';' });
89
- }
90
- /* NOT FOR BROWSER */
91
- /** @override */
92
- cloneNode() {
93
- const cloned = this.cloneChildNodes();
94
- return debug_1.Shadow.run(() => {
95
- // @ts-expect-error abstract class
96
- const token = new ConverterFlagsToken([], this.getAttribute('config'));
97
- token.append(...cloned);
98
- token.afterBuild();
99
- return token;
100
- });
101
- }
102
- /** @private */
103
- getAttribute(key) {
104
- return key === 'flags' ? this.#flags : super.getAttribute(key);
105
- }
106
- /**
107
- * @override
108
- * @param i 移除位置
109
- */
110
- removeAt(i) {
111
- const token = super.removeAt(i);
112
- this.#flags?.splice(i, 1);
113
- return token;
114
- }
115
- /**
116
- * @override
117
- * @param token 待插入的子节点
118
- * @param i 插入位置
119
- */
120
- insertAt(token, i = this.length) {
121
- super.insertAt(token, i);
122
- this.#flags?.splice(i, 0, token.text().trim());
123
- return token;
124
- }
125
- /** 获取所有转换类型标记 */
126
- getAllFlags() {
127
- return new Set(this.#flags);
128
- }
129
- /**
130
- * 获取转换类型标记节点
131
- * @param flag 转换类型标记
132
- */
133
- getFlagTokens(flag) {
134
- return this.#flags.includes(flag) ? this.childNodes.filter(child => child.text().trim() === flag) : [];
135
- }
136
- /** 获取有效的转换类型标记 */
137
- getEffectiveFlags() {
138
- const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags();
139
- if (variantFlags.size > 0) {
140
- return new Set([...variantFlags, ...unknownFlags]);
141
- }
142
- const flags = new Set([...this.#flags.filter(flag => definedFlags.has(flag)), ...unknownFlags]);
143
- if (flags.size === 0) {
144
- return new Set('S');
145
- }
146
- else if (flags.has('R')) {
147
- return new Set('R');
148
- }
149
- else if (flags.has('N')) {
150
- return new Set('N');
151
- }
152
- else if (flags.has('-')) {
153
- return new Set('-');
154
- }
155
- else if (flags.has('H')) {
156
- const hasT = flags.has('T'), hasD = flags.has('D');
157
- return hasT && hasD
158
- ? new Set(['+', 'H', 'T', 'D'])
159
- : new Set(['+', 'H', ...hasT ? ['T'] : [], ...hasD ? ['D'] : [], ...unknownFlags]);
160
- }
161
- if (flags.size === 1 && flags.has('T')) {
162
- flags.add('H');
163
- }
164
- if (flags.has('A')) {
165
- flags.add('+');
166
- flags.add('S');
167
- }
168
- if (flags.has('D')) {
169
- flags.delete('S');
170
- }
171
- return flags;
172
- }
173
- /**
174
- * 是否具有某转换类型标记
175
- * @param flag 转换类型标记
176
- */
177
- hasFlag(flag) {
178
- return this.#flags.includes(flag);
179
- }
180
- /**
181
- * 是否具有某有效的转换类型标记
182
- * @param flag 转换类型标记
183
- */
184
- hasEffectiveFlag(flag) {
185
- return this.getEffectiveFlags().has(flag);
186
- }
187
- /**
188
- * 移除某转换类型标记
189
- * @param flag 转换类型标记
190
- */
191
- removeFlag(flag) {
192
- for (const token of this.getFlagTokens(flag)) {
193
- token.remove();
194
- }
195
- }
196
- /**
197
- * 添加转换类型标记
198
- * @param flag 转换类型标记
199
- */
200
- #newFlag(flag) {
201
- this.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(flag, 'converter-flag', this.getAttribute('config'))));
202
- }
203
- /**
204
- * 设置转换类型标记
205
- * @param flag 转换类型标记
206
- */
207
- setFlag(flag) {
208
- if (!this.#flags.includes(flag)) {
209
- this.#newFlag(flag);
210
- }
211
- }
212
- /**
213
- * 开关转换类型标记
214
- * @param flag 转换类型标记
215
- */
216
- toggleFlag(flag) {
217
- if (this.#flags.includes(flag)) {
218
- this.removeFlag(flag);
219
- }
220
- else {
221
- this.#newFlag(flag);
222
- }
223
- }
224
- }
225
- exports.ConverterFlagsToken = ConverterFlagsToken;
226
- 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): LintError[];
34
- /** @override */
35
- print(): string;
36
- /** @override */
37
- cloneNode(): this;
38
- /**
39
- * 设置链接显示文字
40
- * @param str 链接显示文字
41
- */
42
- setLinkText(str: string): void;
43
- }