wikiparser-node 1.4.2 → 1.4.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 (162) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +59 -0
  9. package/extensions/dist/lint.js +48 -0
  10. package/extensions/editor.css +63 -0
  11. package/extensions/ui.css +141 -0
  12. package/package.json +30 -15
  13. package/config/.schema.json +0 -172
  14. package/dist/addon/table.d.ts +0 -6
  15. package/dist/addon/table.js +0 -560
  16. package/dist/base.d.ts +0 -53
  17. package/dist/index.d.ts +0 -32
  18. package/dist/index.js +0 -211
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -154
  21. package/dist/lib/element.js +0 -643
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -425
  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 -306
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -172
  32. package/dist/mixin/attributesParent.d.ts +0 -20
  33. package/dist/mixin/attributesParent.js +0 -89
  34. package/dist/mixin/fixed.d.ts +0 -5
  35. package/dist/mixin/fixed.js +0 -28
  36. package/dist/mixin/flagsParent.d.ts +0 -61
  37. package/dist/mixin/flagsParent.js +0 -72
  38. package/dist/mixin/hidden.d.ts +0 -5
  39. package/dist/mixin/hidden.js +0 -24
  40. package/dist/mixin/magicLinkParent.d.ts +0 -34
  41. package/dist/mixin/magicLinkParent.js +0 -43
  42. package/dist/mixin/singleLine.d.ts +0 -5
  43. package/dist/mixin/singleLine.js +0 -25
  44. package/dist/mixin/sol.d.ts +0 -8
  45. package/dist/mixin/sol.js +0 -41
  46. package/dist/mixin/syntax.d.ts +0 -6
  47. package/dist/mixin/syntax.js +0 -54
  48. package/dist/parser/braces.js +0 -131
  49. package/dist/parser/commentAndExt.js +0 -90
  50. package/dist/parser/converter.js +0 -41
  51. package/dist/parser/externalLinks.js +0 -32
  52. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  53. package/dist/parser/html.js +0 -39
  54. package/dist/parser/links.js +0 -97
  55. package/dist/parser/list.js +0 -68
  56. package/dist/parser/magicLinks.js +0 -43
  57. package/dist/parser/quotes.js +0 -68
  58. package/dist/parser/selector.js +0 -162
  59. package/dist/parser/table.js +0 -124
  60. package/dist/src/arg.d.ts +0 -58
  61. package/dist/src/arg.js +0 -196
  62. package/dist/src/atom.d.ts +0 -12
  63. package/dist/src/atom.js +0 -27
  64. package/dist/src/attribute.d.ts +0 -67
  65. package/dist/src/attribute.js +0 -422
  66. package/dist/src/attributes.d.ts +0 -109
  67. package/dist/src/attributes.js +0 -347
  68. package/dist/src/converter.d.ts +0 -28
  69. package/dist/src/converter.js +0 -85
  70. package/dist/src/converterFlags.d.ts +0 -87
  71. package/dist/src/converterFlags.js +0 -227
  72. package/dist/src/converterRule.d.ts +0 -77
  73. package/dist/src/converterRule.js +0 -210
  74. package/dist/src/extLink.d.ts +0 -38
  75. package/dist/src/extLink.js +0 -137
  76. package/dist/src/gallery.d.ts +0 -54
  77. package/dist/src/gallery.js +0 -127
  78. package/dist/src/heading.d.ts +0 -47
  79. package/dist/src/heading.js +0 -143
  80. package/dist/src/hidden.d.ts +0 -7
  81. package/dist/src/hidden.js +0 -23
  82. package/dist/src/html.d.ts +0 -62
  83. package/dist/src/html.js +0 -286
  84. package/dist/src/imageParameter.d.ts +0 -65
  85. package/dist/src/imageParameter.js +0 -247
  86. package/dist/src/imagemap.d.ts +0 -56
  87. package/dist/src/imagemap.js +0 -156
  88. package/dist/src/imagemapLink.d.ts +0 -28
  89. package/dist/src/imagemapLink.js +0 -44
  90. package/dist/src/index.d.ts +0 -143
  91. package/dist/src/index.js +0 -804
  92. package/dist/src/link/base.d.ts +0 -52
  93. package/dist/src/link/base.js +0 -212
  94. package/dist/src/link/category.d.ts +0 -13
  95. package/dist/src/link/category.js +0 -28
  96. package/dist/src/link/file.d.ts +0 -96
  97. package/dist/src/link/file.js +0 -266
  98. package/dist/src/link/galleryImage.d.ts +0 -31
  99. package/dist/src/link/galleryImage.js +0 -109
  100. package/dist/src/link/index.d.ts +0 -56
  101. package/dist/src/link/index.js +0 -134
  102. package/dist/src/magicLink.d.ts +0 -51
  103. package/dist/src/magicLink.js +0 -149
  104. package/dist/src/nested.d.ts +0 -43
  105. package/dist/src/nested.js +0 -91
  106. package/dist/src/nowiki/base.d.ts +0 -27
  107. package/dist/src/nowiki/base.js +0 -42
  108. package/dist/src/nowiki/comment.d.ts +0 -27
  109. package/dist/src/nowiki/comment.js +0 -77
  110. package/dist/src/nowiki/dd.d.ts +0 -8
  111. package/dist/src/nowiki/dd.js +0 -24
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  113. package/dist/src/nowiki/doubleUnderscore.js +0 -51
  114. package/dist/src/nowiki/hr.d.ts +0 -8
  115. package/dist/src/nowiki/hr.js +0 -14
  116. package/dist/src/nowiki/index.d.ts +0 -16
  117. package/dist/src/nowiki/index.js +0 -20
  118. package/dist/src/nowiki/list.d.ts +0 -19
  119. package/dist/src/nowiki/list.js +0 -48
  120. package/dist/src/nowiki/listBase.d.ts +0 -5
  121. package/dist/src/nowiki/listBase.js +0 -11
  122. package/dist/src/nowiki/noinclude.d.ts +0 -10
  123. package/dist/src/nowiki/noinclude.js +0 -23
  124. package/dist/src/nowiki/quote.d.ts +0 -14
  125. package/dist/src/nowiki/quote.js +0 -68
  126. package/dist/src/onlyinclude.d.ts +0 -16
  127. package/dist/src/onlyinclude.js +0 -57
  128. package/dist/src/paramTag/index.d.ts +0 -37
  129. package/dist/src/paramTag/index.js +0 -68
  130. package/dist/src/paramTag/inputbox.d.ts +0 -8
  131. package/dist/src/paramTag/inputbox.js +0 -22
  132. package/dist/src/parameter.d.ts +0 -67
  133. package/dist/src/parameter.js +0 -213
  134. package/dist/src/pre.d.ts +0 -28
  135. package/dist/src/pre.js +0 -54
  136. package/dist/src/syntax.d.ts +0 -14
  137. package/dist/src/syntax.js +0 -35
  138. package/dist/src/table/base.d.ts +0 -27
  139. package/dist/src/table/base.js +0 -81
  140. package/dist/src/table/index.d.ts +0 -230
  141. package/dist/src/table/index.js +0 -390
  142. package/dist/src/table/td.d.ts +0 -88
  143. package/dist/src/table/td.js +0 -284
  144. package/dist/src/table/tr.d.ts +0 -32
  145. package/dist/src/table/tr.js +0 -57
  146. package/dist/src/table/trBase.d.ts +0 -53
  147. package/dist/src/table/trBase.js +0 -154
  148. package/dist/src/tagPair/ext.d.ts +0 -29
  149. package/dist/src/tagPair/ext.js +0 -153
  150. package/dist/src/tagPair/include.d.ts +0 -37
  151. package/dist/src/tagPair/include.js +0 -71
  152. package/dist/src/tagPair/index.d.ts +0 -27
  153. package/dist/src/tagPair/index.js +0 -79
  154. package/dist/src/transclude.d.ts +0 -167
  155. package/dist/src/transclude.js +0 -715
  156. package/dist/util/constants.js +0 -113
  157. package/dist/util/debug.js +0 -90
  158. package/dist/util/diff.js +0 -82
  159. package/dist/util/lint.js +0 -30
  160. package/dist/util/string.js +0 -53
  161. package/errors/README +0 -1
  162. 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 index_1 = require("../index");
