wikiparser-node 1.9.3 → 1.10.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 (171) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/enwiki.json +3 -815
  3. package/config/llwiki.json +3 -36
  4. package/config/moegirl.json +3 -45
  5. package/config/zhwiki.json +3 -467
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +58 -0
  9. package/extensions/dist/lint.js +72 -0
  10. package/extensions/editor.css +64 -0
  11. package/extensions/ui.css +144 -0
  12. package/package.json +32 -22
  13. package/config/.schema.json +0 -181
  14. package/dist/addon/table.js +0 -486
  15. package/dist/addon/token.js +0 -240
  16. package/dist/addon/transclude.js +0 -185
  17. package/dist/base.d.ts +0 -79
  18. package/dist/base.js +0 -39
  19. package/dist/index.d.ts +0 -31
  20. package/dist/index.js +0 -231
  21. package/dist/internal.d.ts +0 -46
  22. package/dist/lib/element.d.ts +0 -125
  23. package/dist/lib/element.js +0 -374
  24. package/dist/lib/node.d.ts +0 -168
  25. package/dist/lib/node.js +0 -472
  26. package/dist/lib/range.d.ts +0 -105
  27. package/dist/lib/range.js +0 -406
  28. package/dist/lib/ranges.d.ts +0 -28
  29. package/dist/lib/ranges.js +0 -126
  30. package/dist/lib/rect.d.ts +0 -18
  31. package/dist/lib/rect.js +0 -34
  32. package/dist/lib/text.d.ts +0 -55
  33. package/dist/lib/text.js +0 -351
  34. package/dist/lib/title.d.ts +0 -40
  35. package/dist/lib/title.js +0 -197
  36. package/dist/mixin/attributesParent.d.ts +0 -49
  37. package/dist/mixin/attributesParent.js +0 -82
  38. package/dist/mixin/fixed.d.ts +0 -5
  39. package/dist/mixin/fixed.js +0 -32
  40. package/dist/mixin/flagsParent.d.ts +0 -41
  41. package/dist/mixin/flagsParent.js +0 -60
  42. package/dist/mixin/hidden.d.ts +0 -6
  43. package/dist/mixin/hidden.js +0 -34
  44. package/dist/mixin/magicLinkParent.d.ts +0 -19
  45. package/dist/mixin/magicLinkParent.js +0 -43
  46. package/dist/mixin/singleLine.d.ts +0 -5
  47. package/dist/mixin/singleLine.js +0 -27
  48. package/dist/mixin/sol.d.ts +0 -5
  49. package/dist/mixin/sol.js +0 -44
  50. package/dist/mixin/syntax.d.ts +0 -8
  51. package/dist/mixin/syntax.js +0 -48
  52. package/dist/parser/braces.js +0 -150
  53. package/dist/parser/commentAndExt.js +0 -79
  54. package/dist/parser/converter.js +0 -39
  55. package/dist/parser/externalLinks.js +0 -37
  56. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  57. package/dist/parser/html.js +0 -38
  58. package/dist/parser/links.js +0 -101
  59. package/dist/parser/list.js +0 -97
  60. package/dist/parser/magicLinks.js +0 -53
  61. package/dist/parser/quotes.js +0 -67
  62. package/dist/parser/redirect.js +0 -26
  63. package/dist/parser/selector.js +0 -393
  64. package/dist/parser/table.js +0 -123
  65. package/dist/src/arg.d.ts +0 -51
  66. package/dist/src/arg.js +0 -214
  67. package/dist/src/atom.d.ts +0 -14
  68. package/dist/src/atom.js +0 -52
  69. package/dist/src/attribute.d.ts +0 -64
  70. package/dist/src/attribute.js +0 -486
  71. package/dist/src/attributes.d.ts +0 -102
  72. package/dist/src/attributes.js +0 -355
  73. package/dist/src/converter.d.ts +0 -28
  74. package/dist/src/converter.js +0 -137
  75. package/dist/src/converterFlags.d.ts +0 -80
  76. package/dist/src/converterFlags.js +0 -242
  77. package/dist/src/converterRule.d.ts +0 -71
  78. package/dist/src/converterRule.js +0 -212
  79. package/dist/src/extLink.d.ts +0 -36
  80. package/dist/src/extLink.js +0 -194
  81. package/dist/src/gallery.d.ts +0 -47
  82. package/dist/src/gallery.js +0 -142
  83. package/dist/src/heading.d.ts +0 -40
  84. package/dist/src/heading.js +0 -186
  85. package/dist/src/hidden.d.ts +0 -9
  86. package/dist/src/hidden.js +0 -80
  87. package/dist/src/html.d.ts +0 -57
  88. package/dist/src/html.js +0 -335
  89. package/dist/src/imageParameter.d.ts +0 -58
  90. package/dist/src/imageParameter.js +0 -247
  91. package/dist/src/imagemap.d.ts +0 -47
  92. package/dist/src/imagemap.js +0 -146
  93. package/dist/src/imagemapLink.d.ts +0 -31
  94. package/dist/src/imagemapLink.js +0 -97
  95. package/dist/src/index.d.ts +0 -131
  96. package/dist/src/index.js +0 -746
  97. package/dist/src/link/base.d.ts +0 -45
  98. package/dist/src/link/base.js +0 -226
  99. package/dist/src/link/category.d.ts +0 -22
  100. package/dist/src/link/category.js +0 -34
  101. package/dist/src/link/file.d.ts +0 -96
  102. package/dist/src/link/file.js +0 -276
  103. package/dist/src/link/galleryImage.d.ts +0 -29
  104. package/dist/src/link/galleryImage.js +0 -132
  105. package/dist/src/link/index.d.ts +0 -51
  106. package/dist/src/link/index.js +0 -136
  107. package/dist/src/link/redirectTarget.d.ts +0 -36
  108. package/dist/src/link/redirectTarget.js +0 -98
  109. package/dist/src/magicLink.d.ts +0 -60
  110. package/dist/src/magicLink.js +0 -273
  111. package/dist/src/nested.d.ts +0 -40
  112. package/dist/src/nested.js +0 -106
  113. package/dist/src/nowiki/base.d.ts +0 -30
  114. package/dist/src/nowiki/base.js +0 -89
  115. package/dist/src/nowiki/comment.d.ts +0 -14
  116. package/dist/src/nowiki/comment.js +0 -124
  117. package/dist/src/nowiki/dd.d.ts +0 -8
  118. package/dist/src/nowiki/dd.js +0 -26
  119. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  120. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  121. package/dist/src/nowiki/hr.d.ts +0 -5
  122. package/dist/src/nowiki/hr.js +0 -65
  123. package/dist/src/nowiki/index.d.ts +0 -14
  124. package/dist/src/nowiki/index.js +0 -31
  125. package/dist/src/nowiki/list.d.ts +0 -16
  126. package/dist/src/nowiki/list.js +0 -111
  127. package/dist/src/nowiki/listBase.d.ts +0 -5
  128. package/dist/src/nowiki/listBase.js +0 -61
  129. package/dist/src/nowiki/noinclude.d.ts +0 -6
  130. package/dist/src/nowiki/noinclude.js +0 -71
  131. package/dist/src/nowiki/quote.d.ts +0 -14
  132. package/dist/src/nowiki/quote.js +0 -130
  133. package/dist/src/onlyinclude.d.ts +0 -13
  134. package/dist/src/onlyinclude.js +0 -58
  135. package/dist/src/paramTag/index.d.ts +0 -30
  136. package/dist/src/paramTag/index.js +0 -78
  137. package/dist/src/paramTag/inputbox.d.ts +0 -8
  138. package/dist/src/paramTag/inputbox.js +0 -22
  139. package/dist/src/parameter.d.ts +0 -60
  140. package/dist/src/parameter.js +0 -261
  141. package/dist/src/pre.d.ts +0 -28
  142. package/dist/src/pre.js +0 -60
  143. package/dist/src/redirect.d.ts +0 -30
  144. package/dist/src/redirect.js +0 -122
  145. package/dist/src/syntax.d.ts +0 -17
  146. package/dist/src/syntax.js +0 -87
  147. package/dist/src/table/base.d.ts +0 -28
  148. package/dist/src/table/base.js +0 -81
  149. package/dist/src/table/index.d.ts +0 -230
  150. package/dist/src/table/index.js +0 -495
  151. package/dist/src/table/td.d.ts +0 -72
  152. package/dist/src/table/td.js +0 -364
  153. package/dist/src/table/tr.d.ts +0 -30
  154. package/dist/src/table/tr.js +0 -59
  155. package/dist/src/table/trBase.d.ts +0 -49
  156. package/dist/src/table/trBase.js +0 -156
  157. package/dist/src/tagPair/ext.d.ts +0 -29
  158. package/dist/src/tagPair/ext.js +0 -204
  159. package/dist/src/tagPair/include.d.ts +0 -33
  160. package/dist/src/tagPair/include.js +0 -126
  161. package/dist/src/tagPair/index.d.ts +0 -23
  162. package/dist/src/tagPair/index.js +0 -128
  163. package/dist/src/transclude.d.ts +0 -159
  164. package/dist/src/transclude.js +0 -582
  165. package/dist/util/constants.js +0 -25
  166. package/dist/util/debug.js +0 -95
  167. package/dist/util/diff.js +0 -83
  168. package/dist/util/lint.js +0 -32
  169. package/dist/util/string.js +0 -60
  170. package/errors/README +0 -1
  171. package/printed/README +0 -1
