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