10
- const index_2 = require("./index");
11
- const atom_1 = require("./atom");
12
- /* NOT FOR BROWSER */
13
- const stages = { 'ext-attr': 0, 'html-attr': 2, 'table-attr': 3 };
14
- /* NOT FOR BROWSER END */
15
- const commonHtmlAttrs = new Set([
16
- 'id',
17
- 'class',
18
- 'style',
19
- 'lang',
20
- 'dir',
21
- 'title',
22
- 'tabindex',
23
- 'aria-describedby',
24
- 'aria-flowto',
25
- 'aria-hidden',
26
- 'aria-label',
27
- 'aria-labelledby',
28
- 'aria-owns',
29
- 'role',
30
- 'about',
31
- 'property',
32
- 'resource',
33
- 'datatype',
34
- 'typeof',
35
- 'itemid',
36
- 'itemprop',
37
- 'itemref',
38
- 'itemscope',
39
- 'itemtype',
40
- ]), 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 = {
41
- div: blockAttrs,
42
- h1: blockAttrs,
43
- h2: blockAttrs,
44
- h3: blockAttrs,
45
- h4: blockAttrs,
46
- h5: blockAttrs,
47
- h6: blockAttrs,
48
- blockquote: citeAttrs,
49
- q: citeAttrs,
50
- p: blockAttrs,
51
- br: brAttrs,
52
- pre: widthAttrs,
53
- ins: citeAndAttrs,
54
- del: citeAndAttrs,
55
- ul: typeAttrs,
56
- ol: new Set(['type', 'start', 'reversed']),
57
- li: new Set(['type', 'value']),
58
- table: new Set([...obsoleteTableAttrs, 'border']),
59
- caption: blockAttrs,
60
- tr: trAttrs,
61
- td: tdAttrs,
62
- th: tdAttrs,
63
- img: new Set(['alt', 'src', 'width', 'height', 'srcset']),
64
- font: new Set(['size', 'color', 'face']),
65
- hr: widthAttrs,
66
- rt: new Set(['rbspan']),
67
- data: new Set(['value']),
68
- time: new Set(['datetime']),
69
- meta: new Set(['itemprop', 'content']),
70
- link: new Set(['itemprop', 'href', 'title']),
71
- gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails', 'type']),
72
- poem: new Set(['compact', 'align']),
73
- categorytree: new Set([
74
- 'align',
75
- 'hideroot',
76
- 'onlyroot',
77
- 'depth',
78
- 'mode',
79
- 'hideprefix',
80
- 'namespaces',
81
- 'showcount',
82
- 'notranslations',
83
- ]),
84
- combooption: new Set(['name', 'for', 'inline', 'align']),
85
- }, empty = new Set(), extAttrs = {
86
- nowiki: empty,
87
- indicator: new Set(['name']),
88
- langconvert: new Set(['from', 'to']),
89
- ref: new Set(['group', 'name', 'extends', 'follow', 'dir']),
90
- references: new Set(['group', 'responsive']),
91
- charinsert: new Set(['label']),
92
- choose: new Set(['uncached', 'before', 'after']),
93
- option: new Set(['weight']),
94
- imagemap: empty,
95
- inputbox: empty,
96
- templatestyles: new Set(['src', 'wrapper']),
97
- dynamicpagelist: empty,
98
- poll: new Set(['id', 'show-results-before-voting']),
99
- sm2: typeAttrs,
100
- flashmp3: typeAttrs,
101
- score: new Set([
102
- 'line_width_inches',
103
- 'lang',
104
- 'override_midi',
105
- 'raw',
106
- 'note-language',
107
- 'override_audio',
108
- 'override_ogg',
109
- 'sound',
110
- 'vorbis',
111
- ]),
112
- seo: new Set([
113
- 'title',
114
- 'title_mode',
115
- 'title_separator',
116
- 'keywords',
117
- 'description',
118
- 'robots',
119
- 'google_bot',
120
- 'image',
121
- 'image_width',
122
- 'image_height',
123
- 'image_alt',
124
- 'type',
125
- 'site_name',
126
- 'locale',
127
- 'section',
128
- 'author',
129
- 'published_time',
130
- 'twitter_site',
131
- ]),
132
- tab: new Set([
133
- 'nested',
134
- 'name',
135
- 'index',
136
- 'class',
137
- 'block',
138
- 'inline',
139
- 'openname',
140
- 'closename',
141
- 'collapsed',
142
- 'dropdown',
143
- 'style',
144
- 'bgcolor',
145
- 'container',
146
- 'id',
147
- 'title',
148
- ]),
149
- tabs: new Set(['plain', 'class', 'container', 'id', 'title', 'style']),
150
- combobox: new Set(['placeholder', 'value', 'id', 'class', 'text', 'dropdown', 'style']),
151
- }, insecureStyle = new RegExp('expression'
152
- + '|'
153
- + '(?:filter|accelerator|-o-link(?:-source)?|-o-replace)\\s*:'
154
- + '|'
155
- + '(?:url|image(?:-set)?)\\s*\\('
156
- + '|'
157
- + 'attr\\s*\\([^)]+[\\s,]url', 'u'), obsoleteAttrs = {
158
- table: obsoleteTableAttrs,
159
- td: new Set([...obsoleteTdAttrs, 'scope']),
160
- th: obsoleteTdAttrs,
161
- br: brAttrs,
162
- caption: blockAttrs,
163
- div: blockAttrs,
164
- hr: widthAttrs,
165
- h1: blockAttrs,
166
- h2: blockAttrs,
167
- h3: blockAttrs,
168
- h4: blockAttrs,
169
- h5: blockAttrs,
170
- h6: blockAttrs,
171
- li: typeAttrs,
172
- p: blockAttrs,
173
- pre: widthAttrs,
174
- tr: trAttrs,
175
- ul: typeAttrs,
176
- };
177
- /**
178
- * 扩展和HTML标签属性
179
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
180
- */
181
- class AttributeToken extends (0, fixed_1.fixedToken)(index_2.Token) {
182
- tag;
183
- #equal;
184
- #quotes;
185
- /** 引号是否匹配 */
186
- get balanced() {
187
- return !this.#equal || this.#quotes[0] === this.#quotes[1];
188
- }
189
- /* NOT FOR BROWSER */
190
- set balanced(value) {
191
- if (value) {
192
- this.close();
193
- }
194
- }
195
- /** getValue()的getter */
196
- get value() {
197
- return this.getValue();
198
- }
199
- set value(value) {
200
- this.setValue(value);
201
- }
202
- /* NOT FOR BROWSER END */
203
- /**
204
- * @param type 标签类型
205
- * @param tag 标签名
206
- * @param key 属性名
207
- * @param equal 等号
208
- * @param value 属性值
209
- * @param quotes 引号
210
- */
211
- constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
212
- const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
213
- [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
214
- });
215
- let valueToken;
216
- if (key === 'title' || tag === 'img' && key === 'alt') {
217
- valueToken = new index_2.Token(value, config, accum, {
218
- [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
219
- });
220
- valueToken.type = 'attr-value';
221
- valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
222
- }
223
- else if (tag === 'gallery' && key === 'caption') {
224
- const newConfig = {
225
- ...config,
226
- excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
227
- };
228
- valueToken = new index_2.Token(value, newConfig, accum, {
229
- AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
230
- });
231
- valueToken.type = 'attr-value';
232
- valueToken.setAttribute('stage', 5);
233
- }
234
- else if (tag === 'choose' && (key === 'before' || key === 'after')) {
235
- const newConfig = {
236
- ...config,
237
- excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
238
- };
239
- valueToken = new index_2.Token(value, newConfig, accum, {
240
- ArgToken: ':',
241
- TranscludeToken: ':',
242
- LinkToken: ':',
243
- FileToken: ':',
244
- CategoryToken: ':',
245
- QuoteToken: ':',
246
- ExtLinkToken: ':',
247
- MagicLinkToken: ':',
248
- ConverterToken: ':',
249
- });
250
- valueToken.type = 'attr-value';
251
- valueToken.setAttribute('stage', 1);
252
- }
253
- else {
254
- valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
255
- [`Stage-${stages[type]}`]: ':',
256
- });
257
- }
258
- super(undefined, config, accum);
259
- this.type = type;
260
- this.append(keyToken, valueToken);
261
- this.#equal = equal;
262
- this.#quotes = [...quotes];
263
- this.tag = tag;
264
- /* NOT FOR BROWSER */
265
- this.seal('tag', true);
266
- /* NOT FOR BROWSER END */
267
- this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
268
- }
269
- /** @private */
270
- afterBuild() {
271
- if (this.#equal.includes('\0')) {
272
- this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
273
- }
274
- if (this.parentNode) {
275
- this.setAttribute('tag', this.parentNode.name);
276
- }
277
- this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
278
- }
279
- /** @private */
280
- toString() {
281
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
282
- return this.#equal ? `${super.toString(`${this.#equal}${quoteStart}`)}${quoteEnd}` : String(this.firstChild);
283
- }
284
- /** @override */
285
- text() {
286
- return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
287
- }
288
- /** @private */
289
- getGaps() {
290
- return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
291
- }
292
- /** @override */
293
- lint(start = this.getAbsoluteIndex()) {
294
- const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
295
- let rect;
296
- if (!balanced) {
297
- const root = this.getRootNode();
298
- rect = { start, ...root.posFromIndex(start) };
299
- const e = (0, lint_1.generateForChild)(lastChild, rect, index_1.default.msg('unclosed $1', 'quotes'), 'warning');
300
- errors.push({
301
- ...e,
302
- startIndex: e.startIndex - 1,
303
- startCol: e.startCol - 1,
304
- });
305
- }
306
- if (extAttrs[tag] && !extAttrs[tag].has(name)
307
- || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
308
- && !htmlAttrs[tag]?.has(name)
309
- && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
310
- && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
311
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
312
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal attribute name'));
313
- }
314
- else if (obsoleteAttrs[tag]?.has(name)) {
315
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
316
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete attribute', 'warning'));
317
- }
318
- else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
319
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
320
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure style'));
321
- }
322
- else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
323
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
324
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'nonzero tabindex'));
325
- }
326
- return errors;
327
- }
328
- /** 获取属性值 */
329
- getValue() {
330
- if (this.#equal) {
331
- const value = this.lastChild.text();
332
- if (this.#quotes[1]) {
333
- return value;
334
- }
335
- return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
336
- }
337
- return this.type === 'ext-attr' || '';
338
- }
339
- /** @override */
340
- print() {
341
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
342
- return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
343
- }
344
- /* NOT FOR BROWSER */
345
- /** @private */
346
- getAttribute(key) {
347
- if (key === 'equal') {
348
- return this.#equal;
349
- }
350
- return key === 'quotes' ? this.#quotes : super.getAttribute(key);
351
- }
352
- /** @override */
353
- cloneNode() {
354
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
355
- return debug_1.Shadow.run(() => {
356
- // @ts-expect-error abstract class
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 } = index_1.default.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 } = index_1.default.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 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 abstract class AttributesToken extends Token {
14
- #private;
15
- type: AttributesTypes;
16
- readonly name: string;
17
- readonly childNodes: readonly (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): 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 {};