wikiparser-node 1.13.0 → 1.13.1-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 (176) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +32 -41
  3. package/config/enwiki.json +17 -839
  4. package/config/llwiki.json +21 -56
  5. package/config/moegirl.json +21 -65
  6. package/config/zhwiki.json +32 -498
  7. package/extensions/dist/base.js +163 -0
  8. package/extensions/dist/codejar.js +53 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +30 -0
  11. package/extensions/dist/lint.js +72 -0
  12. package/extensions/editor.css +59 -0
  13. package/extensions/ui.css +162 -0
  14. package/i18n/zh-hans.json +1 -0
  15. package/i18n/zh-hant.json +1 -0
  16. package/package.json +29 -22
  17. package/config/.schema.json +0 -203
  18. package/dist/addon/table.js +0 -494
  19. package/dist/addon/token.js +0 -392
  20. package/dist/addon/transclude.js +0 -184
  21. package/dist/base.d.ts +0 -109
  22. package/dist/base.js +0 -67
  23. package/dist/index.d.ts +0 -33
  24. package/dist/index.js +0 -279
  25. package/dist/internal.d.ts +0 -47
  26. package/dist/lib/element.d.ts +0 -125
  27. package/dist/lib/element.js +0 -364
  28. package/dist/lib/node.d.ts +0 -173
  29. package/dist/lib/node.js +0 -478
  30. package/dist/lib/range.d.ts +0 -105
  31. package/dist/lib/range.js +0 -406
  32. package/dist/lib/ranges.d.ts +0 -28
  33. package/dist/lib/ranges.js +0 -126
  34. package/dist/lib/rect.d.ts +0 -18
  35. package/dist/lib/rect.js +0 -36
  36. package/dist/lib/text.d.ts +0 -58
  37. package/dist/lib/text.js +0 -414
  38. package/dist/lib/title.d.ts +0 -49
  39. package/dist/lib/title.js +0 -251
  40. package/dist/mixin/attributesParent.d.ts +0 -49
  41. package/dist/mixin/attributesParent.js +0 -80
  42. package/dist/mixin/fixed.d.ts +0 -5
  43. package/dist/mixin/fixed.js +0 -32
  44. package/dist/mixin/flagsParent.d.ts +0 -43
  45. package/dist/mixin/flagsParent.js +0 -64
  46. package/dist/mixin/hidden.d.ts +0 -7
  47. package/dist/mixin/hidden.js +0 -39
  48. package/dist/mixin/magicLinkParent.d.ts +0 -19
  49. package/dist/mixin/magicLinkParent.js +0 -43
  50. package/dist/mixin/singleLine.d.ts +0 -5
  51. package/dist/mixin/singleLine.js +0 -25
  52. package/dist/mixin/sol.d.ts +0 -6
  53. package/dist/mixin/sol.js +0 -45
  54. package/dist/mixin/syntax.d.ts +0 -8
  55. package/dist/mixin/syntax.js +0 -46
  56. package/dist/parser/braces.js +0 -152
  57. package/dist/parser/commentAndExt.js +0 -84
  58. package/dist/parser/converter.js +0 -41
  59. package/dist/parser/externalLinks.js +0 -39
  60. package/dist/parser/hrAndDoubleUnderscore.js +0 -44
  61. package/dist/parser/html.js +0 -40
  62. package/dist/parser/links.js +0 -103
  63. package/dist/parser/list.js +0 -116
  64. package/dist/parser/magicLinks.js +0 -55
  65. package/dist/parser/quotes.js +0 -69
  66. package/dist/parser/redirect.js +0 -28
  67. package/dist/parser/selector.js +0 -443
  68. package/dist/parser/table.js +0 -125
  69. package/dist/src/arg.d.ts +0 -49
  70. package/dist/src/arg.js +0 -220
  71. package/dist/src/atom.d.ts +0 -14
  72. package/dist/src/atom.js +0 -54
  73. package/dist/src/attribute.d.ts +0 -64
  74. package/dist/src/attribute.js +0 -482
  75. package/dist/src/attributes.d.ts +0 -103
  76. package/dist/src/attributes.js +0 -383
  77. package/dist/src/converter.d.ts +0 -28
  78. package/dist/src/converter.js +0 -153
  79. package/dist/src/converterFlags.d.ts +0 -80
  80. package/dist/src/converterFlags.js +0 -241
  81. package/dist/src/converterRule.d.ts +0 -71
  82. package/dist/src/converterRule.js +0 -218
  83. package/dist/src/extLink.d.ts +0 -36
  84. package/dist/src/extLink.js +0 -223
  85. package/dist/src/gallery.d.ts +0 -51
  86. package/dist/src/gallery.js +0 -166
  87. package/dist/src/heading.d.ts +0 -44
  88. package/dist/src/heading.js +0 -222
  89. package/dist/src/hidden.d.ts +0 -9
  90. package/dist/src/hidden.js +0 -82
  91. package/dist/src/html.d.ts +0 -61
  92. package/dist/src/html.js +0 -344
  93. package/dist/src/imageParameter.d.ts +0 -60
  94. package/dist/src/imageParameter.js +0 -262
  95. package/dist/src/imagemap.d.ts +0 -47
  96. package/dist/src/imagemap.js +0 -148
  97. package/dist/src/imagemapLink.d.ts +0 -35
  98. package/dist/src/imagemapLink.js +0 -99
  99. package/dist/src/index.d.ts +0 -136
  100. package/dist/src/index.js +0 -790
  101. package/dist/src/link/base.d.ts +0 -52
  102. package/dist/src/link/base.js +0 -258
  103. package/dist/src/link/category.d.ts +0 -22
  104. package/dist/src/link/category.js +0 -36
  105. package/dist/src/link/file.d.ts +0 -102
  106. package/dist/src/link/file.js +0 -345
  107. package/dist/src/link/galleryImage.d.ts +0 -29
  108. package/dist/src/link/galleryImage.js +0 -133
  109. package/dist/src/link/index.d.ts +0 -39
  110. package/dist/src/link/index.js +0 -100
  111. package/dist/src/link/redirectTarget.d.ts +0 -27
  112. package/dist/src/link/redirectTarget.js +0 -71
  113. package/dist/src/magicLink.d.ts +0 -57
  114. package/dist/src/magicLink.js +0 -261
  115. package/dist/src/nested.d.ts +0 -40
  116. package/dist/src/nested.js +0 -108
  117. package/dist/src/nowiki/base.d.ts +0 -28
  118. package/dist/src/nowiki/base.js +0 -90
  119. package/dist/src/nowiki/comment.d.ts +0 -14
  120. package/dist/src/nowiki/comment.js +0 -123
  121. package/dist/src/nowiki/dd.d.ts +0 -8
  122. package/dist/src/nowiki/dd.js +0 -74
  123. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  124. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  125. package/dist/src/nowiki/hr.d.ts +0 -5
  126. package/dist/src/nowiki/hr.js +0 -72
  127. package/dist/src/nowiki/index.d.ts +0 -14
  128. package/dist/src/nowiki/index.js +0 -30
  129. package/dist/src/nowiki/list.d.ts +0 -5
  130. package/dist/src/nowiki/list.js +0 -67
  131. package/dist/src/nowiki/listBase.d.ts +0 -23
  132. package/dist/src/nowiki/listBase.js +0 -100
  133. package/dist/src/nowiki/noinclude.d.ts +0 -6
  134. package/dist/src/nowiki/noinclude.js +0 -77
  135. package/dist/src/nowiki/quote.d.ts +0 -14
  136. package/dist/src/nowiki/quote.js +0 -149
  137. package/dist/src/onlyinclude.d.ts +0 -13
  138. package/dist/src/onlyinclude.js +0 -60
  139. package/dist/src/paramTag/index.d.ts +0 -28
  140. package/dist/src/paramTag/index.js +0 -80
  141. package/dist/src/paramTag/inputbox.d.ts +0 -8
  142. package/dist/src/paramTag/inputbox.js +0 -24
  143. package/dist/src/parameter.d.ts +0 -60
  144. package/dist/src/parameter.js +0 -267
  145. package/dist/src/pre.d.ts +0 -28
  146. package/dist/src/pre.js +0 -62
  147. package/dist/src/redirect.d.ts +0 -30
  148. package/dist/src/redirect.js +0 -128
  149. package/dist/src/syntax.d.ts +0 -15
  150. package/dist/src/syntax.js +0 -87
  151. package/dist/src/table/base.d.ts +0 -28
  152. package/dist/src/table/base.js +0 -81
  153. package/dist/src/table/index.d.ts +0 -230
  154. package/dist/src/table/index.js +0 -506
  155. package/dist/src/table/td.d.ts +0 -72
  156. package/dist/src/table/td.js +0 -375
  157. package/dist/src/table/tr.d.ts +0 -30
  158. package/dist/src/table/tr.js +0 -61
  159. package/dist/src/table/trBase.d.ts +0 -49
  160. package/dist/src/table/trBase.js +0 -165
  161. package/dist/src/tagPair/ext.d.ts +0 -29
  162. package/dist/src/tagPair/ext.js +0 -229
  163. package/dist/src/tagPair/include.d.ts +0 -33
  164. package/dist/src/tagPair/include.js +0 -132
  165. package/dist/src/tagPair/index.d.ts +0 -23
  166. package/dist/src/tagPair/index.js +0 -130
  167. package/dist/src/transclude.d.ts +0 -159
  168. package/dist/src/transclude.js +0 -598
  169. package/dist/util/constants.js +0 -26
  170. package/dist/util/debug.js +0 -95
  171. package/dist/util/diff.js +0 -83
  172. package/dist/util/html.js +0 -146
  173. package/dist/util/lint.js +0 -32
  174. package/dist/util/string.js +0 -107
  175. package/errors/README +0 -3
  176. package/printed/README +0 -3
@@ -1,482 +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: 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;
@@ -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 {};