@@ -1,486 +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 rect_1 = require("../lib/rect");
40
- const string_1 = require("../util/string");
41
- const debug_1 = require("../util/debug");
42
- const constants_1 = require("../util/constants");
43
- const fixed_1 = require("../mixin/fixed");
44
- const index_1 = require("../index");
45
- const index_2 = require("./index");
46
- const atom_1 = require("./atom");
47
- /* NOT FOR BROWSER */
48
- const stages = { 'ext-attr': 0, 'html-attr': 2, 'table-attr': 3 };
49
- /* NOT FOR BROWSER END */
50
- const commonHtmlAttrs = new Set([
51
- 'id',
52
- 'class',
53
- 'style',
54
- 'lang',
55
- 'dir',
56
- 'title',
57
- 'tabindex',
58
- 'aria-describedby',
59
- 'aria-flowto',
60
- 'aria-hidden',
61
- 'aria-label',
62
- 'aria-labelledby',
63
- 'aria-level',
64
- 'aria-owns',
65
- 'role',
66
- 'about',
67
- 'property',
68
- 'resource',
69
- 'datatype',
70
- 'typeof',
71
- 'itemid',
72
- 'itemprop',
73
- 'itemref',
74
- 'itemscope',
75
- 'itemtype',
76
- ]), 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 = {
77
- div: blockAttrs,
78
- h1: blockAttrs,
79
- h2: blockAttrs,
80
- h3: blockAttrs,
81
- h4: blockAttrs,
82
- h5: blockAttrs,
83
- h6: blockAttrs,
84
- blockquote: citeAttrs,
85
- q: citeAttrs,
86
- p: blockAttrs,
87
- br: brAttrs,
88
- pre: widthAttrs,
89
- ins: citeAndAttrs,
90
- del: citeAndAttrs,
91
- ul: typeAttrs,
92
- ol: new Set(['type', 'start', 'reversed']),
93
- li: new Set(['type', 'value']),
94
- table: new Set([...obsoleteTableAttrs, 'border']),
95
- caption: blockAttrs,
96
- tr: trAttrs,
97
- td: tdAttrs,
98
- th: tdAttrs,
99
- img: new Set(['alt', 'src', 'width', 'height', 'srcset']),
100
- font: new Set(['size', 'color', 'face']),
101
- hr: widthAttrs,
102
- rt: new Set(['rbspan']),
103
- data: new Set(['value']),
104
- time: new Set(['datetime']),
105
- meta: new Set(['itemprop', 'content']),
106
- link: new Set(['itemprop', 'href', 'title']),
107
- gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails', 'type']),
108
- poem: new Set(['compact', 'align']),
109
- categorytree: new Set([
110
- 'align',
111
- 'hideroot',
112
- 'onlyroot',
113
- 'depth',
114
- 'mode',
115
- 'hideprefix',
116
- 'namespaces',
117
- 'showcount',
118
- 'notranslations',
119
- ]),
120
- combooption: new Set(['name', 'for', 'inline', 'align']),
121
- }, empty = new Set(), extAttrs = {
122
- nowiki: empty,
123
- indicator: new Set(['name']),
124
- langconvert: new Set(['from', 'to']),
125
- ref: new Set(['group', 'name', 'extends', 'follow', 'dir']),
126
- references: new Set(['group', 'responsive']),
127
- charinsert: new Set(['label']),
128
- choose: new Set(['uncached', 'before', 'after']),
129
- option: new Set(['weight']),
130
- imagemap: empty,
131
- inputbox: empty,
132
- templatestyles: new Set(['src', 'wrapper']),
133
- dynamicpagelist: empty,
134
- poll: new Set(['id', 'show-results-before-voting']),
135
- sm2: typeAttrs,
136
- flashmp3: typeAttrs,
137
- score: new Set([
138
- 'line_width_inches',
139
- 'lang',
140
- 'override_midi',
141
- 'raw',
142
- 'note-language',
143
- 'override_audio',
144
- 'override_ogg',
145
- 'sound',
146
- 'vorbis',
147
- ]),
148
- seo: new Set([
149
- 'title',
150
- 'title_mode',
151
- 'title_separator',
152
- 'keywords',
153
- 'description',
154
- 'robots',
155
- 'google_bot',
156
- 'image',
157
- 'image_width',
158
- 'image_height',
159
- 'image_alt',
160
- 'type',
161
- 'site_name',
162
- 'locale',
163
- 'section',
164
- 'author',
165
- 'published_time',
166
- 'twitter_site',
167
- ]),
168
- tab: new Set([
169
- 'nested',
170
- 'name',
171
- 'index',
172
- 'class',
173
- 'block',
174
- 'inline',
175
- 'openname',
176
- 'closename',
177
- 'collapsed',
178
- 'dropdown',
179
- 'style',
180
- 'bgcolor',
181
- 'container',
182
- 'id',
183
- 'title',
184
- ]),
185
- tabs: new Set(['plain', 'class', 'container', 'id', 'title', 'style']),
186
- combobox: new Set(['placeholder', 'value', 'id', 'class', 'text', 'dropdown', 'style']),
187
- }, insecureStyle = /expression|(?:accelerator|-o-link(?:-source)?|-o-replace)\s*:|(?:url|image(?:-set)?)\s*\(|attr\s*\([^)]+[\s,]url/u, obsoleteAttrs = {
188
- table: obsoleteTableAttrs,
189
- td: new Set([...obsoleteTdAttrs, 'scope']),
190
- th: obsoleteTdAttrs,
191
- br: brAttrs,
192
- caption: blockAttrs,
193
- div: blockAttrs,
194
- hr: widthAttrs,
195
- h1: blockAttrs,
196
- h2: blockAttrs,
197
- h3: blockAttrs,
198
- h4: blockAttrs,
199
- h5: blockAttrs,
200
- h6: blockAttrs,
201
- li: typeAttrs,
202
- p: blockAttrs,
203
- pre: widthAttrs,
204
- tr: trAttrs,
205
- ul: typeAttrs,
206
- };
207
- /**
208
- * 扩展和HTML标签属性
209
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
210
- */
211
- let AttributeToken = (() => {
212
- let _classDecorators = [fixed_1.fixedToken];
213
- let _classDescriptor;
214
- let _classExtraInitializers = [];
215
- let _classThis;
216
- let _classSuper = index_2.Token;
217
- var AttributeToken = class extends _classSuper {
218
- static { _classThis = this; }
219
- static {
220
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
221
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
222
- AttributeToken = _classThis = _classDescriptor.value;
223
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
224
- __runInitializers(_classThis, _classExtraInitializers);
225
- }
226
- #type;
227
- #tag;
228
- #equal;
229
- #quotes;
230
- /* NOT FOR BROWSER END */
231
- get type() {
232
- return this.#type;
233
- }
234
- /** 标签名 */
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
- super.afterBuild();
329
- }
330
- /** @private */
331
- toString() {
332
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
333
- return this.#equal ? super.toString(this.#equal + quoteStart) + quoteEnd : this.firstChild.toString();
334
- }
335
- /** @private */
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
- /** @private */
344
- lint(start = this.getAbsoluteIndex(), re) {
345
- const errors = super.lint(start, re), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue(), rect = new rect_1.BoundingRect(this, start);
346
- if (!balanced) {
347
- const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed-quote', index_1.default.msg('unclosed $1', 'quotes'), 'warning');
348
- e.startIndex--;
349
- e.startCol--;
350
- const fix = {
351
- range: [e.endIndex, e.endIndex],
352
- text: this.#quotes[0],
353
- };
354
- if (lastChild.childNodes.some(({ type: t, data }) => t === 'text' && /\s/u.test(data))) {
355
- e.suggestions = [
356
- {
357
- desc: 'close',
358
- ...fix,
359
- },
360
- ];
361
- }
362
- else {
363
- e.fix = fix;
364
- }
365
- errors.push(e);
366
- }
367
- const attrs = extAttrs[tag];
368
- if (attrs && !attrs.has(name)
369
- || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
370
- && !htmlAttrs[tag]?.has(name)
371
- && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
372
- && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
373
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal-attr', 'illegal attribute name'));
374
- }
375
- else if (obsoleteAttrs[tag]?.has(name)) {
376
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete-attr', 'obsolete attribute', 'warning'));
377
- }
378
- else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
379
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure-style', 'insecure style'));
380
- }
381
- else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
382
- const e = (0, lint_1.generateForChild)(lastChild, rect, 'illegal-attr', 'nonzero tabindex');
383
- e.suggestions = [
384
- {
385
- desc: 'remove',
386
- range: [start, e.endIndex],
387
- text: '',
388
- },
389
- {
390
- desc: '0 tabindex',
391
- range: [e.startIndex, e.endIndex],
392
- text: '0',
393
- },
394
- ];
395
- errors.push(e);
396
- }
397
- return errors;
398
- }
399
- /** 获取属性值 */
400
- getValue() {
401
- if (this.#equal) {
402
- const value = this.lastChild.text();
403
- if (this.#quotes[1]) {
404
- return value;
405
- }
406
- return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
407
- }
408
- return this.type === 'ext-attr' || '';
409
- }
410
- /** @private */
411
- print() {
412
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
413
- return this.#equal ? super.print({ sep: (0, string_1.escape)(this.#equal) + quoteStart, post: quoteEnd }) : super.print();
414
- }
415
- /* NOT FOR BROWSER */
416
- cloneNode() {
417
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
418
- return debug_1.Shadow.run(() => {
419
- // @ts-expect-error abstract class
420
- const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
421
- token.firstChild.safeReplaceWith(key);
422
- token.lastChild.safeReplaceWith(value);
423
- return token;
424
- });
425
- }
426
- /** 转义等号 */
427
- escape() {
428
- this.#equal = '{{=}}';
429
- }
430
- /** 闭合引号 */
431
- close() {
432
- const [opening] = this.#quotes;
433
- if (opening) {
434
- this.#quotes[1] = opening;
435
- }
436
- }
437
- /**
438
- * 设置属性值
439
- * @param value 参数值
440
- * @throws `RangeError` 扩展标签属性不能包含 ">"
441
- * @throws `RangeError` 同时包含单引号和双引号
442
- */
443
- setValue(value) {
444
- if (value === false) {
445
- this.remove();
446
- return;
447
- }
448
- else if (value === true) {
449
- this.#equal = '';
450
- return;
451
- }
452
- else if (this.type === 'ext-attr' && value.includes('>')) {
453
- throw new RangeError('Attributes of an extension tag cannot contain ">"!');
454
- }
455
- else if (value.includes('"') && value.includes(`'`)) {
456
- throw new RangeError('Attribute values cannot contain single and double quotes simultaneously!');
457
- }
458
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
459
- this.lastChild.replaceChildren(...childNodes);
460
- if (value.includes('"')) {
461
- this.#quotes = [`'`, `'`];
462
- }
463
- else if (value.includes(`'`) || !this.#quotes[0]) {
464
- this.#quotes = ['"', '"'];
465
- }
466
- else {
467
- this.close();
468
- }
469
- }
470
- /**
471
- * 修改属性名
472
- * @param key 新属性名
473
- * @throws `Error` title和alt属性不能更名
474
- */
475
- rename(key) {
476
- if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
477
- throw new Error(`${this.name} attribute cannot be renamed!`);
478
- }
479
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
480
- this.firstChild.replaceChildren(...childNodes);
481
- }
482
- };
483
- return AttributeToken = _classThis;
484
- })();
485
- exports.AttributeToken = AttributeToken;
486
- constants_1.classes['AttributeToken'] = __filename;
@@ -1,102 +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
- readonly name: string;
16
- readonly childNodes: readonly (AtomToken | AttributeToken)[];
17
- abstract get firstChild(): AtomToken | AttributeToken | undefined;
18
- abstract get lastChild(): AtomToken | AttributeToken | undefined;
19
- abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
20
- abstract get children(): (AtomToken | AttributeToken)[];
21
- abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
22
- abstract get lastElementChild(): AtomToken | AttributeToken | undefined;
23
- abstract get parentElement(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
24
- get type(): AttributesTypes;
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
- /** 清理无效属性 */
62
- sanitize(): void;
63
- cloneNode(): this;
64
- /**
65
- * @override
66
- * @param token 待插入的子节点
67
- * @param i 插入位置
68
- * @throws `RangeError` 标签不匹配
69
- */
70
- insertAt<T extends AttributeToken | AtomToken>(token: T, i?: number): T;
71
- /**
72
- * 设置指定属性
73
- * @param key 属性键
74
- * @param value 属性值
75
- * @param prop 属性对象
76
- * @throws `RangeError` 扩展标签属性不能包含">"
77
- */
78
- setAttr(key: string, value: string | boolean): void;
79
- setAttr(prop: Record<string, string | boolean>): void;
80
- /**
81
- * 标签是否具有某属性
82
- * @param key 属性键
83
- */
84
- hasAttr(key: string): boolean;
85
- /** 获取全部的属性名 */
86
- getAttrNames(): Set<string>;
87
- /** 获取全部属性 */
88
- getAttrs(): Record<string, string | true>;
89
- /**
90
- * 移除指定属性
91
- * @param key 属性键
92
- */
93
- removeAttr(key: string): void;
94
- /**
95
- * 开关指定属性
96
- * @param key 属性键
97
- * @param force 强制开启或关闭
98
- * @throws `RangeError` 不为Boolean类型的属性值
99
- */
100
- toggleAttr(key: string, force?: boolean): void;
101
- }
102
- export {};