wikiparser-node 1.4.5 → 1.5.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 (162) hide show
  1. package/bundle/bundle.min.js +37 -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 +60 -0
  10. package/extensions/editor.css +63 -0
  11. package/extensions/ui.css +141 -0
  12. package/package.json +28 -14
  13. package/config/.schema.json +0 -172
  14. package/dist/addon/table.d.ts +0 -6
  15. package/dist/addon/table.js +0 -564
  16. package/dist/base.d.ts +0 -60
  17. package/dist/index.d.ts +0 -30
  18. package/dist/index.js +0 -211
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -655
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -428
  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 -314
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -164
  32. package/dist/mixin/attributesParent.d.ts +0 -50
  33. package/dist/mixin/attributesParent.js +0 -78
  34. package/dist/mixin/fixed.d.ts +0 -6
  35. package/dist/mixin/fixed.js +0 -30
  36. package/dist/mixin/flagsParent.d.ts +0 -72
  37. package/dist/mixin/flagsParent.js +0 -59
  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 -40
  41. package/dist/mixin/magicLinkParent.js +0 -42
  42. package/dist/mixin/singleLine.d.ts +0 -6
  43. package/dist/mixin/singleLine.js +0 -26
  44. package/dist/mixin/sol.d.ts +0 -6
  45. package/dist/mixin/sol.js +0 -43
  46. package/dist/mixin/syntax.d.ts +0 -9
  47. package/dist/mixin/syntax.js +0 -50
  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 -95
  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 -69
  65. package/dist/src/attribute.js +0 -475
  66. package/dist/src/attributes.d.ts +0 -109
  67. package/dist/src/attributes.js +0 -346
  68. package/dist/src/converter.d.ts +0 -33
  69. package/dist/src/converter.js +0 -134
  70. package/dist/src/converterFlags.d.ts +0 -87
  71. package/dist/src/converterFlags.js +0 -226
  72. package/dist/src/converterRule.d.ts +0 -77
  73. package/dist/src/converterRule.js +0 -209
  74. package/dist/src/extLink.d.ts +0 -43
  75. package/dist/src/extLink.js +0 -186
  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 -190
  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 -65
  83. package/dist/src/html.js +0 -340
  84. package/dist/src/imageParameter.d.ts +0 -65
  85. package/dist/src/imageParameter.js +0 -246
  86. package/dist/src/imagemap.d.ts +0 -56
  87. package/dist/src/imagemap.js +0 -150
  88. package/dist/src/imagemapLink.d.ts +0 -31
  89. package/dist/src/imagemapLink.js +0 -93
  90. package/dist/src/index.d.ts +0 -143
  91. package/dist/src/index.js +0 -803
  92. package/dist/src/link/base.d.ts +0 -52
  93. package/dist/src/link/base.js +0 -209
  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 -265
  98. package/dist/src/link/galleryImage.d.ts +0 -32
  99. package/dist/src/link/galleryImage.js +0 -157
  100. package/dist/src/link/index.d.ts +0 -56
  101. package/dist/src/link/index.js +0 -133
  102. package/dist/src/magicLink.d.ts +0 -59
  103. package/dist/src/magicLink.js +0 -199
  104. package/dist/src/nested.d.ts +0 -43
  105. package/dist/src/nested.js +0 -92
  106. package/dist/src/nowiki/base.d.ts +0 -31
  107. package/dist/src/nowiki/base.js +0 -93
  108. package/dist/src/nowiki/comment.d.ts +0 -25
  109. package/dist/src/nowiki/comment.js +0 -70
  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 -101
  114. package/dist/src/nowiki/hr.d.ts +0 -5
  115. package/dist/src/nowiki/hr.js +0 -63
  116. package/dist/src/nowiki/index.d.ts +0 -16
  117. package/dist/src/nowiki/index.js +0 -21
  118. package/dist/src/nowiki/list.d.ts +0 -16
  119. package/dist/src/nowiki/list.js +0 -97
  120. package/dist/src/nowiki/listBase.d.ts +0 -5
  121. package/dist/src/nowiki/listBase.js +0 -61
  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 -117
  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 -69
  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 -70
  133. package/dist/src/parameter.js +0 -262
  134. package/dist/src/pre.d.ts +0 -28
  135. package/dist/src/pre.js +0 -55
  136. package/dist/src/syntax.d.ts +0 -20
  137. package/dist/src/syntax.js +0 -86
  138. package/dist/src/table/base.d.ts +0 -30
  139. package/dist/src/table/base.js +0 -132
  140. package/dist/src/table/index.d.ts +0 -233
  141. package/dist/src/table/index.js +0 -396
  142. package/dist/src/table/td.d.ts +0 -92
  143. package/dist/src/table/td.js +0 -337
  144. package/dist/src/table/tr.d.ts +0 -32
  145. package/dist/src/table/tr.js +0 -58
  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 -32
  149. package/dist/src/tagPair/ext.js +0 -203
  150. package/dist/src/tagPair/include.d.ts +0 -35
  151. package/dist/src/tagPair/include.js +0 -65
  152. package/dist/src/tagPair/index.d.ts +0 -27
  153. package/dist/src/tagPair/index.js +0 -128
  154. package/dist/src/transclude.d.ts +0 -167
  155. package/dist/src/transclude.js +0 -710
  156. package/dist/util/constants.js +0 -113
  157. package/dist/util/debug.js +0 -88
  158. package/dist/util/diff.js +0 -82
  159. package/dist/util/lint.js +0 -31
  160. package/dist/util/string.js +0 -53
  161. package/errors/README +0 -1
  162. package/printed/README +0 -1
