wikiparser-node 1.3.2 → 1.3.3-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 (154) 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 +68 -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/package.json +32 -12
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -564
  15. package/dist/base.d.ts +0 -45
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -31
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -634
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -419
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -117
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -248
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -94
  33. package/dist/mixin/fixed.js +0 -32
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -26
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -56
  40. package/dist/parser/braces.js +0 -121
  41. package/dist/parser/commentAndExt.js +0 -69
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -59
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -162
  51. package/dist/parser/table.js +0 -112
  52. package/dist/src/arg.d.ts +0 -58
  53. package/dist/src/arg.js +0 -189
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -87
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -107
  59. package/dist/src/attributes.js +0 -341
  60. package/dist/src/converter.d.ts +0 -52
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -224
  64. package/dist/src/converterRule.d.ts +0 -81
  65. package/dist/src/converterRule.js +0 -212
  66. package/dist/src/extLink.d.ts +0 -54
  67. package/dist/src/extLink.js +0 -122
  68. package/dist/src/gallery.d.ts +0 -55
  69. package/dist/src/gallery.js +0 -122
  70. package/dist/src/heading.d.ts +0 -74
  71. package/dist/src/heading.js +0 -127
  72. package/dist/src/hidden.d.ts +0 -22
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -101
  75. package/dist/src/html.js +0 -222
  76. package/dist/src/imageParameter.d.ts +0 -66
  77. package/dist/src/imageParameter.js +0 -247
  78. package/dist/src/imagemap.d.ts +0 -57
  79. package/dist/src/imagemap.js +0 -148
  80. package/dist/src/imagemapLink.d.ts +0 -59
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -146
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -209
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -255
  90. package/dist/src/link/galleryImage.d.ts +0 -44
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -70
  95. package/dist/src/magicLink.js +0 -147
  96. package/dist/src/nested.d.ts +0 -44
  97. package/dist/src/nested.js +0 -87
  98. package/dist/src/nowiki/base.d.ts +0 -47
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -40
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -45
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -31
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -30
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -19
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -26
  115. package/dist/src/nowiki/noinclude.js +0 -25
  116. package/dist/src/nowiki/quote.d.ts +0 -23
  117. package/dist/src/nowiki/quote.js +0 -45
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -85
  125. package/dist/src/parameter.js +0 -205
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -28
  129. package/dist/src/syntax.js +0 -34
  130. package/dist/src/table/base.d.ts +0 -53
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -229
  133. package/dist/src/table/index.js +0 -379
  134. package/dist/src/table/td.d.ts +0 -104
  135. package/dist/src/table/td.js +0 -261
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -54
  139. package/dist/src/table/trBase.js +0 -159
  140. package/dist/src/tagPair/ext.d.ts +0 -56
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -53
  143. package/dist/src/tagPair/include.js +0 -63
  144. package/dist/src/tagPair/index.d.ts +0 -48
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -689
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -64
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -46
  152. package/dist/util/string.js +0 -61
  153. package/errors/README +0 -1
  154. 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,81 +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
