wikiparser-node 1.11.1 → 1.12.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 (175) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +28 -28
  3. package/config/enwiki.json +14 -827
  4. package/config/llwiki.json +20 -54
  5. package/config/minimum.json +1 -1
  6. package/config/moegirl.json +20 -63
  7. package/config/zhwiki.json +27 -492
  8. package/extensions/dist/base.js +162 -0
  9. package/extensions/dist/codejar.js +52 -0
  10. package/extensions/dist/editor.js +159 -0
  11. package/extensions/dist/highlight.js +30 -0
  12. package/extensions/dist/lint.js +72 -0
  13. package/extensions/editor.css +59 -0
  14. package/extensions/ui.css +159 -0
  15. package/package.json +29 -21
  16. package/config/.schema.json +0 -186
  17. package/dist/addon/table.js +0 -486
  18. package/dist/addon/token.js +0 -304
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -39
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -235
  24. package/dist/internal.d.ts +0 -46
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -375
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -477
  29. package/dist/lib/range.d.ts +0 -105
  30. package/dist/lib/range.js +0 -406
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/rect.d.ts +0 -18
  34. package/dist/lib/rect.js +0 -34
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -400
  37. package/dist/lib/title.d.ts +0 -42
  38. package/dist/lib/title.js +0 -208
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -79
  41. package/dist/mixin/fixed.d.ts +0 -5
  42. package/dist/mixin/fixed.js +0 -32
  43. package/dist/mixin/flagsParent.d.ts +0 -43
  44. package/dist/mixin/flagsParent.js +0 -64
  45. package/dist/mixin/hidden.d.ts +0 -7
  46. package/dist/mixin/hidden.js +0 -37
  47. package/dist/mixin/magicLinkParent.d.ts +0 -19
  48. package/dist/mixin/magicLinkParent.js +0 -43
  49. package/dist/mixin/singleLine.d.ts +0 -5
  50. package/dist/mixin/singleLine.js +0 -25
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -45
  53. package/dist/mixin/syntax.d.ts +0 -8
  54. package/dist/mixin/syntax.js +0 -46
  55. package/dist/parser/braces.js +0 -150
  56. package/dist/parser/commentAndExt.js +0 -79
  57. package/dist/parser/converter.js +0 -39
  58. package/dist/parser/externalLinks.js +0 -37
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  60. package/dist/parser/html.js +0 -38
  61. package/dist/parser/links.js +0 -101
  62. package/dist/parser/list.js +0 -114
  63. package/dist/parser/magicLinks.js +0 -52
  64. package/dist/parser/quotes.js +0 -67
  65. package/dist/parser/redirect.js +0 -26
  66. package/dist/parser/selector.js +0 -394
  67. package/dist/parser/table.js +0 -123
  68. package/dist/src/arg.d.ts +0 -51
  69. package/dist/src/arg.js +0 -214
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -52
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -480
  74. package/dist/src/attributes.d.ts +0 -101
  75. package/dist/src/attributes.js +0 -381
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -148
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -239
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -216
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -218
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -143
  86. package/dist/src/heading.d.ts +0 -40
  87. package/dist/src/heading.js +0 -192
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -80
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -343
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -260
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -146
  96. package/dist/src/imagemapLink.d.ts +0 -31
  97. package/dist/src/imagemapLink.js +0 -97
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -834
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -256
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -34
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -333
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -132
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -98
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -69
  112. package/dist/src/magicLink.d.ts +0 -58
  113. package/dist/src/magicLink.js +0 -256
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -106
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -89
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -121
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -72
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -70
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -28
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -65
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -99
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -75
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -140
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -58
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -78
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -22
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -264
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -60
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -126
  148. package/dist/src/syntax.d.ts +0 -17
  149. package/dist/src/syntax.js +0 -87
  150. package/dist/src/table/base.d.ts +0 -28
  151. package/dist/src/table/base.js +0 -81
  152. package/dist/src/table/index.d.ts +0 -230
  153. package/dist/src/table/index.js +0 -506
  154. package/dist/src/table/td.d.ts +0 -72
  155. package/dist/src/table/td.js +0 -370
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -59
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -164
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -220
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -130
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -128
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -587
  168. package/dist/util/constants.js +0 -25
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -143
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -87
  174. package/errors/README +0 -3
  175. package/printed/README +0 -3