@@ -1,475 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.AttributeToken = void 0;
38
- const lint_1 = require("../util/lint");
39
- const string_1 = require("../util/string");
40
- const debug_1 = require("../util/debug");
41
- const constants_1 = require("../util/constants");
42
- const fixed_1 = require("../mixin/fixed");
43
- const index_1 = require("../index");
44
- const index_2 = require("./index");
45
- const atom_1 = require("./atom");
46
- /* NOT FOR BROWSER */
47
- const stages = { 'ext-attr': 0, 'html-attr': 2, 'table-attr': 3 };
48
- /* NOT FOR BROWSER END */
49
- const commonHtmlAttrs = new Set([
50
- 'id',
51
- 'class',
52
- 'style',
53
- 'lang',
54
- 'dir',
55
- 'title',
56
- 'tabindex',
57
- 'aria-describedby',
58
- 'aria-flowto',
59
- 'aria-hidden',
60
- 'aria-label',
61
- 'aria-labelledby',
62
- 'aria-owns',
63
- 'role',
64
- 'about',
65
- 'property',
66
- 'resource',
67
- 'datatype',
68
- 'typeof',
69
- 'itemid',
70
- 'itemprop',
71
- 'itemref',
72
- 'itemscope',
73
- 'itemtype',
74
- ]), 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 = {
75
- div: blockAttrs,
76
- h1: blockAttrs,
77
- h2: blockAttrs,
78
- h3: blockAttrs,
79
- h4: blockAttrs,
80
- h5: blockAttrs,
81
- h6: blockAttrs,
82
- blockquote: citeAttrs,
83
- q: citeAttrs,
84
- p: blockAttrs,
85
- br: brAttrs,
86
- pre: widthAttrs,
87
- ins: citeAndAttrs,
88
- del: citeAndAttrs,
89
- ul: typeAttrs,
90
- ol: new Set(['type', 'start', 'reversed']),
91
- li: new Set(['type', 'value']),
92
- table: new Set([...obsoleteTableAttrs, 'border']),
93
- caption: blockAttrs,
94
- tr: trAttrs,
95
- td: tdAttrs,
96
- th: tdAttrs,
97
- img: new Set(['alt', 'src', 'width', 'height', 'srcset']),
98
- font: new Set(['size', 'color', 'face']),
99
- hr: widthAttrs,
100
- rt: new Set(['rbspan']),
101
- data: new Set(['value']),
102
- time: new Set(['datetime']),
103
- meta: new Set(['itemprop', 'content']),
104
- link: new Set(['itemprop', 'href', 'title']),
105
- gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails', 'type']),
106
- poem: new Set(['compact', 'align']),
107
- categorytree: new Set([
108
- 'align',
109
- 'hideroot',
110
- 'onlyroot',
111
- 'depth',
112
- 'mode',
113
- 'hideprefix',
114
- 'namespaces',
115
- 'showcount',
116
- 'notranslations',
117
- ]),
118
- combooption: new Set(['name', 'for', 'inline', 'align']),
119
- }, empty = new Set(), extAttrs = {
120
- nowiki: empty,
121
- indicator: new Set(['name']),
122
- langconvert: new Set(['from', 'to']),
123
- ref: new Set(['group', 'name', 'extends', 'follow', 'dir']),
124
- references: new Set(['group', 'responsive']),
125
- charinsert: new Set(['label']),
126
- choose: new Set(['uncached', 'before', 'after']),
127
- option: new Set(['weight']),
128
- imagemap: empty,
129
- inputbox: empty,
130
- templatestyles: new Set(['src', 'wrapper']),
131
- dynamicpagelist: empty,
132
- poll: new Set(['id', 'show-results-before-voting']),
133
- sm2: typeAttrs,
134
- flashmp3: typeAttrs,
135
- score: new Set([
136
- 'line_width_inches',
137
- 'lang',
138
- 'override_midi',
139
- 'raw',
140
- 'note-language',
141
- 'override_audio',
142
- 'override_ogg',
143
- 'sound',
144
- 'vorbis',
145
- ]),
146
- seo: new Set([
147
- 'title',
148
- 'title_mode',
149
- 'title_separator',
150
- 'keywords',
151
- 'description',
152
- 'robots',
153
- 'google_bot',
154
- 'image',
155
- 'image_width',
156
- 'image_height',
157
- 'image_alt',
158
- 'type',
159
- 'site_name',
160
- 'locale',
161
- 'section',
162
- 'author',
163
- 'published_time',
164
- 'twitter_site',
165
- ]),
166
- tab: new Set([
167
- 'nested',
168
- 'name',
169
- 'index',
170
- 'class',
171
- 'block',
172
- 'inline',
173
- 'openname',
174
- 'closename',
175
- 'collapsed',
176
- 'dropdown',
177
- 'style',
178
- 'bgcolor',
179
- 'container',
180
- 'id',
181
- 'title',
182
- ]),
183
- tabs: new Set(['plain', 'class', 'container', 'id', 'title', 'style']),
184
- combobox: new Set(['placeholder', 'value', 'id', 'class', 'text', 'dropdown', 'style']),
185
- }, insecureStyle = new RegExp('expression'
186
- + '|'
187
- + '(?:filter|accelerator|-o-link(?:-source)?|-o-replace)\\s*:'
188
- + '|'
189
- + '(?:url|image(?:-set)?)\\s*\\('
190
- + '|'
191
- + 'attr\\s*\\([^)]+[\\s,]url', 'u'), obsoleteAttrs = {
192
- table: obsoleteTableAttrs,
193
- td: new Set([...obsoleteTdAttrs, 'scope']),
194
- th: obsoleteTdAttrs,
195
- br: brAttrs,
196
- caption: blockAttrs,
197
- div: blockAttrs,
198
- hr: widthAttrs,
199
- h1: blockAttrs,
200
- h2: blockAttrs,
201
- h3: blockAttrs,
202
- h4: blockAttrs,
203
- h5: blockAttrs,
204
- h6: blockAttrs,
205
- li: typeAttrs,
206
- p: blockAttrs,
207
- pre: widthAttrs,
208
- tr: trAttrs,
209
- ul: typeAttrs,
210
- };
211
- /**
212
- * 扩展和HTML标签属性
213
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
214
- */
215
- let AttributeToken = (() => {
216
- let _classDecorators = [fixed_1.fixedToken];
217
- let _classDescriptor;
218
- let _classExtraInitializers = [];
219
- let _classThis;
220
- let _classSuper = index_2.Token;
221
- var AttributeToken = class extends _classSuper {
222
- static { _classThis = this; }
223
- static {
224
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
225
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
226
- AttributeToken = _classThis = _classDescriptor.value;
227
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
228
- __runInitializers(_classThis, _classExtraInitializers);
229
- }
230
- #tag;
231
- #equal;
232
- #quotes;
233
- /* NOT FOR BROWSER END */
234
- /** @private */
235
- get tag() {
236
- return this.#tag;
237
- }
238
- /** 引号是否匹配 */
239
- get balanced() {
240
- return !this.#equal || this.#quotes[0] === this.#quotes[1];
241
- }
242
- /* NOT FOR BROWSER */
243
- set balanced(value) {
244
- if (value) {
245
- this.close();
246
- }
247
- }
248
- /** getValue()的getter */
249
- get value() {
250
- return this.getValue();
251
- }
252
- set value(value) {
253
- this.setValue(value);
254
- }
255
- /* NOT FOR BROWSER END */
256
- /**
257
- * @param type 标签类型
258
- * @param tag 标签名
259
- * @param key 属性名
260
- * @param equal 等号
261
- * @param value 属性值
262
- * @param quotes 引号
263
- */
264
- constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
265
- const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
266
- [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
267
- });
268
- let valueToken;
269
- if (key === 'title' || tag === 'img' && key === 'alt') {
270
- valueToken = new index_2.Token(value, config, accum, {
271
- [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
272
- });
273
- valueToken.type = 'attr-value';
274
- valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
275
- }
276
- else if (tag === 'gallery' && key === 'caption') {
277
- const newConfig = {
278
- ...config,
279
- excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
280
- };
281
- valueToken = new index_2.Token(value, newConfig, accum, {
282
- AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
283
- });
284
- valueToken.type = 'attr-value';
285
- valueToken.setAttribute('stage', 5);
286
- }
287
- else if (tag === 'choose' && (key === 'before' || key === 'after')) {
288
- const newConfig = {
289
- ...config,
290
- excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
291
- };
292
- valueToken = new index_2.Token(value, newConfig, accum, {
293
- ArgToken: ':',
294
- TranscludeToken: ':',
295
- LinkToken: ':',
296
- FileToken: ':',
297
- CategoryToken: ':',
298
- QuoteToken: ':',
299
- ExtLinkToken: ':',
300
- MagicLinkToken: ':',
301
- ConverterToken: ':',
302
- });
303
- valueToken.type = 'attr-value';
304
- valueToken.setAttribute('stage', 1);
305
- }
306
- else {
307
- valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
308
- [`Stage-${stages[type]}`]: ':',
309
- });
310
- }
311
- super(undefined, config, accum);
312
- this.type = type;
313
- this.append(keyToken, valueToken);
314
- this.#equal = equal;
315
- this.#quotes = [...quotes];
316
- this.#tag = tag;
317
- this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
318
- }
319
- /** @private */
320
- afterBuild() {
321
- if (this.#equal.includes('\0')) {
322
- this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
323
- }
324
- if (this.parentNode) {
325
- this.#tag = this.parentNode.name;
326
- }
327
- this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
328
- }
329
- /** @private */
330
- toString() {
331
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
332
- return this.#equal ? `${super.toString(`${this.#equal}${quoteStart}`)}${quoteEnd}` : String(this.firstChild);
333
- }
334
- /** @override */
335
- text() {
336
- return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
337
- }
338
- /** @private */
339
- getGaps() {
340
- return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
341
- }
342
- /** @override */
343
- lint(start = this.getAbsoluteIndex()) {
344
- const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
345
- let rect;
346
- if (!balanced) {
347
- const root = this.getRootNode();
348
- rect = { start, ...root.posFromIndex(start) };
349
- const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed-quote', index_1.default.msg('unclosed $1', 'quotes'), 'warning');
350
- errors.push({
351
- ...e,
352
- startIndex: e.startIndex - 1,
353
- startCol: e.startCol - 1,
354
- });
355
- }
356
- const attrs = extAttrs[tag];
357
- if (attrs && !attrs.has(name)
358
- || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
359
- && !htmlAttrs[tag]?.has(name)
360
- && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
361
- && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
362
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
363
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal-attr', 'illegal attribute name'));
364
- }
365
- else if (obsoleteAttrs[tag]?.has(name)) {
366
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
367
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete-attr', 'obsolete attribute', 'warning'));
368
- }
369
- else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
370
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
371
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure-style', 'insecure style'));
372
- }
373
- else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
374
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
375
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'illegal-attr', 'nonzero tabindex'));
376
- }
377
- return errors;
378
- }
379
- /** 获取属性值 */
380
- getValue() {
381
- if (this.#equal) {
382
- const value = this.lastChild.text();
383
- if (this.#quotes[1]) {
384
- return value;
385
- }
386
- return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
387
- }
388
- return this.type === 'ext-attr' || '';
389
- }
390
- /** @override */
391
- print() {
392
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
393
- return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
394
- }
395
- /* NOT FOR BROWSER */
396
- /** @private */
397
- getAttribute(key) {
398
- if (key === 'equal') {
399
- return this.#equal;
400
- }
401
- return key === 'quotes' ? this.#quotes : super.getAttribute(key);
402
- }
403
- /** @override */
404
- cloneNode() {
405
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
406
- return debug_1.Shadow.run(() => {
407
- // @ts-expect-error abstract class
408
- const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
409
- token.firstChild.safeReplaceWith(key);
410
- token.lastChild.safeReplaceWith(value);
411
- token.setAttribute('name', this.name);
412
- return token;
413
- });
414
- }
415
- /** 转义等号 */
416
- escape() {
417
- this.#equal = '{{=}}';
418
- }
419
- /** 闭合引号 */
420
- close() {
421
- const [opening] = this.#quotes;
422
- if (opening) {
423
- this.#quotes[1] = opening;
424
- }
425
- }
426
- /**
427
- * 设置属性值
428
- * @param value 参数值
429
- * @throws `RangeError` 扩展标签属性不能包含 ">"
430
- * @throws `RangeError` 同时包含单引号和双引号
431
- */
432
- setValue(value) {
433
- if (value === false) {
434
- this.remove();
435
- return;
436
- }
437
- else if (value === true) {
438
- this.#equal = '';
439
- return;
440
- }
441
- else if (this.type === 'ext-attr' && value.includes('>')) {
442
- throw new RangeError('扩展标签属性不能包含 ">"!');
443
- }
444
- else if (value.includes('"') && value.includes(`'`)) {
445
- throw new RangeError('属性值不能同时包含单引号和双引号!');
446
- }
447
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
448
- this.lastChild.replaceChildren(...childNodes);
449
- if (value.includes('"')) {
450
- this.#quotes = [`'`, `'`];
451
- }
452
- else if (value.includes(`'`) || !this.#quotes[0]) {
453
- this.#quotes = ['"', '"'];
454
- }
455
- else {
456
- this.close();
457
- }
458
- }
459
- /**
460
- * 修改属性名
461
- * @param key 新属性名
462
- * @throws `Error` title和alt属性不能更名
463
- */
464
- rename(key) {
465
- if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
466
- throw new Error(`${this.name} 属性不能更名!`);
467
- }
468
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
469
- this.firstChild.replaceChildren(...childNodes);
470
- }
471
- };
472
- return AttributeToken = _classThis;
473
- })();
474
- exports.AttributeToken = AttributeToken;
475
- 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 firstChild(): AtomToken | AttributeToken | undefined;
19
- abstract get lastChild(): AtomToken | AttributeToken | undefined;
20
- abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
21
- abstract get children(): (AtomToken | AttributeToken)[];
22
- abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
23
- abstract get lastElementChild(): AtomToken | AttributeToken | 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 {};