wikiparser-node 1.11.0 → 1.11.1-b

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