wikiparser-node 1.10.0 → 1.11.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 (173) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +56 -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/i18n/zh-hans.json +1 -1
  13. package/i18n/zh-hant.json +1 -1
  14. package/package.json +43 -33
  15. package/config/.schema.json +0 -186
  16. package/dist/addon/table.js +0 -486
  17. package/dist/addon/token.js +0 -324
  18. package/dist/addon/transclude.js +0 -185
  19. package/dist/base.d.ts +0 -81
  20. package/dist/base.js +0 -39
  21. package/dist/index.d.ts +0 -33
  22. package/dist/index.js +0 -231
  23. package/dist/internal.d.ts +0 -46
  24. package/dist/lib/element.d.ts +0 -125
  25. package/dist/lib/element.js +0 -374
  26. package/dist/lib/node.d.ts +0 -173
  27. package/dist/lib/node.js +0 -478
  28. package/dist/lib/range.d.ts +0 -105
  29. package/dist/lib/range.js +0 -406
  30. package/dist/lib/ranges.d.ts +0 -28
  31. package/dist/lib/ranges.js +0 -126
  32. package/dist/lib/rect.d.ts +0 -18
  33. package/dist/lib/rect.js +0 -34
  34. package/dist/lib/text.d.ts +0 -58
  35. package/dist/lib/text.js +0 -361
  36. package/dist/lib/title.d.ts +0 -42
  37. package/dist/lib/title.js +0 -205
  38. package/dist/mixin/attributesParent.d.ts +0 -49
  39. package/dist/mixin/attributesParent.js +0 -79
  40. package/dist/mixin/fixed.d.ts +0 -5
  41. package/dist/mixin/fixed.js +0 -32
  42. package/dist/mixin/flagsParent.d.ts +0 -41
  43. package/dist/mixin/flagsParent.js +0 -60
  44. package/dist/mixin/hidden.d.ts +0 -7
  45. package/dist/mixin/hidden.js +0 -37
  46. package/dist/mixin/magicLinkParent.d.ts +0 -19
  47. package/dist/mixin/magicLinkParent.js +0 -43
  48. package/dist/mixin/singleLine.d.ts +0 -5
  49. package/dist/mixin/singleLine.js +0 -25
  50. package/dist/mixin/sol.d.ts +0 -6
  51. package/dist/mixin/sol.js +0 -44
  52. package/dist/mixin/syntax.d.ts +0 -8
  53. package/dist/mixin/syntax.js +0 -46
  54. package/dist/parser/braces.js +0 -150
  55. package/dist/parser/commentAndExt.js +0 -79
  56. package/dist/parser/converter.js +0 -39
  57. package/dist/parser/externalLinks.js +0 -37
  58. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  59. package/dist/parser/html.js +0 -38
  60. package/dist/parser/links.js +0 -101
  61. package/dist/parser/list.js +0 -99
  62. package/dist/parser/magicLinks.js +0 -53
  63. package/dist/parser/quotes.js +0 -67
  64. package/dist/parser/redirect.js +0 -26
  65. package/dist/parser/selector.js +0 -394
  66. package/dist/parser/table.js +0 -123
  67. package/dist/src/arg.d.ts +0 -51
  68. package/dist/src/arg.js +0 -214
  69. package/dist/src/atom.d.ts +0 -14
  70. package/dist/src/atom.js +0 -52
  71. package/dist/src/attribute.d.ts +0 -64
  72. package/dist/src/attribute.js +0 -483
  73. package/dist/src/attributes.d.ts +0 -101
  74. package/dist/src/attributes.js +0 -382
  75. package/dist/src/converter.d.ts +0 -28
  76. package/dist/src/converter.js +0 -147
  77. package/dist/src/converterFlags.d.ts +0 -80
  78. package/dist/src/converterFlags.js +0 -242
  79. package/dist/src/converterRule.d.ts +0 -71
  80. package/dist/src/converterRule.js +0 -216
  81. package/dist/src/extLink.d.ts +0 -36
  82. package/dist/src/extLink.js +0 -198
  83. package/dist/src/gallery.d.ts +0 -47
  84. package/dist/src/gallery.js +0 -142
  85. package/dist/src/heading.d.ts +0 -40
  86. package/dist/src/heading.js +0 -191
  87. package/dist/src/hidden.d.ts +0 -9
  88. package/dist/src/hidden.js +0 -80
  89. package/dist/src/html.d.ts +0 -57
  90. package/dist/src/html.js +0 -343
  91. package/dist/src/imageParameter.d.ts +0 -58
  92. package/dist/src/imageParameter.js +0 -247
  93. package/dist/src/imagemap.d.ts +0 -47
  94. package/dist/src/imagemap.js +0 -146
  95. package/dist/src/imagemapLink.d.ts +0 -31
  96. package/dist/src/imagemapLink.js +0 -97
  97. package/dist/src/index.d.ts +0 -141
  98. package/dist/src/index.js +0 -795
  99. package/dist/src/link/base.d.ts +0 -54
  100. package/dist/src/link/base.js +0 -263
  101. package/dist/src/link/category.d.ts +0 -22
  102. package/dist/src/link/category.js +0 -34
  103. package/dist/src/link/file.d.ts +0 -96
  104. package/dist/src/link/file.js +0 -276
  105. package/dist/src/link/galleryImage.d.ts +0 -29
  106. package/dist/src/link/galleryImage.js +0 -132
  107. package/dist/src/link/index.d.ts +0 -39
  108. package/dist/src/link/index.js +0 -99
  109. package/dist/src/link/redirectTarget.d.ts +0 -27
  110. package/dist/src/link/redirectTarget.js +0 -72
  111. package/dist/src/magicLink.d.ts +0 -61
  112. package/dist/src/magicLink.js +0 -261
  113. package/dist/src/nested.d.ts +0 -40
  114. package/dist/src/nested.js +0 -106
  115. package/dist/src/nowiki/base.d.ts +0 -30
  116. package/dist/src/nowiki/base.js +0 -89
  117. package/dist/src/nowiki/comment.d.ts +0 -14
  118. package/dist/src/nowiki/comment.js +0 -124
  119. package/dist/src/nowiki/dd.d.ts +0 -8
  120. package/dist/src/nowiki/dd.js +0 -72
  121. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  122. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  123. package/dist/src/nowiki/hr.d.ts +0 -5
  124. package/dist/src/nowiki/hr.js +0 -70
  125. package/dist/src/nowiki/index.d.ts +0 -14
  126. package/dist/src/nowiki/index.js +0 -31
  127. package/dist/src/nowiki/list.d.ts +0 -5
  128. package/dist/src/nowiki/list.js +0 -65
  129. package/dist/src/nowiki/listBase.d.ts +0 -17
  130. package/dist/src/nowiki/listBase.js +0 -75
  131. package/dist/src/nowiki/noinclude.d.ts +0 -6
  132. package/dist/src/nowiki/noinclude.js +0 -75
  133. package/dist/src/nowiki/quote.d.ts +0 -14
  134. package/dist/src/nowiki/quote.js +0 -135
  135. package/dist/src/onlyinclude.d.ts +0 -13
  136. package/dist/src/onlyinclude.js +0 -58
  137. package/dist/src/paramTag/index.d.ts +0 -30
  138. package/dist/src/paramTag/index.js +0 -78
  139. package/dist/src/paramTag/inputbox.d.ts +0 -8
  140. package/dist/src/paramTag/inputbox.js +0 -22
  141. package/dist/src/parameter.d.ts +0 -60
  142. package/dist/src/parameter.js +0 -268
  143. package/dist/src/pre.d.ts +0 -28
  144. package/dist/src/pre.js +0 -60
  145. package/dist/src/redirect.d.ts +0 -30
  146. package/dist/src/redirect.js +0 -126
  147. package/dist/src/syntax.d.ts +0 -17
  148. package/dist/src/syntax.js +0 -87
  149. package/dist/src/table/base.d.ts +0 -28
  150. package/dist/src/table/base.js +0 -81
  151. package/dist/src/table/index.d.ts +0 -230
  152. package/dist/src/table/index.js +0 -505
  153. package/dist/src/table/td.d.ts +0 -72
  154. package/dist/src/table/td.js +0 -370
  155. package/dist/src/table/tr.d.ts +0 -30
  156. package/dist/src/table/tr.js +0 -59
  157. package/dist/src/table/trBase.d.ts +0 -49
  158. package/dist/src/table/trBase.js +0 -164
  159. package/dist/src/tagPair/ext.d.ts +0 -29
  160. package/dist/src/tagPair/ext.js +0 -220
  161. package/dist/src/tagPair/include.d.ts +0 -33
  162. package/dist/src/tagPair/include.js +0 -130
  163. package/dist/src/tagPair/index.d.ts +0 -23
  164. package/dist/src/tagPair/index.js +0 -128
  165. package/dist/src/transclude.d.ts +0 -159
  166. package/dist/src/transclude.js +0 -587
  167. package/dist/util/constants.js +0 -25
  168. package/dist/util/debug.js +0 -95
  169. package/dist/util/diff.js +0 -83
  170. package/dist/util/lint.js +0 -32
  171. package/dist/util/string.js +0 -84
  172. package/errors/README +0 -3
  173. package/printed/README +0 -3
