wikiparser-node 1.3.9 → 1.4.0-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 +1 -0
  12. package/i18n/zh-hant.json +1 -0
  13. package/package.json +30 -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 -51
  18. package/dist/index.d.ts +0 -32
  19. package/dist/index.js +0 -211
  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 -422
  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 -143
  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 -268
  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 -213
  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 -30
  118. package/dist/src/nowiki/quote.js +0 -61
  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 -694
  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,422 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttributeToken = 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 fixed_1 = require("../mixin/fixed");
9
- const Parser = require("../index");
10
- const index_1 = require("./index");
11
- const atom_1 = require("./atom");
12
- const stages = { 'ext-attr': 0, 'html-attr': 2, 'table-attr': 3 };
13
- const commonHtmlAttrs = new Set([
14
- 'id',
15
- 'class',
16
- 'style',
17
- 'lang',
18
- 'dir',
19
- 'title',
20
- 'tabindex',
21
- 'aria-describedby',
22
- 'aria-flowto',
23
- 'aria-hidden',
24
- 'aria-label',
25
- 'aria-labelledby',
26
- 'aria-owns',
27
- 'role',
28
- 'about',
29
- 'property',
30
- 'resource',
31
- 'datatype',
32
- 'typeof',
33
- 'itemid',
34
- 'itemprop',
35
- 'itemref',
36
- 'itemscope',
37
- 'itemtype',
38
- ]), blockAttrs = new Set(['align']), citeAttrs = new Set(['cite']), citeAndAttrs = new Set(['cite', 'datetime']), widthAttrs = new Set(['width']), obsoleteTdAttrs = new Set(['axis', 'align', 'bgcolor', 'height', 'width', 'valign']), tdAttrs = new Set([...obsoleteTdAttrs, 'abbr', 'headers', 'scope', 'rowspan', 'colspan']), typeAttrs = new Set(['type']), obsoleteTableAttrs = new Set(['summary', 'align', 'bgcolor', 'cellpadding', 'cellspacing', 'frame', 'rules', 'width']), brAttrs = new Set(['clear']), trAttrs = new Set(['bgcolor', 'align', 'valign']), htmlAttrs = {
39
- div: blockAttrs,
40
- h1: blockAttrs,
41
- h2: blockAttrs,
42
- h3: blockAttrs,
43
- h4: blockAttrs,
44
- h5: blockAttrs,
45
- h6: blockAttrs,
46
- blockquote: citeAttrs,
47
- q: citeAttrs,
48
- p: blockAttrs,
49
- br: brAttrs,
50
- pre: widthAttrs,
51
- ins: citeAndAttrs,
52
- del: citeAndAttrs,
53
- ul: typeAttrs,
54
- ol: new Set(['type', 'start', 'reversed']),
55
- li: new Set(['type', 'value']),
56
- table: new Set([...obsoleteTableAttrs, 'border']),
57
- caption: blockAttrs,
58
- tr: trAttrs,
59
- td: tdAttrs,
60
- th: tdAttrs,
61
- img: new Set(['alt', 'src', 'width', 'height', 'srcset']),
62
- font: new Set(['size', 'color', 'face']),
63
- hr: widthAttrs,
64
- rt: new Set(['rbspan']),
65
- data: new Set(['value']),
66
- time: new Set(['datetime']),
67
- meta: new Set(['itemprop', 'content']),
68
- link: new Set(['itemprop', 'href', 'title']),
69
- gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails', 'type']),
70
- poem: new Set(['compact', 'align']),
71
- categorytree: new Set([
72
- 'align',
73
- 'hideroot',
74
- 'onlyroot',
75
- 'depth',
76
- 'mode',
77
- 'hideprefix',
78
- 'namespaces',
79
- 'showcount',
80
- 'notranslations',
81
- ]),
82
- combooption: new Set(['name', 'for', 'inline', 'align']),
83
- }, empty = new Set(), extAttrs = {
84
- nowiki: empty,
85
- indicator: new Set(['name']),
86
- langconvert: new Set(['from', 'to']),
87
- ref: new Set(['group', 'name', 'extends', 'follow', 'dir']),
88
- references: new Set(['group', 'responsive']),
89
- charinsert: new Set(['label']),
90
- choose: new Set(['uncached', 'before', 'after']),
91
- option: new Set(['weight']),
92
- imagemap: empty,
93
- inputbox: empty,
94
- templatestyles: new Set(['src', 'wrapper']),
95
- dynamicpagelist: empty,
96
- poll: new Set(['id', 'show-results-before-voting']),
97
- sm2: typeAttrs,
98
- flashmp3: typeAttrs,
99
- score: new Set([
100
- 'line_width_inches',
101
- 'lang',
102
- 'override_midi',
103
- 'raw',
104
- 'note-language',
105
- 'override_audio',
106
- 'override_ogg',
107
- 'sound',
108
- 'vorbis',
109
- ]),
110
- seo: new Set([
111
- 'title',
112
- 'title_mode',
113
- 'title_separator',
114
- 'keywords',
115
- 'description',
116
- 'robots',
117
- 'google_bot',
118
- 'image',
119
- 'image_width',
120
- 'image_height',
121
- 'image_alt',
122
- 'type',
123
- 'site_name',
124
- 'locale',
125
- 'section',
126
- 'author',
127
- 'published_time',
128
- 'twitter_site',
129
- ]),
130
- tab: new Set([
131
- 'nested',
132
- 'name',
133
- 'index',
134
- 'class',
135
- 'block',
136
- 'inline',
137
- 'openname',
138
- 'closename',
139
- 'collapsed',
140
- 'dropdown',
141
- 'style',
142
- 'bgcolor',
143
- 'container',
144
- 'id',
145
- 'title',
146
- ]),
147
- tabs: new Set(['plain', 'class', 'container', 'id', 'title', 'style']),
148
- combobox: new Set(['placeholder', 'value', 'id', 'class', 'text', 'dropdown', 'style']),
149
- }, insecureStyle = new RegExp('expression'
150
- + '|'
151
- + '(?:filter|accelerator|-o-link(?:-source)?|-o-replace)\\s*:'
152
- + '|'
153
- + '(?:url|image(?:-set)?)\\s*\\('
154
- + '|'
155
- + 'attr\\s*\\([^)]+[\\s,]url', 'u'), obsoleteAttrs = {
156
- table: obsoleteTableAttrs,
157
- td: new Set([...obsoleteTdAttrs, 'scope']),
158
- th: obsoleteTdAttrs,
159
- br: brAttrs,
160
- caption: blockAttrs,
161
- div: blockAttrs,
162
- hr: widthAttrs,
163
- h1: blockAttrs,
164
- h2: blockAttrs,
165
- h3: blockAttrs,
166
- h4: blockAttrs,
167
- h5: blockAttrs,
168
- h6: blockAttrs,
169
- li: typeAttrs,
170
- p: blockAttrs,
171
- pre: widthAttrs,
172
- tr: trAttrs,
173
- ul: typeAttrs,
174
- };
175
- /**
176
- * 扩展和HTML标签属性
177
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
178
- */
179
- class AttributeToken extends (0, fixed_1.fixed)(index_1.Token) {
180
- tag;
181
- #equal;
182
- #quotes;
183
- /** 引号是否匹配 */
184
- get balanced() {
185
- return !this.#equal || this.#quotes[0] === this.#quotes[1];
186
- }
187
- /* NOT FOR BROWSER */
188
- set balanced(value) {
189
- if (value) {
190
- this.close();
191
- }
192
- }
193
- /** getValue()的getter */
194
- get value() {
195
- return this.getValue();
196
- }
197
- set value(value) {
198
- this.setValue(value);
199
- }
200
- /* NOT FOR BROWSER END */
201
- /**
202
- * @param type 标签类型
203
- * @param tag 标签名
204
- * @param key 属性名
205
- * @param equal 等号
206
- * @param value 属性值
207
- * @param quotes 引号
208
- */
209
- constructor(type, tag, key, equal = '', value, quotes = [], config = Parser.getConfig(), accum = []) {
210
- const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
211
- [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
212
- });
213
- let valueToken;
214
- if (key === 'title' || tag === 'img' && key === 'alt') {
215
- valueToken = new index_1.Token(value, config, accum, {
216
- [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
217
- });
218
- valueToken.type = 'attr-value';
219
- valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
220
- }
221
- else if (tag === 'gallery' && key === 'caption') {
222
- const newConfig = {
223
- ...config,
224
- excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
225
- };
226
- valueToken = new index_1.Token(value, newConfig, accum, {
227
- AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
228
- });
229
- valueToken.type = 'attr-value';
230
- valueToken.setAttribute('stage', 5);
231
- }
232
- else if (tag === 'choose' && (key === 'before' || key === 'after')) {
233
- const newConfig = {
234
- ...config,
235
- excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
236
- };
237
- valueToken = new index_1.Token(value, newConfig, accum, {
238
- ArgToken: ':',
239
- TranscludeToken: ':',
240
- LinkToken: ':',
241
- FileToken: ':',
242
- CategoryToken: ':',
243
- QuoteToken: ':',
244
- ExtLinkToken: ':',
245
- MagicLinkToken: ':',
246
- ConverterToken: ':',
247
- });
248
- valueToken.type = 'attr-value';
249
- valueToken.setAttribute('stage', 1);
250
- }
251
- else {
252
- valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
253
- [`Stage-${stages[type]}`]: ':',
254
- });
255
- }
256
- super(undefined, config, accum);
257
- this.type = type;
258
- this.append(keyToken, valueToken);
259
- this.#equal = equal;
260
- this.#quotes = [...quotes];
261
- this.tag = tag;
262
- this.seal('tag', true);
263
- this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
264
- }
265
- /** @private */
266
- afterBuild() {
267
- if (this.#equal.includes('\0')) {
268
- this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
269
- }
270
- if (this.parentNode) {
271
- this.setAttribute('tag', this.parentNode.name);
272
- }
273
- this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
274
- }
275
- /** @private */
276
- toString(omit) {
277
- if (omit && this.matchesTypes(omit)) {
278
- return '';
279
- }
280
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
281
- return this.#equal
282
- ? `${super.toString(omit, `${this.#equal}${quoteStart}`)}${quoteEnd}`
283
- : this.firstChild.toString(omit);
284
- }
285
- /** @override */
286
- text() {
287
- return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
288
- }
289
- /** @private */
290
- getGaps() {
291
- return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
292
- }
293
- /** @override */
294
- lint(start = this.getAbsoluteIndex()) {
295
- const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
296
- let rect;
297
- if (!balanced) {
298
- const root = this.getRootNode();
299
- rect = { start, ...root.posFromIndex(start) };
300
- const e = (0, lint_1.generateForChild)(lastChild, rect, Parser.msg('unclosed $1', 'quotes'), 'warning');
301
- errors.push({
302
- ...e,
303
- startIndex: e.startIndex - 1,
304
- startCol: e.startCol - 1,
305
- });
306
- }
307
- if (extAttrs[tag] && !extAttrs[tag].has(name)
308
- || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
309
- && !htmlAttrs[tag]?.has(name)
310
- && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
311
- && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
312
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
313
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal attribute name'));
314
- }
315
- else if (obsoleteAttrs[tag]?.has(name)) {
316
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
317
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete attribute', 'warning'));
318
- }
319
- else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
320
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
321
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure style'));
322
- }
323
- else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
324
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
325
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'nonzero tabindex'));
326
- }
327
- return errors;
328
- }
329
- /** 获取属性值 */
330
- getValue() {
331
- if (this.#equal) {
332
- const value = this.lastChild.text();
333
- if (this.#quotes[1]) {
334
- return value;
335
- }
336
- return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
337
- }
338
- return this.type === 'ext-attr' || '';
339
- }
340
- /** @override */
341
- print() {
342
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
343
- return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
344
- }
345
- /* NOT FOR BROWSER */
346
- /** @private */
347
- getAttribute(key) {
348
- if (key === 'equal') {
349
- return this.#equal;
350
- }
351
- return key === 'quotes' ? this.#quotes : super.getAttribute(key);
352
- }
353
- /** @override */
354
- cloneNode() {
355
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
356
- return debug_1.Shadow.run(() => {
357
- const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
358
- token.firstChild.safeReplaceWith(key);
359
- token.lastChild.safeReplaceWith(value);
360
- token.setAttribute('name', this.name);
361
- return token;
362
- });
363
- }
364
- /** 转义等号 */
365
- escape() {
366
- this.#equal = '{{=}}';
367
- }
368
- /** 闭合引号 */
369
- close() {
370
- const [opening] = this.#quotes;
371
- if (opening) {
372
- this.#quotes[1] = opening;
373
- }
374
- }
375
- /**
376
- * 设置属性值
377
- * @param value 参数值
378
- * @throws `RangeError` 扩展标签属性不能包含 ">"
379
- * @throws `RangeError` 同时包含单引号和双引号
380
- */
381
- setValue(value) {
382
- if (value === false) {
383
- this.remove();
384
- return;
385
- }
386
- else if (value === true) {
387
- this.#equal = '';
388
- return;
389
- }
390
- else if (this.type === 'ext-attr' && value.includes('>')) {
391
- throw new RangeError('扩展标签属性不能包含 ">"!');
392
- }
393
- else if (value.includes('"') && value.includes(`'`)) {
394
- throw new RangeError('属性值不能同时包含单引号和双引号!');
395
- }
396
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
397
- this.lastChild.replaceChildren(...childNodes);
398
- if (value.includes('"')) {
399
- this.#quotes = [`'`, `'`];
400
- }
401
- else if (value.includes(`'`) || !this.#quotes[0]) {
402
- this.#quotes = ['"', '"'];
403
- }
404
- else {
405
- this.close();
406
- }
407
- }
408
- /**
409
- * 修改属性名
410
- * @param key 新属性名
411
- * @throws `Error` title和alt属性不能更名
412
- */
413
- rename(key) {
414
- if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
415
- throw new Error(`${this.name} 属性不能更名!`);
416
- }
417
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
418
- this.firstChild.replaceChildren(...childNodes);
419
- }
420
- }
421
- exports.AttributeToken = AttributeToken;
422
- constants_1.classes['AttributeToken'] = __filename;
@@ -1,109 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { AtomToken } from './atom';
4
- import { AttributeToken } from './attribute';
5
- import type { LintError } from '../base';
6
- import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken } from '../internal';
7
- import type { AttributeTypes } from './attribute';
8
- declare type AttributesTypes = `${AttributeTypes}s`;
9
- /**
10
- * 扩展和HTML标签属性
11
- * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
12
- */
13
- export declare class AttributesToken extends Token {
14
- #private;
15
- type: AttributesTypes;
16
- readonly name: string;
17
- readonly childNodes: (AtomToken | AttributeToken)[];
18
- abstract get children(): (AtomToken | AttributeToken)[];
19
- abstract get firstChild(): AtomToken | AttributeToken | undefined;
20
- abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
21
- abstract get lastChild(): AtomToken | AttributeToken | undefined;
22
- abstract get lastElementChild(): AtomToken | AttributeToken | undefined;
23
- abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
24
- abstract get parentElement(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
25
- /** getAttrs()方法的getter写法 */
26
- get attributes(): Record<string, string | true>;
27
- set attributes(attrs: Record<string, string | true>);
28
- /** 以字符串表示的class属性 */
29
- get className(): string;
30
- set className(className: string);
31
- /** 以Set表示的class属性 */
32
- get classList(): Set<string>;
33
- set classList(classList: Set<string>);
34
- /** id属性 */
35
- get id(): string;
36
- set id(id: string);
37
- /** 是否含有无效属性 */
38
- get sanitized(): boolean;
39
- set sanitized(sanitized: boolean);
40
- /**
41
- * @param attr 标签属性
42
- * @param type 标签类型
43
- * @param name 标签名
44
- */
45
- constructor(attr: string | undefined, type: AttributesTypes, name: string, config?: Parser.Config, accum?: Token[]);
46
- /**
47
- * 所有指定属性名的AttributeToken
48
- * @param key 属性名
49
- */
50
- getAttrTokens(key?: string): readonly AttributeToken[];
51
- /**
52
- * 指定属性名的最后一个AttributeToken
53
- * @param key 属性名
54
- */
55
- getAttrToken(key: string): AttributeToken | undefined;
56
- /**
57
- * 获取指定属性
58
- * @param key 属性键
59
- */
60
- getAttr(key: string): string | true | undefined;
61
- /** @override */
62
- lint(start?: number): LintError[];
63
- /** @override */
64
- print(): string;
65
- /** 清理无效属性 */
66
- sanitize(): void;
67
- /** @override */
68
- cloneNode(): this;
69
- /**
70
- * @override
71
- * @param token 待插入的子节点
72
- * @param i 插入位置
73
- * @throws `RangeError` 标签不匹配
74
- */
75
- insertAt<T extends AttributeToken | AtomToken>(token: T, i?: number): T;
76
- /**
77
- * 设置指定属性
78
- * @param key 属性键
79
- * @param value 属性值
80
- * @param prop 属性对象
81
- * @throws `RangeError` 扩展标签属性不能包含">"
82
- */
83
- setAttr(key: string, value: string | boolean): void;
84
- setAttr(prop: Record<string, string | boolean>): void;
85
- /**
86
- * 标签是否具有某属性
87
- * @param key 属性键
88
- */
89
- hasAttr(key: string): boolean;
90
- /** 获取全部的属性名 */
91
- getAttrNames(): Set<string>;
92
- /** 获取全部属性 */
93
- getAttrs(): Record<string, string | true>;
94
- /**
95
- * 移除指定属性
96
- * @param key 属性键
97
- */
98
- removeAttr(key: string): void;
99
- /**
100
- * 开关指定属性
101
- * @param key 属性键
102
- * @param force 强制开启或关闭
103
- * @throws `RangeError` 不为Boolean类型的属性值
104
- */
105
- toggleAttr(key: string, force?: boolean): void;
106
- /** @override */
107
- text(): string;
108
- }
109
- export {};