wikiparser-node 1.3.6 → 1.3.7-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 -558
  15. package/dist/base.d.ts +0 -45
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -32
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -154
  21. package/dist/lib/element.js +0 -625
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -423
  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 -118
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -247
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -89
  33. package/dist/mixin/fixed.js +0 -25
  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 -54
  40. package/dist/parser/braces.js +0 -128
  41. package/dist/parser/commentAndExt.js +0 -77
  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 -66
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -161
  51. package/dist/parser/table.js +0 -120
  52. package/dist/src/arg.d.ts +0 -56
  53. package/dist/src/arg.js +0 -187
  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 -88
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -109
  59. package/dist/src/attributes.js +0 -344
  60. package/dist/src/converter.d.ts +0 -53
  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 -77
  65. package/dist/src/converterRule.js +0 -208
  66. package/dist/src/extLink.d.ts +0 -55
  67. package/dist/src/extLink.js +0 -122
  68. package/dist/src/gallery.d.ts +0 -54
  69. package/dist/src/gallery.js +0 -121
  70. package/dist/src/heading.d.ts +0 -76
  71. package/dist/src/heading.js +0 -127
  72. package/dist/src/hidden.d.ts +0 -23
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -104
  75. package/dist/src/html.js +0 -226
  76. package/dist/src/imageParameter.d.ts +0 -65
  77. package/dist/src/imageParameter.js +0 -245
  78. package/dist/src/imagemap.d.ts +0 -56
  79. package/dist/src/imagemap.js +0 -147
  80. package/dist/src/imagemapLink.d.ts +0 -61
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -139
  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 -256
  90. package/dist/src/link/galleryImage.d.ts +0 -45
  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 -69
  95. package/dist/src/magicLink.js +0 -146
  96. package/dist/src/nested.d.ts +0 -43
  97. package/dist/src/nested.js +0 -86
  98. package/dist/src/nowiki/base.d.ts +0 -48
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -41
  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 -47
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -33
  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 -31
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -20
  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 -24
  116. package/dist/src/nowiki/quote.d.ts +0 -24
  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 -86
  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 -30
  129. package/dist/src/syntax.js +0 -34
  130. package/dist/src/table/base.d.ts +0 -55
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -228
  133. package/dist/src/table/index.js +0 -378
  134. package/dist/src/table/td.d.ts +0 -107
  135. package/dist/src/table/td.js +0 -260
  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 -53
  139. package/dist/src/table/trBase.js +0 -151
  140. package/dist/src/tagPair/ext.d.ts +0 -58
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -54
  143. package/dist/src/tagPair/include.js +0 -63
  144. package/dist/src/tagPair/index.d.ts +0 -49
  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 -696
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -83
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -30
  152. package/dist/util/string.js +0 -51
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
@@ -1,344 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttributesToken = void 0;
4
- const lint_1 = require("../util/lint");
5
- const string_1 = require("../util/string");
6
- const debug_1 = require("../util/debug");
7
- const constants_1 = require("../util/constants");
8
- const Parser = require("../index");
9
- const index_1 = require("./index");
10
- const atom_1 = require("./atom");
11
- const attribute_1 = require("./attribute");
12
- /* NOT FOR BROWSER */
13
- const stages = { 'ext-attrs': 0, 'html-attrs': 2, 'table-attrs': 3 };
14
- /**
15
- * 将属性类型转换为单属性类型
16
- * @param type 属性类型
17
- */
18
- const toAttributeType = (type) => type.slice(0, -1);
19
- /**
20
- * 将属性类型转换为无效属性类型
21
- * @param type 属性类型
22
- */
23
- const toDirty = (type) => `${toAttributeType(type)}-dirty`;
24
- /**
25
- * 扩展和HTML标签属性
26
- * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
27
- */
28
- class AttributesToken extends index_1.Token {
29
- /* NOT FOR BROWSER */
30
- /** getAttrs()方法的getter写法 */
31
- get attributes() {
32
- return this.getAttrs();
33
- }
34
- set attributes(attrs) {
35
- this.replaceChildren();
36
- this.setAttr(attrs);
37
- }
38
- /** 以字符串表示的class属性 */
39
- get className() {
40
- const attr = this.getAttr('class');
41
- return typeof attr === 'string' ? attr : '';
42
- }
43
- set className(className) {
44
- this.setAttr('class', className || false);
45
- }
46
- /** 以Set表示的class属性 */
47
- get classList() {
48
- return new Set(this.className.split(/\s/u));
49
- }
50
- set classList(classList) {
51
- this.setAttr('class', [...classList].join(' '));
52
- }
53
- /** id属性 */
54
- get id() {
55
- const attr = this.getAttr('id');
56
- return typeof attr === 'string' ? attr : '';
57
- }
58
- set id(id) {
59
- this.setAttr('id', id || false);
60
- }
61
- /** 是否含有无效属性 */
62
- get sanitized() {
63
- return this.childNodes.filter(child => child instanceof atom_1.AtomToken && child.text().trim()).length === 0;
64
- }
65
- set sanitized(sanitized) {
66
- if (sanitized) {
67
- this.sanitize();
68
- }
69
- }
70
- /* NOT FOR BROWSER END */
71
- /**
72
- * @param attr 标签属性
73
- * @param type 标签类型
74
- * @param name 标签名
75
- */
76
- constructor(attr, type, name, config = Parser.getConfig(), accum = []) {
77
- super(undefined, config, accum, {
78
- AtomToken: ':', AttributeToken: ':',
79
- });
80
- this.type = type;
81
- this.setAttribute('name', name);
82
- if (attr) {
83
- const regex = new RegExp('([^\\s/](?:(?!\0\\d+~\x7F)[^\\s/=])*)' // 属性名
84
- + '(?:'
85
- + '((?:\\s|\0\\d+c\x7F)*' // `=`前的空白字符
86
- + '(?:=|\0\\d+~\x7F)' // `=`
87
- + '(?:\\s|\0\\d+c\x7F)*)' // `=`后的空白字符
88
- + `(?:(["'])(.*?)(\\3|$)|(\\S*))` // 属性值
89
- + ')?', 'gsu');
90
- let out = '', mt = regex.exec(attr), lastIndex = 0;
91
- const insertDirty = /** 插入无效属性 */ () => {
92
- if (out) {
93
- super.insertAt(new atom_1.AtomToken(out, toDirty(type), config, accum, {
94
- [`Stage-${stages[type]}`]: ':',
95
- }));
96
- out = '';
97
- }
98
- };
99
- while (mt) {
100
- const { index, 0: full, 1: key, 2: equal, 3: quoteStart, 4: quoted, 5: quoteEnd, 6: unquoted } = mt;
101
- out += attr.slice(lastIndex, index);
102
- if (/^(?:[\w:]|\0\d+[t!~{}+-]\x7F)(?:[\w:.-]|\0\d+[t!~{}+-]\x7F)*$/u.test((0, string_1.removeComment)(key).trim())) {
103
- const value = quoted ?? unquoted, quotes = [quoteStart, quoteEnd], token = new attribute_1.AttributeToken(toAttributeType(type), name, key, equal, value, quotes, config, accum);
104
- insertDirty();
105
- super.insertAt(token);
106
- }
107
- else {
108
- out += full;
109
- }
110
- ({ lastIndex } = regex);
111
- mt = regex.exec(attr);
112
- }
113
- out += attr.slice(lastIndex);
114
- insertDirty();
115
- }
116
- }
117
- /** @private */
118
- afterBuild() {
119
- if (this.type === 'table-attrs') {
120
- const { parentNode } = this;
121
- this.setAttribute('name', parentNode?.type === 'td' && parentNode.subtype === 'caption' ? 'caption' : parentNode?.type);
122
- }
123
- }
124
- /**
125
- * 所有指定属性名的AttributeToken
126
- * @param key 属性名
127
- */
128
- getAttrTokens(key) {
129
- return this.childNodes.filter((child) => child instanceof attribute_1.AttributeToken && (!key || child.name === key.toLowerCase().trim()));
130
- }
131
- /**
132
- * 指定属性名的最后一个AttributeToken
133
- * @param key 属性名
134
- */
135
- getAttrToken(key) {
136
- const tokens = this.getAttrTokens(key);
137
- return tokens.at(-1);
138
- }
139
- /**
140
- * 获取指定属性
141
- * @param key 属性键
142
- */
143
- getAttr(key) {
144
- return this.getAttrToken(key)?.getValue();
145
- }
146
- /** @override */
147
- lint(start = this.getAbsoluteIndex()) {
148
- const errors = super.lint(start), { parentNode, length, childNodes } = this, attrs = new Map(), duplicated = new Set();
149
- let rect;
150
- if (parentNode?.type === 'html' && parentNode.closing && this.text().trim()) {
151
- rect = { start, ...this.getRootNode().posFromIndex(start) };
152
- errors.push((0, lint_1.generateForSelf)(this, rect, 'attributes of a closing tag'));
153
- }
154
- for (let i = 0; i < length; i++) {
155
- const attr = childNodes[i];
156
- if (attr instanceof atom_1.AtomToken && attr.text().trim()) {
157
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
158
- errors.push((0, lint_1.generateForChild)(attr, rect, 'containing invalid attribute'));
159
- }
160
- else if (attr instanceof attribute_1.AttributeToken) {
161
- const { name } = attr;
162
- if (attrs.has(name)) {
163
- duplicated.add(name);
164
- attrs.get(name).push(attr);
165
- }
166
- else if (name !== 'class') {
167
- attrs.set(name, [attr]);
168
- }
169
- }
170
- }
171
- if (duplicated.size > 0) {
172
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
173
- for (const key of duplicated) {
174
- errors.push(...attrs.get(key).map(attr => (0, lint_1.generateForChild)(attr, rect, Parser.msg('duplicated $1 attribute', key))));
175
- }
176
- }
177
- return errors;
178
- }
179
- /** @override */
180
- print() {
181
- return String(this)
182
- ? `<span class="wpb-${this.type}">${this.childNodes.map(child => child.print(child instanceof atom_1.AtomToken && child.text().trim() ? { class: 'attr-dirty' } : undefined)).join('')}</span>`
183
- : '';
184
- }
185
- /* NOT FOR BROWSER */
186
- /** 清理无效属性 */
187
- sanitize() {
188
- let dirty = false;
189
- for (let i = this.length - 1; i >= 0; i--) {
190
- const child = this.childNodes[i];
191
- if (child instanceof atom_1.AtomToken && child.text().trim()) {
192
- dirty = true;
193
- this.removeAt(i);
194
- }
195
- }
196
- if (!debug_1.Shadow.running && dirty) {
197
- Parser.warn(`${this.constructor.name}.sanitize 方法将清理无效属性!`);
198
- }
199
- }
200
- /** @override */
201
- cloneNode() {
202
- const cloned = this.cloneChildNodes();
203
- return debug_1.Shadow.run(() => {
204
- const token = new AttributesToken(undefined, this.type, this.name, this.getAttribute('config'));
205
- token.append(...cloned);
206
- token.setAttribute('name', this.name);
207
- return token;
208
- });
209
- }
210
- /**
211
- * @override
212
- * @param token 待插入的子节点
213
- * @param i 插入位置
214
- * @throws `RangeError` 标签不匹配
215
- */
216
- insertAt(token, i = this.length) {
217
- if (!(token instanceof attribute_1.AttributeToken)) {
218
- if (String(token).trim()) {
219
- this.constructorError('只能插入 AttributeToken');
220
- }
221
- return super.insertAt(token, i);
222
- }
223
- else if (token.type !== this.type.slice(0, -1) || token.tag !== this.name) {
224
- throw new RangeError(`待插入的AttributeToken只可用于${token.tag}标签!`);
225
- }
226
- else if (i === this.length) {
227
- const { lastChild } = this;
228
- if (lastChild instanceof attribute_1.AttributeToken) {
229
- lastChild.close();
230
- }
231
- }
232
- else {
233
- token.close();
234
- }
235
- if (this.closest('parameter')) {
236
- token.escape();
237
- }
238
- super.insertAt(token, i);
239
- const { previousVisibleSibling, nextVisibleSibling } = token, type = toDirty(this.type), config = this.getAttribute('config'), acceptable = { [`Stage-${stages[this.type]}`]: ':' };
240
- if (nextVisibleSibling && !/^\s/u.test(String(nextVisibleSibling))) {
241
- super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(' ', type, config, [], acceptable)), i + 1);
242
- }
243
- if (previousVisibleSibling && !/\s$/u.test(String(previousVisibleSibling))) {
244
- super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(' ', type, config, [], acceptable)), i);
245
- }
246
- return token;
247
- }
248
- setAttr(keyOrProp, value) {
249
- if (typeof keyOrProp !== 'string') {
250
- for (const [key, val] of Object.entries(keyOrProp)) {
251
- this.setAttr(key, val);
252
- }
253
- return;
254
- }
255
- else if (this.type === 'ext-attrs' && typeof value === 'string' && value.includes('>')) {
256
- throw new RangeError('扩展标签属性不能包含 ">"!');
257
- }
258
- const key = keyOrProp.toLowerCase().trim(), attr = this.getAttrToken(key);
259
- if (attr) {
260
- attr.setValue(value);
261
- return;
262
- }
263
- else if (value === false) {
264
- return;
265
- }
266
- const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken(toAttributeType(this.type), this.name, key, value === true ? '' : '=', value === true ? '' : value, ['"', '"'], this.getAttribute('config')));
267
- this.insertAt(token);
268
- }
269
- /**
270
- * 标签是否具有某属性
271
- * @param key 属性键
272
- */
273
- hasAttr(key) {
274
- return this.getAttrTokens(key).length > 0;
275
- }
276
- /** 获取全部的属性名 */
277
- getAttrNames() {
278
- return new Set(this.getAttrTokens().map(({ name }) => name));
279
- }
280
- /** 获取全部属性 */
281
- getAttrs() {
282
- return Object.fromEntries(this.getAttrTokens().map(({ name, value }) => [name, value]));
283
- }
284
- /**
285
- * 移除指定属性
286
- * @param key 属性键
287
- */
288
- removeAttr(key) {
289
- for (const attr of this.getAttrTokens(key)) {
290
- attr.remove();
291
- }
292
- }
293
- /**
294
- * 开关指定属性
295
- * @param key 属性键
296
- * @param force 强制开启或关闭
297
- * @throws `RangeError` 不为Boolean类型的属性值
298
- */
299
- toggleAttr(key, force) {
300
- key = key.toLowerCase().trim();
301
- const attr = this.getAttrToken(key);
302
- if (attr && attr.getValue() !== true) {
303
- throw new RangeError(`${key} 属性的值不为 Boolean!`);
304
- }
305
- else if (attr) {
306
- attr.setValue(force === true);
307
- }
308
- else if (force !== false) {
309
- this.setAttr(key, true);
310
- }
311
- }
312
- /**
313
- * 生成引导空格
314
- * @param str 属性字符串
315
- */
316
- #leadingSpace(str) {
317
- const { type } = this, leadingRegex = { 'ext-attrs': /^\s/u, 'html-attrs': /^[/\s]/u };
318
- return str && type !== 'table-attrs' && !leadingRegex[type].test(str) ? ' ' : '';
319
- }
320
- /** @private */
321
- toString(omit) {
322
- if (this.type === 'table-attrs') {
323
- (0, string_1.normalizeSpace)(this);
324
- }
325
- const str = super.toString(omit);
326
- return `${this.#leadingSpace(str)}${str}`;
327
- }
328
- /** @private */
329
- getAttribute(key) {
330
- return key === 'padding'
331
- ? this.#leadingSpace(super.toString()).length
332
- : super.getAttribute(key);
333
- }
334
- /** @override */
335
- text() {
336
- if (this.type === 'table-attrs') {
337
- (0, string_1.normalizeSpace)(this);
338
- }
339
- const str = (0, string_1.text)(this.childNodes.filter(child => child instanceof attribute_1.AttributeToken), ' ');
340
- return `${this.#leadingSpace(str)}${str}`;
341
- }
342
- }
343
- exports.AttributesToken = AttributesToken;
344
- constants_1.classes['AttributesToken'] = __filename;
@@ -1,53 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { ConverterFlagsToken } from './converterFlags';
4
- import { ConverterRuleToken } from './converterRule';
5
- declare const ConverterToken_base: (abstract new (...args: any[]) => {
6
- readonly firstChild: Parser.ConverterFlagsToken;
7
- readonly firstElementChild: Parser.ConverterFlagsToken;
8
- flags: Set<string>;
9
- getAllFlags(): Set<string>;
10
- getEffectiveFlags(): Set<string>;
11
- getUnknownFlags(): Set<string>;
12
- hasFlag(flag: string): boolean;
13
- hasEffectiveFlag(flag: string): boolean;
14
- removeFlag(flag: string): void;
15
- setFlag(flag: string): void;
16
- toggleFlag(flag: string): void;
17
- readonly length: number;
18
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
19
- text(separator?: string | undefined): string;
20
- lint(start?: number | undefined): Parser.LintError[];
21
- insertAt(token: unknown, i?: number | undefined): unknown;
22
- afterBuild(): void;
23
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
24
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
25
- addEventListener(events: string | string[], listener: AstListener): void;
26
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
27
- constructorError(msg: string): never;
28
- }) & typeof Parser.Token;
29
- /**
30
- * 转换
31
- * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
32
- */
33
- export declare class ConverterToken extends ConverterToken_base {
34
- readonly type = "converter";
35
- readonly childNodes: [ConverterFlagsToken, ...ConverterRuleToken[]];
36
- abstract get children(): [ConverterFlagsToken, ...ConverterRuleToken[]];
37
- abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
38
- abstract get lastElementChild(): ConverterFlagsToken | ConverterRuleToken;
39
- /** 是否不转换 */
40
- get noConvert(): boolean;
41
- /**
42
- * @param flags 转换类型标记
43
- * @param rules 转换规则
44
- */
45
- constructor(flags: readonly string[], rules: readonly [string, ...string[]], config?: Parser.Config, accum?: Token[]);
46
- /** @override */
47
- text(): string;
48
- /** @override */
49
- print(): string;
50
- /** @override */
51
- cloneNode(): this;
52
- }
53
- export {};
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConverterToken = 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 flagsParent_1 = require("../mixin/flagsParent");
8
- const Parser = require("../index");
9
- const index_1 = require("./index");
10
- const converterFlags_1 = require("./converterFlags");
11
- const converterRule_1 = require("./converterRule");
12
- /**
13
- * 转换
14
- * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
15
- */
16
- class ConverterToken extends (0, flagsParent_1.flagsParent)(index_1.Token) {
17
- type = 'converter';
18
- /* NOT FOR BROWSER */
19
- /** 是否不转换 */
20
- get noConvert() {
21
- return this.hasFlag('R') || this.length === 2 && this.lastChild.length === 1;
22
- }
23
- /* NOT FOR BROWSER END */
24
- /**
25
- * @param flags 转换类型标记
26
- * @param rules 转换规则
27
- */
28
- constructor(flags, rules, config = Parser.getConfig(), accum = []) {
29
- super(undefined, config, accum);
30
- this.append(new converterFlags_1.ConverterFlagsToken(flags, config, accum));
31
- const [firstRule] = rules, hasColon = firstRule.includes(':'), firstRuleToken = new converterRule_1.ConverterRuleToken(firstRule, hasColon, config, accum);
32
- if (hasColon && firstRuleToken.length === 1) {
33
- this.insertAt(new converterRule_1.ConverterRuleToken(rules.join(';'), false, config, accum));
34
- }
35
- else {
36
- this.append(firstRuleToken, ...rules.slice(1).map(rule => new converterRule_1.ConverterRuleToken(rule, true, config, accum)));
37
- }
38
- this.protectChildren(0);
39
- }
40
- /** @private */
41
- toString(omit) {
42
- const { childNodes: [flags, ...rules] } = this;
43
- return omit && this.matchesTypes(omit)
44
- ? ''
45
- : `-{${flags.toString(omit)}${flags.length > 0 ? '|' : ''}${rules.map(rule => rule.toString(omit)).join(';')}}-`;
46
- }
47
- /** @override */
48
- text() {
49
- const { childNodes: [flags, ...rules] } = this;
50
- return `-{${flags.text()}|${(0, string_1.text)(rules, ';')}}-`;
51
- }
52
- /** @private */
53
- getAttribute(key) {
54
- return key === 'padding' ? 2 : super.getAttribute(key);
55
- }
56
- /** @private */
57
- getGaps(i) {
58
- return i || this.firstChild.length > 0 ? 1 : 0;
59
- }
60
- /** @override */
61
- print() {
62
- const { childNodes: [flags, ...rules] } = this;
63
- return `<span class="wpb-converter">-{${flags.print()}${flags.length > 0 ? '|' : ''}${(0, string_1.print)(rules, { sep: ';' })}}-</span>`;
64
- }
65
- /* NOT FOR BROWSER */
66
- /** @override */
67
- cloneNode() {
68
- const [flags, ...rules] = this.cloneChildNodes();
69
- return debug_1.Shadow.run(() => {
70
- const token = new ConverterToken([], [''], this.getAttribute('config'));
71
- token.firstChild.safeReplaceWith(flags);
72
- token.removeAt(1);
73
- token.append(...rules);
74
- return token;
75
- });
76
- }
77
- }
78
- exports.ConverterToken = ConverterToken;
79
- constants_1.classes['ConverterToken'] = __filename;
@@ -1,87 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { AtomToken } from './atom';
4
- import type { LintError } from '../base';
5
- import type { ConverterToken, ConverterRuleToken } from '../internal';
6
- /**
7
- * 转换flags
8
- * @classdesc `{childNodes: ...AtomToken}`
9
- */
10
- export declare class ConverterFlagsToken extends Token {
11
- #private;
12
- readonly type = "converter-flags";
13
- readonly childNodes: AtomToken[];
14
- abstract get children(): AtomToken[];
15
- abstract get firstChild(): AtomToken | undefined;
16
- abstract get firstElementChild(): AtomToken | undefined;
17
- abstract get lastChild(): AtomToken | undefined;
18
- abstract get lastElementChild(): AtomToken | undefined;
19
- abstract get parentNode(): ConverterToken | undefined;
20
- abstract get parentElement(): ConverterToken | undefined;
21
- abstract get previousSibling(): undefined;
22
- abstract get previousElementSibling(): undefined;
23
- abstract get nextSibling(): ConverterRuleToken | undefined;
24
- abstract get nextElementSibling(): ConverterRuleToken | undefined;
25
- /** 所有转换类型标记 */
26
- get flags(): Set<string>;
27
- set flags(value: Set<string>);
28
- /** @param flags 转换类型标记 */
29
- constructor(flags: readonly string[], config?: Parser.Config, accum?: Token[]);
30
- /** @override */
31
- text(): string;
32
- /** 获取未知的转换类型标记 */
33
- getUnknownFlags(): Set<string>;
34
- /** 获取指定语言变体的转换标记 */
35
- getVariantFlags(): Set<string>;
36
- /** @override */
37
- lint(start?: number): LintError[];
38
- /** @override */
39
- print(): string;
40
- /** @override */
41
- cloneNode(): this;
42
- /**
43
- * @override
44
- * @param i 移除位置
45
- */
46
- removeAt(i: number): AtomToken;
47
- /**
48
- * @override
49
- * @param token 待插入的子节点
50
- * @param i 插入位置
51
- */
52
- insertAt<T extends AtomToken>(token: T, i?: number): T;
53
- /** 获取所有转换类型标记 */
54
- getAllFlags(): Set<string>;
55
- /**
56
- * 获取转换类型标记节点
57
- * @param flag 转换类型标记
58
- */
59
- getFlagTokens(flag: string): readonly AtomToken[];
60
- /** 获取有效的转换类型标记 */
61
- getEffectiveFlags(): Set<string>;
62
- /**
63
- * 是否具有某转换类型标记
64
- * @param flag 转换类型标记
65
- */
66
- hasFlag(flag: string): boolean;
67
- /**
68
- * 是否具有某有效的转换类型标记
69
- * @param flag 转换类型标记
70
- */
71
- hasEffectiveFlag(flag: string): boolean;
72
- /**
73
- * 移除某转换类型标记
74
- * @param flag 转换类型标记
75
- */
76
- removeFlag(flag: string): void;
77
- /**
78
- * 设置转换类型标记
79
- * @param flag 转换类型标记
80
- */
81
- setFlag(flag: string): void;
82
- /**
83
- * 开关转换类型标记
84
- * @param flag 转换类型标记
85
- */
86
- toggleFlag(flag: string): void;
87
- }