wikiparser-node 1.13.2-b → 1.13.2

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