@@ -1,483 +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 = {
339
- range: [e.endIndex, e.endIndex],
340
- text: this.#quotes[0],
341
- };
342
- if (lastChild.childNodes.some(({ type: t, data }) => t === 'text' && /\s/u.test(data))) {
343
- e.suggestions = [
344
- {
345
- desc: 'close',
346
- ...fix,
347
- },
348
- ];
349
- }
350
- else {
351
- e.fix = fix;
352
- }
353
- errors.push(e);
354
- }
355
- const attrs = extAttrs[tag];
356
- if (attrs && !attrs.has(name)
357
- || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
358
- && !htmlAttrs[tag]?.has(name)
359
- && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/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(), 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, '', 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
- toHtml() {
465
- const { type, name, tag, lastChild } = this;
466
- if (type === 'ext-attr' && !(tag in htmlAttrs)
467
- || !htmlAttrs[tag]?.has(name) && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
468
- return '';
469
- }
470
- let value = lastChild.toHtml().trim();
471
- if (name === 'style' && insecureStyle.test(value) || name === 'tabindex' && value !== '0') {
472
- return '';
473
- }
474
- else if (name === 'id') {
475
- value = value.replace(/\s+/gu, '_');
476
- }
477
- return `${name}="${value.replace(/["\n]/gu, p => p === '"' ? '&quot;' : '&#10;')}"`;
478
- }
479
- };
480
- return AttributeToken = _classThis;
481
- })();
482
- exports.AttributeToken = AttributeToken;
483
- 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 {};