wikiparser-node 1.12.4 → 1.12.5-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 (175) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +29 -30
  3. package/config/enwiki.json +15 -829
  4. package/config/llwiki.json +21 -56
  5. package/config/minimum.json +6 -1
  6. package/config/moegirl.json +21 -65
  7. package/config/zhwiki.json +28 -494
  8. package/extensions/dist/base.js +163 -0
  9. package/extensions/dist/codejar.js +52 -0
  10. package/extensions/dist/editor.js +159 -0
  11. package/extensions/dist/highlight.js +30 -0
  12. package/extensions/dist/lint.js +72 -0
  13. package/extensions/editor.css +59 -0
  14. package/extensions/ui.css +162 -0
  15. package/package.json +28 -21
  16. package/config/.schema.json +0 -203
  17. package/dist/addon/table.js +0 -494
  18. package/dist/addon/token.js +0 -392
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -40
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -275
  24. package/dist/internal.d.ts +0 -47
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -377
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -478
  29. package/dist/lib/range.d.ts +0 -105
  30. package/dist/lib/range.js +0 -406
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/rect.d.ts +0 -18
  34. package/dist/lib/rect.js +0 -36
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -414
  37. package/dist/lib/title.d.ts +0 -49
  38. package/dist/lib/title.js +0 -253
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -80
  41. package/dist/mixin/fixed.d.ts +0 -5
  42. package/dist/mixin/fixed.js +0 -32
  43. package/dist/mixin/flagsParent.d.ts +0 -43
  44. package/dist/mixin/flagsParent.js +0 -64
  45. package/dist/mixin/hidden.d.ts +0 -7
  46. package/dist/mixin/hidden.js +0 -39
  47. package/dist/mixin/magicLinkParent.d.ts +0 -19
  48. package/dist/mixin/magicLinkParent.js +0 -43
  49. package/dist/mixin/singleLine.d.ts +0 -5
  50. package/dist/mixin/singleLine.js +0 -25
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -45
  53. package/dist/mixin/syntax.d.ts +0 -8
  54. package/dist/mixin/syntax.js +0 -46
  55. package/dist/parser/braces.js +0 -152
  56. package/dist/parser/commentAndExt.js +0 -84
  57. package/dist/parser/converter.js +0 -41
  58. package/dist/parser/externalLinks.js +0 -39
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -44
  60. package/dist/parser/html.js +0 -40
  61. package/dist/parser/links.js +0 -103
  62. package/dist/parser/list.js +0 -116
  63. package/dist/parser/magicLinks.js +0 -55
  64. package/dist/parser/quotes.js +0 -69
  65. package/dist/parser/redirect.js +0 -28
  66. package/dist/parser/selector.js +0 -393
  67. package/dist/parser/table.js +0 -125
  68. package/dist/src/arg.d.ts +0 -49
  69. package/dist/src/arg.js +0 -219
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -54
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -478
  74. package/dist/src/attributes.d.ts +0 -103
  75. package/dist/src/attributes.js +0 -380
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -153
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -241
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -218
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -223
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -145
  86. package/dist/src/heading.d.ts +0 -44
  87. package/dist/src/heading.js +0 -222
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -82
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -344
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -262
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -148
  96. package/dist/src/imagemapLink.d.ts +0 -35
  97. package/dist/src/imagemapLink.js +0 -99
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -790
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -258
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -36
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -335
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -133
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -100
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -71
  112. package/dist/src/magicLink.d.ts +0 -57
  113. package/dist/src/magicLink.js +0 -261
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -108
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -90
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -123
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -74
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -72
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -30
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -67
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -100
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -77
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -149
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -60
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -80
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -24
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -267
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -62
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -128
  148. package/dist/src/syntax.d.ts +0 -15
  149. package/dist/src/syntax.js +0 -87
  150. package/dist/src/table/base.d.ts +0 -28
  151. package/dist/src/table/base.js +0 -81
  152. package/dist/src/table/index.d.ts +0 -230
  153. package/dist/src/table/index.js +0 -506
  154. package/dist/src/table/td.d.ts +0 -72
  155. package/dist/src/table/td.js +0 -375
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -61
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -165
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -217
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -132
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -130
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -598
  168. package/dist/util/constants.js +0 -26
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -146
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -107
  174. package/errors/README +0 -3
  175. package/printed/README +0 -3
@@ -1,241 +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 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;
@@ -1,71 +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 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
- }
@@ -1,218 +0,0 @@
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;
@@ -1,36 +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 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
- }