@@ -1,480 +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
- 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 = /expression|(?:accelerator|-o-link(?:-source)?|-o-replace)\s*:|(?:url|image(?:-set)?)\s*\(|attr\s*\([^)]+[\s,]url/u, obsoleteAttrs = {
187
- table: obsoleteTableAttrs,
188
- td: new Set([...obsoleteTdAttrs, 'scope']),
189
- th: obsoleteTdAttrs,
190
- br: brAttrs,
191
- caption: blockAttrs,
192
- div: blockAttrs,
193
- hr: widthAttrs,
194
- h1: blockAttrs,
195
- h2: blockAttrs,
196
- h3: blockAttrs,
197
- h4: blockAttrs,
198
- h5: blockAttrs,
199
- h6: blockAttrs,
200
- li: typeAttrs,
201
- p: blockAttrs,
202
- pre: widthAttrs,
203
- tr: trAttrs,
204
- ul: typeAttrs,
205
- };
206
- /**
207
- * 扩展和HTML标签属性
208
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
209
- */
210
- let AttributeToken = (() => {
211
- let _classDecorators = [fixed_1.fixedToken];
212
- let _classDescriptor;
213
- let _classExtraInitializers = [];
214
- let _classThis;
215
- let _classSuper = index_2.Token;
216
- var AttributeToken = class extends _classSuper {
217
- static { _classThis = this; }
218
- static {
219
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
220
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
221
- AttributeToken = _classThis = _classDescriptor.value;
222
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
223
- __runInitializers(_classThis, _classExtraInitializers);
224
- }
225
- #type;
226
- #tag;
227
- #equal;
228
- #quotes;
229
- /* NOT FOR BROWSER END */
230
- get type() {
231
- return this.#type;
232
- }
233
- /** 标签名 */
234
- get tag() {
235
- return this.#tag;
236
- }
237
- /** 引号是否匹配 */
238
- get balanced() {
239
- return !this.#equal || this.#quotes[0] === this.#quotes[1];
240
- }
241
- /* NOT FOR BROWSER */
242
- set balanced(value) {
243
- if (value) {
244
- this.close();
245
- }
246
- }
247
- /** getValue()的getter */
248
- get value() {
249
- return this.getValue();
250
- }
251
- set value(value) {
252
- this.setValue(value);
253
- }
254
- /* NOT FOR BROWSER END */
255
- /**
256
- * @param type 标签类型
257
- * @param tag 标签名
258
- * @param key 属性名
259
- * @param equal 等号
260
- * @param value 属性值
261
- * @param quotes 引号
262
- */
263
- constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
264
- const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, type === 'ext-attr' ? { AstText: ':' } : { 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '' });
265
- let valueToken;
266
- if (key === 'title' || tag === 'img' && key === 'alt') {
267
- valueToken = new index_2.Token(value, config, accum, {
268
- [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
269
- });
270
- valueToken.type = 'attr-value';
271
- valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
272
- }
273
- else if (tag === 'gallery' && key === 'caption'
274
- || tag === 'choose' && (key === 'before' || key === 'after')) {
275
- const newConfig = {
276
- ...config,
277
- excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
278
- };
279
- valueToken = new index_2.Token(value, newConfig, accum, {
280
- AstText: ':',
281
- ArgToken: ':',
282
- TranscludeToken: ':',
283
- LinkToken: ':',
284
- FileToken: ':',
285
- CategoryToken: ':',
286
- QuoteToken: ':',
287
- ExtLinkToken: ':',
288
- MagicLinkToken: ':',
289
- ConverterToken: ':',
290
- });
291
- valueToken.type = 'attr-value';
292
- valueToken.setAttribute('stage', 1);
293
- }
294
- else {
295
- valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
296
- [`Stage-${stages[type]}`]: ':',
297
- });
298
- }
299
- super(undefined, config, accum);
300
- this.#type = type;
301
- this.append(keyToken, valueToken);
302
- this.#equal = equal;
303
- this.#quotes = [...quotes];
304
- this.#tag = tag;
305
- this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
306
- }
307
- /** @private */
308
- afterBuild() {
309
- if (this.#equal.includes('\0')) {
310
- this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
311
- }
312
- if (this.parentNode) {
313
- this.#tag = this.parentNode.name;
314
- }
315
- this.setAttribute('name', this.firstChild.toString(true).trim().toLowerCase());
316
- super.afterBuild();
317
- }
318
- /** @private */
319
- toString(skip) {
320
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
321
- return this.#equal ? super.toString(skip, this.#equal + quoteStart) + quoteEnd : this.firstChild.toString(skip);
322
- }
323
- /** @private */
324
- text() {
325
- return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
326
- }
327
- /** @private */
328
- getGaps() {
329
- return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
330
- }
331
- /** @private */
332
- lint(start = this.getAbsoluteIndex(), re) {
333
- const errors = super.lint(start, re), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue(), rect = new rect_1.BoundingRect(this, start);
334
- if (!balanced) {
335
- const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed-quote', index_1.default.msg('unclosed $1', 'quotes'), 'warning');
336
- e.startIndex--;
337
- e.startCol--;
338
- const fix = { range: [e.endIndex, e.endIndex], text: this.#quotes[0] };
339
- if (lastChild.childNodes.some(({ type: t, data }) => t === 'text' && /\s/u.test(data))) {
340
- e.suggestions = [
341
- {
342
- desc: 'close',
343
- ...fix,
344
- },
345
- ];
346
- }
347
- else {
348
- e.fix = fix;
349
- }
350
- errors.push(e);
351
- }
352
- const attrs = extAttrs[tag];
353
- if (attrs && !attrs.has(name)
354
- || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
355
- && !htmlAttrs[tag]?.has(name)
356
- && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
357
- && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
358
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal-attr', 'illegal attribute name'));
359
- }
360
- else if (obsoleteAttrs[tag]?.has(name)) {
361
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete-attr', 'obsolete attribute', 'warning'));
362
- }
363
- else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
364
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure-style', 'insecure style'));
365
- }
366
- else if (name === 'tabindex' && typeof value === 'string' && value !== '0') {
367
- const e = (0, lint_1.generateForChild)(lastChild, rect, 'illegal-attr', 'nonzero tabindex');
368
- e.suggestions = [
369
- {
370
- desc: 'remove',
371
- range: [start, e.endIndex],
372
- text: '',
373
- },
374
- {
375
- desc: '0 tabindex',
376
- range: [e.startIndex, e.endIndex],
377
- text: '0',
378
- },
379
- ];
380
- errors.push(e);
381
- }
382
- return errors;
383
- }
384
- /** 获取属性值 */
385
- getValue() {
386
- return this.#equal ? this.lastChild.text().trim() : this.type === 'ext-attr' || '';
387
- }
388
- /** @private */
389
- print() {
390
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
391
- return this.#equal ? super.print({ sep: (0, string_1.escape)(this.#equal) + quoteStart, post: quoteEnd }) : super.print();
392
- }
393
- /* NOT FOR BROWSER */
394
- cloneNode() {
395
- const [key, value] = this.cloneChildNodes(), k = key.toString(), config = this.getAttribute('config');
396
- return debug_1.Shadow.run(() => {
397
- // @ts-expect-error abstract class
398
- const token = new AttributeToken(this.type, this.tag, k, this.#equal, '', this.#quotes, config);
399
- token.firstChild.safeReplaceWith(key);
400
- token.lastChild.safeReplaceWith(value);
401
- return token;
402
- });
403
- }
404
- /** 转义等号 */
405
- escape() {
406
- this.#equal = '{{=}}';
407
- }
408
- /** 闭合引号 */
409
- close() {
410
- const [opening] = this.#quotes;
411
- if (opening) {
412
- this.#quotes[1] = opening;
413
- }
414
- }
415
- /**
416
- * 设置属性值
417
- * @param value 参数值
418
- * @throws `RangeError` 扩展标签属性不能包含 ">"
419
- * @throws `RangeError` 同时包含单引号和双引号
420
- */
421
- setValue(value) {
422
- if (value === false) {
423
- this.remove();
424
- return;
425
- }
426
- else if (value === true) {
427
- this.#equal = '';
428
- return;
429
- }
430
- else if (this.type === 'ext-attr' && value.includes('>')) {
431
- throw new RangeError('Attributes of an extension tag cannot contain ">"!');
432
- }
433
- else if (value.includes('"') && value.includes(`'`)) {
434
- throw new RangeError('Attribute values cannot contain single and double quotes simultaneously!');
435
- }
436
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
437
- this.lastChild.replaceChildren(...childNodes);
438
- if (value.includes('"')) {
439
- this.#quotes = [`'`, `'`];
440
- }
441
- else if (value.includes(`'`) || !this.#quotes[0]) {
442
- this.#quotes = ['"', '"'];
443
- }
444
- else {
445
- this.close();
446
- }
447
- }
448
- /**
449
- * 修改属性名
450
- * @param key 新属性名
451
- * @throws `Error` title和alt属性不能更名
452
- */
453
- rename(key) {
454
- if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
455
- throw new Error(`${this.name} attribute cannot be renamed!`);
456
- }
457
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
458
- this.firstChild.replaceChildren(...childNodes);
459
- }
460
- /** @private */
461
- toHtmlInternal() {
462
- const { type, name, tag, lastChild } = this;
463
- if (type === 'ext-attr' && !(tag in htmlAttrs)
464
- || !htmlAttrs[tag]?.has(name) && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
465
- return '';
466
- }
467
- let value = lastChild.toHtmlInternal().trim();
468
- if (name === 'style' && insecureStyle.test(value) || name === 'tabindex' && value !== '0') {
469
- return '';
470
- }
471
- else if (name === 'id') {
472
- value = value.replace(/\s+/gu, '_');
473
- }
474
- return `${name}="${(0, string_1.sanitizeAttr)(value)}"`;
475
- }
476
- };
477
- return AttributeToken = _classThis;
478
- })();
479
- exports.AttributeToken = AttributeToken;
480
- constants_1.classes['AttributeToken'] = __filename;
@@ -1,101 +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
- /** id属性 */
34
- get id(): string;
35
- set id(id: string);
36
- /** 是否含有无效属性 */
37
- get sanitized(): boolean;
38
- set sanitized(sanitized: boolean);
39
- /**
40
- * @param attr 标签属性
41
- * @param type 标签类型
42
- * @param name 标签名
43
- */
44
- constructor(attr: string | undefined, type: AttributesTypes, name: string, config?: Parser.Config, accum?: Token[]);
45
- /**
46
- * 所有指定属性名的AttributeToken
47
- * @param key 属性名
48
- */
49
- getAttrTokens(key?: string): AttributeToken[];
50
- /**
51
- * 指定属性名的最后一个AttributeToken
52
- * @param key 属性名
53
- */
54
- getAttrToken(key: string): AttributeToken | undefined;
55
- /**
56
- * 获取指定属性
57
- * @param key 属性键
58
- */
59
- getAttr(key: string): string | true | undefined;
60
- /** 清理无效属性 */
61
- sanitize(): void;
62
- cloneNode(): this;
63
- /**
64
- * @override
65
- * @param token 待插入的子节点
66
- * @param i 插入位置
67
- * @throws `RangeError` 标签不匹配
68
- */
69
- insertAt<T extends AttributeToken | AtomToken>(token: T, i?: number): T;
70
- /**
71
- * 设置指定属性
72
- * @param key 属性键
73
- * @param value 属性值
74
- * @param prop 属性对象
75
- * @throws `RangeError` 扩展标签属性不能包含">"
76
- */
77
- setAttr(key: string, value: string | boolean): void;
78
- setAttr(prop: Record<string, string | boolean>): void;
79
- /**
80
- * 标签是否具有某属性
81
- * @param key 属性键
82
- */
83
- hasAttr(key: string): boolean;
84
- /** 获取全部的属性名 */
85
- getAttrNames(): Set<string>;
86
- /** 获取全部属性 */
87
- getAttrs(): Record<string, string | true>;
88
- /**
89
- * 移除指定属性
90
- * @param key 属性键
91
- */
92
- removeAttr(key: string): void;
93
- /**
94
- * 开关指定属性
95
- * @param key 属性键
96
- * @param force 强制开启或关闭
97
- * @throws `RangeError` 不为Boolean类型的属性值
98
- */
99
- toggleAttr(key: string, force?: boolean): void;
100
- }
101
- export {};