wikiparser-node 1.4.2 → 1.4.3
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.
- package/dist/addon/table.js +5 -1
- package/dist/base.d.ts +6 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +3 -3
- package/dist/lib/element.d.ts +3 -2
- package/dist/lib/element.js +20 -13
- package/dist/lib/node.js +13 -10
- package/dist/lib/text.js +3 -3
- package/dist/lib/title.js +4 -12
- package/dist/mixin/attributesParent.d.ts +32 -2
- package/dist/mixin/attributesParent.js +14 -25
- package/dist/mixin/fixed.d.ts +2 -1
- package/dist/mixin/fixed.js +3 -1
- package/dist/mixin/flagsParent.d.ts +28 -17
- package/dist/mixin/flagsParent.js +12 -25
- package/dist/mixin/magicLinkParent.d.ts +14 -8
- package/dist/mixin/magicLinkParent.js +7 -8
- package/dist/mixin/singleLine.d.ts +2 -1
- package/dist/mixin/singleLine.js +3 -2
- package/dist/mixin/sol.d.ts +2 -4
- package/dist/mixin/sol.js +8 -6
- package/dist/mixin/syntax.d.ts +5 -2
- package/dist/mixin/syntax.js +14 -18
- package/dist/parser/links.js +1 -3
- package/dist/src/arg.d.ts +4 -4
- package/dist/src/arg.js +4 -4
- package/dist/src/attribute.d.ts +9 -7
- package/dist/src/attribute.js +271 -218
- package/dist/src/attributes.d.ts +3 -3
- package/dist/src/attributes.js +0 -1
- package/dist/src/converter.d.ts +7 -2
- package/dist/src/converter.js +113 -64
- package/dist/src/converterFlags.d.ts +5 -5
- package/dist/src/converterFlags.js +0 -1
- package/dist/src/converterRule.d.ts +5 -5
- package/dist/src/converterRule.js +0 -1
- package/dist/src/extLink.d.ts +7 -2
- package/dist/src/extLink.js +159 -110
- package/dist/src/gallery.d.ts +5 -5
- package/dist/src/gallery.js +0 -1
- package/dist/src/heading.d.ts +8 -8
- package/dist/src/heading.js +172 -125
- package/dist/src/html.d.ts +8 -5
- package/dist/src/html.js +263 -214
- package/dist/src/imageParameter.d.ts +2 -2
- package/dist/src/imageParameter.js +1 -0
- package/dist/src/imagemap.d.ts +5 -5
- package/dist/src/imagemap.js +4 -10
- package/dist/src/imagemapLink.d.ts +7 -4
- package/dist/src/imagemapLink.js +75 -26
- package/dist/src/index.js +3 -4
- package/dist/src/link/base.d.ts +2 -2
- package/dist/src/link/base.js +1 -4
- package/dist/src/link/file.d.ts +1 -1
- package/dist/src/link/file.js +0 -1
- package/dist/src/link/galleryImage.d.ts +2 -1
- package/dist/src/link/galleryImage.js +136 -88
- package/dist/src/link/index.js +0 -1
- package/dist/src/magicLink.d.ts +11 -3
- package/dist/src/magicLink.js +170 -120
- package/dist/src/nested.d.ts +5 -5
- package/dist/src/nested.js +1 -0
- package/dist/src/nowiki/base.d.ts +6 -2
- package/dist/src/nowiki/base.js +79 -28
- package/dist/src/nowiki/comment.d.ts +0 -2
- package/dist/src/nowiki/comment.js +0 -9
- package/dist/src/nowiki/doubleUnderscore.js +88 -38
- package/dist/src/nowiki/hr.d.ts +1 -4
- package/dist/src/nowiki/hr.js +53 -4
- package/dist/src/nowiki/index.d.ts +2 -2
- package/dist/src/nowiki/index.js +1 -0
- package/dist/src/nowiki/list.d.ts +1 -4
- package/dist/src/nowiki/list.js +88 -39
- package/dist/src/nowiki/listBase.d.ts +1 -1
- package/dist/src/nowiki/listBase.js +52 -2
- package/dist/src/nowiki/quote.d.ts +3 -3
- package/dist/src/nowiki/quote.js +102 -54
- package/dist/src/paramTag/index.d.ts +5 -5
- package/dist/src/paramTag/index.js +2 -1
- package/dist/src/parameter.d.ts +11 -8
- package/dist/src/parameter.js +225 -176
- package/dist/src/pre.d.ts +5 -5
- package/dist/src/pre.js +1 -0
- package/dist/src/syntax.d.ts +6 -0
- package/dist/src/syntax.js +74 -23
- package/dist/src/table/base.d.ts +6 -3
- package/dist/src/table/base.js +100 -49
- package/dist/src/table/index.d.ts +6 -3
- package/dist/src/table/index.js +5 -9
- package/dist/src/table/td.d.ts +9 -5
- package/dist/src/table/td.js +270 -217
- package/dist/src/table/tr.d.ts +4 -4
- package/dist/src/table/tr.js +1 -0
- package/dist/src/tagPair/ext.d.ts +6 -3
- package/dist/src/tagPair/ext.js +168 -118
- package/dist/src/tagPair/include.d.ts +2 -4
- package/dist/src/tagPair/include.js +0 -8
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +115 -66
- package/dist/src/transclude.d.ts +3 -3
- package/dist/src/transclude.js +4 -9
- package/dist/util/debug.js +0 -2
- package/package.json +3 -3
package/dist/src/attribute.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
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
|
+
};
|
|
2
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
37
|
exports.AttributeToken = void 0;
|
|
4
38
|
const lint_1 = require("../util/lint");
|
|
@@ -178,245 +212,264 @@ const commonHtmlAttrs = new Set([
|
|
|
178
212
|
* 扩展和HTML标签属性
|
|
179
213
|
* @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
|
|
180
214
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
215
|
+
let AttributeToken = (() => {
|
|
216
|
+
let _classDecorators = [fixed_1.fixedToken];
|
|
217
|
+
let _classDescriptor;
|
|
218
|
+
let _classExtraInitializers = [];
|
|
219
|
+
let _classThis;
|
|
220
|
+
let _classSuper = index_2.Token;
|
|
221
|
+
var AttributeToken = class extends _classSuper {
|
|
222
|
+
static { _classThis = this; }
|
|
223
|
+
static {
|
|
224
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
225
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
226
|
+
AttributeToken = _classThis = _classDescriptor.value;
|
|
227
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
228
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
193
229
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
/* NOT FOR BROWSER END */
|
|
203
|
-
/**
|
|
204
|
-
* @param type 标签类型
|
|
205
|
-
* @param tag 标签名
|
|
206
|
-
* @param key 属性名
|
|
207
|
-
* @param equal 等号
|
|
208
|
-
* @param value 属性值
|
|
209
|
-
* @param quotes 引号
|
|
210
|
-
*/
|
|
211
|
-
constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
|
|
212
|
-
const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
|
|
213
|
-
[type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
|
|
214
|
-
});
|
|
215
|
-
let valueToken;
|
|
216
|
-
if (key === 'title' || tag === 'img' && key === 'alt') {
|
|
217
|
-
valueToken = new index_2.Token(value, config, accum, {
|
|
218
|
-
[`Stage-${stages[type]}`]: ':', ConverterToken: ':',
|
|
219
|
-
});
|
|
220
|
-
valueToken.type = 'attr-value';
|
|
221
|
-
valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
|
|
222
|
-
}
|
|
223
|
-
else if (tag === 'gallery' && key === 'caption') {
|
|
224
|
-
const newConfig = {
|
|
225
|
-
...config,
|
|
226
|
-
excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
|
|
227
|
-
};
|
|
228
|
-
valueToken = new index_2.Token(value, newConfig, accum, {
|
|
229
|
-
AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
|
|
230
|
-
});
|
|
231
|
-
valueToken.type = 'attr-value';
|
|
232
|
-
valueToken.setAttribute('stage', 5);
|
|
233
|
-
}
|
|
234
|
-
else if (tag === 'choose' && (key === 'before' || key === 'after')) {
|
|
235
|
-
const newConfig = {
|
|
236
|
-
...config,
|
|
237
|
-
excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
|
|
238
|
-
};
|
|
239
|
-
valueToken = new index_2.Token(value, newConfig, accum, {
|
|
240
|
-
ArgToken: ':',
|
|
241
|
-
TranscludeToken: ':',
|
|
242
|
-
LinkToken: ':',
|
|
243
|
-
FileToken: ':',
|
|
244
|
-
CategoryToken: ':',
|
|
245
|
-
QuoteToken: ':',
|
|
246
|
-
ExtLinkToken: ':',
|
|
247
|
-
MagicLinkToken: ':',
|
|
248
|
-
ConverterToken: ':',
|
|
249
|
-
});
|
|
250
|
-
valueToken.type = 'attr-value';
|
|
251
|
-
valueToken.setAttribute('stage', 1);
|
|
230
|
+
#tag;
|
|
231
|
+
#equal;
|
|
232
|
+
#quotes;
|
|
233
|
+
/* NOT FOR BROWSER END */
|
|
234
|
+
/** @private */
|
|
235
|
+
get tag() {
|
|
236
|
+
return this.#tag;
|
|
252
237
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
});
|
|
238
|
+
/** 引号是否匹配 */
|
|
239
|
+
get balanced() {
|
|
240
|
+
return !this.#equal || this.#quotes[0] === this.#quotes[1];
|
|
257
241
|
}
|
|
258
|
-
super(undefined, config, accum);
|
|
259
|
-
this.type = type;
|
|
260
|
-
this.append(keyToken, valueToken);
|
|
261
|
-
this.#equal = equal;
|
|
262
|
-
this.#quotes = [...quotes];
|
|
263
|
-
this.tag = tag;
|
|
264
242
|
/* NOT FOR BROWSER */
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
/** @private */
|
|
270
|
-
afterBuild() {
|
|
271
|
-
if (this.#equal.includes('\0')) {
|
|
272
|
-
this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
|
|
243
|
+
set balanced(value) {
|
|
244
|
+
if (value) {
|
|
245
|
+
this.close();
|
|
246
|
+
}
|
|
273
247
|
}
|
|
274
|
-
|
|
275
|
-
|
|
248
|
+
/** getValue()的getter */
|
|
249
|
+
get value() {
|
|
250
|
+
return this.getValue();
|
|
276
251
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
/** @override */
|
|
293
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
294
|
-
const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
|
|
295
|
-
let rect;
|
|
296
|
-
if (!balanced) {
|
|
297
|
-
const root = this.getRootNode();
|
|
298
|
-
rect = { start, ...root.posFromIndex(start) };
|
|
299
|
-
const e = (0, lint_1.generateForChild)(lastChild, rect, index_1.default.msg('unclosed $1', 'quotes'), 'warning');
|
|
300
|
-
errors.push({
|
|
301
|
-
...e,
|
|
302
|
-
startIndex: e.startIndex - 1,
|
|
303
|
-
startCol: e.startCol - 1,
|
|
252
|
+
set value(value) {
|
|
253
|
+
this.setValue(value);
|
|
254
|
+
}
|
|
255
|
+
/* NOT FOR BROWSER END */
|
|
256
|
+
/**
|
|
257
|
+
* @param type 标签类型
|
|
258
|
+
* @param tag 标签名
|
|
259
|
+
* @param key 属性名
|
|
260
|
+
* @param equal 等号
|
|
261
|
+
* @param value 属性值
|
|
262
|
+
* @param quotes 引号
|
|
263
|
+
*/
|
|
264
|
+
constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
|
|
265
|
+
const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
|
|
266
|
+
[type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
|
|
304
267
|
});
|
|
268
|
+
let valueToken;
|
|
269
|
+
if (key === 'title' || tag === 'img' && key === 'alt') {
|
|
270
|
+
valueToken = new index_2.Token(value, config, accum, {
|
|
271
|
+
[`Stage-${stages[type]}`]: ':', ConverterToken: ':',
|
|
272
|
+
});
|
|
273
|
+
valueToken.type = 'attr-value';
|
|
274
|
+
valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
|
|
275
|
+
}
|
|
276
|
+
else if (tag === 'gallery' && key === 'caption') {
|
|
277
|
+
const newConfig = {
|
|
278
|
+
...config,
|
|
279
|
+
excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
|
|
280
|
+
};
|
|
281
|
+
valueToken = new index_2.Token(value, newConfig, accum, {
|
|
282
|
+
AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
|
|
283
|
+
});
|
|
284
|
+
valueToken.type = 'attr-value';
|
|
285
|
+
valueToken.setAttribute('stage', 5);
|
|
286
|
+
}
|
|
287
|
+
else if (tag === 'choose' && (key === 'before' || key === 'after')) {
|
|
288
|
+
const newConfig = {
|
|
289
|
+
...config,
|
|
290
|
+
excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
|
|
291
|
+
};
|
|
292
|
+
valueToken = new index_2.Token(value, newConfig, accum, {
|
|
293
|
+
ArgToken: ':',
|
|
294
|
+
TranscludeToken: ':',
|
|
295
|
+
LinkToken: ':',
|
|
296
|
+
FileToken: ':',
|
|
297
|
+
CategoryToken: ':',
|
|
298
|
+
QuoteToken: ':',
|
|
299
|
+
ExtLinkToken: ':',
|
|
300
|
+
MagicLinkToken: ':',
|
|
301
|
+
ConverterToken: ':',
|
|
302
|
+
});
|
|
303
|
+
valueToken.type = 'attr-value';
|
|
304
|
+
valueToken.setAttribute('stage', 1);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
|
|
308
|
+
[`Stage-${stages[type]}`]: ':',
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
super(undefined, config, accum);
|
|
312
|
+
this.type = type;
|
|
313
|
+
this.append(keyToken, valueToken);
|
|
314
|
+
this.#equal = equal;
|
|
315
|
+
this.#quotes = [...quotes];
|
|
316
|
+
this.#tag = tag;
|
|
317
|
+
this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
|
|
305
318
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
319
|
+
/** @private */
|
|
320
|
+
afterBuild() {
|
|
321
|
+
if (this.#equal.includes('\0')) {
|
|
322
|
+
this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
|
|
323
|
+
}
|
|
324
|
+
if (this.parentNode) {
|
|
325
|
+
this.#tag = this.parentNode.name;
|
|
326
|
+
}
|
|
327
|
+
this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
|
|
313
328
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
329
|
+
/** @private */
|
|
330
|
+
toString() {
|
|
331
|
+
const [quoteStart = '', quoteEnd = ''] = this.#quotes;
|
|
332
|
+
return this.#equal ? `${super.toString(`${this.#equal}${quoteStart}`)}${quoteEnd}` : String(this.firstChild);
|
|
317
333
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
334
|
+
/** @override */
|
|
335
|
+
text() {
|
|
336
|
+
return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
|
|
321
337
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
338
|
+
/** @private */
|
|
339
|
+
getGaps() {
|
|
340
|
+
return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
|
|
325
341
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
342
|
+
/** @override */
|
|
343
|
+
lint(start = this.getAbsoluteIndex()) {
|
|
344
|
+
const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
|
|
345
|
+
let rect;
|
|
346
|
+
if (!balanced) {
|
|
347
|
+
const root = this.getRootNode();
|
|
348
|
+
rect = { start, ...root.posFromIndex(start) };
|
|
349
|
+
const e = (0, lint_1.generateForChild)(lastChild, rect, index_1.default.msg('unclosed $1', 'quotes'), 'warning');
|
|
350
|
+
errors.push({
|
|
351
|
+
...e,
|
|
352
|
+
startIndex: e.startIndex - 1,
|
|
353
|
+
startCol: e.startCol - 1,
|
|
354
|
+
});
|
|
334
355
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
|
|
358
|
-
token.firstChild.safeReplaceWith(key);
|
|
359
|
-
token.lastChild.safeReplaceWith(value);
|
|
360
|
-
token.setAttribute('name', this.name);
|
|
361
|
-
return token;
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
/** 转义等号 */
|
|
365
|
-
escape() {
|
|
366
|
-
this.#equal = '{{=}}';
|
|
367
|
-
}
|
|
368
|
-
/** 闭合引号 */
|
|
369
|
-
close() {
|
|
370
|
-
const [opening] = this.#quotes;
|
|
371
|
-
if (opening) {
|
|
372
|
-
this.#quotes[1] = opening;
|
|
356
|
+
const attrs = extAttrs[tag];
|
|
357
|
+
if (attrs && !attrs.has(name)
|
|
358
|
+
|| (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
|
|
359
|
+
&& !htmlAttrs[tag]?.has(name)
|
|
360
|
+
&& !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
|
|
361
|
+
&& (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
|
|
362
|
+
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
363
|
+
errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal attribute name'));
|
|
364
|
+
}
|
|
365
|
+
else if (obsoleteAttrs[tag]?.has(name)) {
|
|
366
|
+
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
367
|
+
errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete attribute', 'warning'));
|
|
368
|
+
}
|
|
369
|
+
else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
|
|
370
|
+
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
371
|
+
errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure style'));
|
|
372
|
+
}
|
|
373
|
+
else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
|
|
374
|
+
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
375
|
+
errors.push((0, lint_1.generateForChild)(lastChild, rect, 'nonzero tabindex'));
|
|
376
|
+
}
|
|
377
|
+
return errors;
|
|
373
378
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
this.
|
|
384
|
-
return;
|
|
379
|
+
/** 获取属性值 */
|
|
380
|
+
getValue() {
|
|
381
|
+
if (this.#equal) {
|
|
382
|
+
const value = this.lastChild.text();
|
|
383
|
+
if (this.#quotes[1]) {
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
|
|
387
|
+
}
|
|
388
|
+
return this.type === 'ext-attr' || '';
|
|
385
389
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
390
|
+
/** @override */
|
|
391
|
+
print() {
|
|
392
|
+
const [quoteStart = '', quoteEnd = ''] = this.#quotes;
|
|
393
|
+
return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
|
|
389
394
|
}
|
|
390
|
-
|
|
391
|
-
|
|
395
|
+
/* NOT FOR BROWSER */
|
|
396
|
+
/** @private */
|
|
397
|
+
getAttribute(key) {
|
|
398
|
+
if (key === 'equal') {
|
|
399
|
+
return this.#equal;
|
|
400
|
+
}
|
|
401
|
+
return key === 'quotes' ? this.#quotes : super.getAttribute(key);
|
|
392
402
|
}
|
|
393
|
-
|
|
394
|
-
|
|
403
|
+
/** @override */
|
|
404
|
+
cloneNode() {
|
|
405
|
+
const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
|
|
406
|
+
return debug_1.Shadow.run(() => {
|
|
407
|
+
// @ts-expect-error abstract class
|
|
408
|
+
const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
|
|
409
|
+
token.firstChild.safeReplaceWith(key);
|
|
410
|
+
token.lastChild.safeReplaceWith(value);
|
|
411
|
+
token.setAttribute('name', this.name);
|
|
412
|
+
return token;
|
|
413
|
+
});
|
|
395
414
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
this.#quotes = [`'`, `'`];
|
|
415
|
+
/** 转义等号 */
|
|
416
|
+
escape() {
|
|
417
|
+
this.#equal = '{{=}}';
|
|
400
418
|
}
|
|
401
|
-
|
|
402
|
-
|
|
419
|
+
/** 闭合引号 */
|
|
420
|
+
close() {
|
|
421
|
+
const [opening] = this.#quotes;
|
|
422
|
+
if (opening) {
|
|
423
|
+
this.#quotes[1] = opening;
|
|
424
|
+
}
|
|
403
425
|
}
|
|
404
|
-
|
|
405
|
-
|
|
426
|
+
/**
|
|
427
|
+
* 设置属性值
|
|
428
|
+
* @param value 参数值
|
|
429
|
+
* @throws `RangeError` 扩展标签属性不能包含 ">"
|
|
430
|
+
* @throws `RangeError` 同时包含单引号和双引号
|
|
431
|
+
*/
|
|
432
|
+
setValue(value) {
|
|
433
|
+
if (value === false) {
|
|
434
|
+
this.remove();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
else if (value === true) {
|
|
438
|
+
this.#equal = '';
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
else if (this.type === 'ext-attr' && value.includes('>')) {
|
|
442
|
+
throw new RangeError('扩展标签属性不能包含 ">"!');
|
|
443
|
+
}
|
|
444
|
+
else if (value.includes('"') && value.includes(`'`)) {
|
|
445
|
+
throw new RangeError('属性值不能同时包含单引号和双引号!');
|
|
446
|
+
}
|
|
447
|
+
const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
|
|
448
|
+
this.lastChild.replaceChildren(...childNodes);
|
|
449
|
+
if (value.includes('"')) {
|
|
450
|
+
this.#quotes = [`'`, `'`];
|
|
451
|
+
}
|
|
452
|
+
else if (value.includes(`'`) || !this.#quotes[0]) {
|
|
453
|
+
this.#quotes = ['"', '"'];
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
this.close();
|
|
457
|
+
}
|
|
406
458
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
459
|
+
/**
|
|
460
|
+
* 修改属性名
|
|
461
|
+
* @param key 新属性名
|
|
462
|
+
* @throws `Error` title和alt属性不能更名
|
|
463
|
+
*/
|
|
464
|
+
rename(key) {
|
|
465
|
+
if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
|
|
466
|
+
throw new Error(`${this.name} 属性不能更名!`);
|
|
467
|
+
}
|
|
468
|
+
const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
|
|
469
|
+
this.firstChild.replaceChildren(...childNodes);
|
|
416
470
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
471
|
+
};
|
|
472
|
+
return AttributeToken = _classThis;
|
|
473
|
+
})();
|
|
421
474
|
exports.AttributeToken = AttributeToken;
|
|
422
475
|
constants_1.classes['AttributeToken'] = __filename;
|
package/dist/src/attributes.d.ts
CHANGED
|
@@ -15,12 +15,12 @@ export declare abstract class AttributesToken extends Token {
|
|
|
15
15
|
type: AttributesTypes;
|
|
16
16
|
readonly name: string;
|
|
17
17
|
readonly childNodes: readonly (AtomToken | AttributeToken)[];
|
|
18
|
-
abstract get children(): (AtomToken | AttributeToken)[];
|
|
19
18
|
abstract get firstChild(): AtomToken | AttributeToken | undefined;
|
|
20
|
-
abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
|
|
21
19
|
abstract get lastChild(): AtomToken | AttributeToken | undefined;
|
|
22
|
-
abstract get lastElementChild(): AtomToken | AttributeToken | undefined;
|
|
23
20
|
abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
|
|
21
|
+
abstract get children(): (AtomToken | AttributeToken)[];
|
|
22
|
+
abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
|
|
23
|
+
abstract get lastElementChild(): AtomToken | AttributeToken | undefined;
|
|
24
24
|
abstract get parentElement(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
|
|
25
25
|
/** getAttrs()方法的getter写法 */
|
|
26
26
|
get attributes(): Record<string, string | true>;
|
package/dist/src/attributes.js
CHANGED
|
@@ -26,7 +26,6 @@ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
|
|
|
26
26
|
* @classdesc `{childNodes: ...AtomToken|AttributeToken}`
|
|
27
27
|
*/
|
|
28
28
|
class AttributesToken extends index_2.Token {
|
|
29
|
-
/* NOT FOR BROWSER */
|
|
30
29
|
/** getAttrs()方法的getter写法 */
|
|
31
30
|
get attributes() {
|
|
32
31
|
return this.getAttrs();
|
package/dist/src/converter.d.ts
CHANGED
|
@@ -5,11 +5,17 @@ import { ConverterRuleToken } from './converterRule';
|
|
|
5
5
|
import type { FlagsParentBase } from '../mixin/flagsParent';
|
|
6
6
|
export interface ConverterToken extends FlagsParentBase {
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* 转换
|
|
10
|
+
* @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
|
|
11
|
+
*/
|
|
8
12
|
export declare abstract class ConverterToken extends Token {
|
|
9
13
|
readonly type = "converter";
|
|
10
14
|
readonly childNodes: readonly [ConverterFlagsToken, ...ConverterRuleToken[]];
|
|
11
|
-
abstract get
|
|
15
|
+
abstract get firstChild(): ConverterFlagsToken;
|
|
12
16
|
abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
|
|
17
|
+
abstract get children(): [ConverterFlagsToken, ...ConverterRuleToken[]];
|
|
18
|
+
abstract get firstElementChild(): ConverterFlagsToken;
|
|
13
19
|
abstract get lastElementChild(): ConverterFlagsToken | ConverterRuleToken;
|
|
14
20
|
/** 是否不转换 */
|
|
15
21
|
get noConvert(): boolean;
|
|
@@ -25,4 +31,3 @@ export declare abstract class ConverterToken extends Token {
|
|
|
25
31
|
/** @override */
|
|
26
32
|
cloneNode(): this;
|
|
27
33
|
}
|
|
28
|
-
export {};
|