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