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