- * @throws `Error` 至少保留1个子节点
49
- */
50
- removeAt(i: number): AtomToken;
51
- /**
52
- * @override
53
- * @throws `Error` 请勿手动插入子节点
54
- */
55
- insertAt(): never;
56
- /** 修改为不转换 */
57
- noConvert(): void;
58
- /**
59
- * 设置转换目标
60
- * @param to 转换目标
61
- */
62
- setTo(to: string): void;
63
- /**
64
- * 设置语言变体
65
- * @param variant 语言变体
66
- */
67
- setVariant(variant: string): void;
68
- /**
69
- * 设置转换原文
70
- * @param from 转换原文
71
- * @throws `Error` 尚未指定语言变体
72
- */
73
- setFrom(from: string): void;
74
- /**
75
- * 修改为单向转换
76
- * @param from 转换原文
77
- */
78
- makeUnidirectional(from: string): void;
79
- /** 修改为双向转换 */
80
- makeBidirectional(): void;
81
- }
@@ -1,212 +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.at(-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.at(-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
- * @throws `Error` 至少保留1个子节点
139
- */
140
- removeAt(i) {
141
- if (this.length === 1) {
142
- throw new Error(`${this.constructor.name} 需至少保留 1 个子节点!`);
143
- }
144
- return super.removeAt(i);
145
- }
146
- /**
147
- * @override
148
- * @throws `Error` 请勿手动插入子节点
149
- */
150
- insertAt() {
151
- throw new Error(`转换规则语法复杂,请勿尝试对 ${this.constructor.name} 手动插入子节点!`);
152
- }
153
- /** 修改为不转换 */
154
- noConvert() {
155
- const { length } = this;
156
- for (let i = 0; i < length - 1; i++) { // ConverterRuleToken只能从前往后删除子节点
157
- this.removeAt(0);
158
- }
159
- }
160
- /**
161
- * 设置转换目标
162
- * @param to 转换目标
163
- */
164
- setTo(to) {
165
- const { childNodes } = Parser.parse(to, this.getAttribute('include'), undefined, this.getAttribute('config'));
166
- this.lastChild.replaceChildren(...childNodes);
167
- }
168
- /**
169
- * 设置语言变体
170
- * @param variant 语言变体
171
- */
172
- setVariant(variant) {
173
- const config = this.getAttribute('config');
174
- if (this.length === 1) {
175
- super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(variant, 'converter-rule-variant', config)), 0);
176
- }
177
- else {
178
- this.childNodes.at(-2).setText(variant);
179
- }
180
- }
181
- /**
182
- * 设置转换原文
183
- * @param from 转换原文
184
- * @throws `Error` 尚未指定语言变体
185
- */
186
- setFrom(from) {
187
- const { variant, unidirectional } = this;
188
- if (!variant) {
189
- throw new Error('请先指定语言变体!');
190
- }
191
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(from, this.getAttribute('include'), undefined, config);
192
- if (!unidirectional) {
193
- super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'converter-rule-from', config)), 0);
194
- }
195
- this.firstChild.replaceChildren(...childNodes);
196
- }
197
- /**
198
- * 修改为单向转换
199
- * @param from 转换原文
200
- */
201
- makeUnidirectional(from) {
202
- this.setFrom(from);
203
- }
204
- /** 修改为双向转换 */
205
- makeBidirectional() {
206
- if (this.unidirectional) {
207
- this.removeAt(0);
208
- }
209
- }
210
- }
211
- exports.ConverterRuleToken = ConverterRuleToken;
212
- constants_1.classes['ConverterRuleToken'] = __filename;
@@ -1,54 +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
- }) & typeof Parser.Token;
22
- /**
23
- * 外链
24
- * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
25
- */
26
- export declare class ExtLinkToken extends ExtLinkToken_base {
27
- #private;
28
- readonly type = "ext-link";
29
- readonly childNodes: [MagicLinkToken] | [MagicLinkToken, Token];
30
- abstract get children(): [MagicLinkToken] | [MagicLinkToken, Token];
31
- abstract get lastChild(): Token;
32
- abstract get lastElementChild(): Token;
33
- /** 链接显示文字 */
34
- get innerText(): string;
35
- set innerText(text: string);
36
- /**
37
- * @param url 网址
38
- * @param space 空白字符
39
- * @param text 链接文字
40
- */
41
- constructor(url?: string, space?: string, text?: string, config?: Parser.Config, accum?: Token[]);
42
- /** @override */
43
- text(): string;
44
- /** @override */
45
- print(): string;
46
- /** @override */
47
- cloneNode(): this;
48
- /**
49
- * 设置链接显示文字
50
- * @param str 链接显示文字
51
- */
52
- setLinkText(str: string): void;
53
- }
54
- 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;