wikiparser-node 1.29.0 → 1.29.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/bundle-es8.min.js +24 -24
- package/bundle/bundle-lsp.min.js +19 -19
- package/bundle/bundle.min.js +22 -22
- package/dist/addon/transclude.js +19 -2
- package/dist/bin/config.js +1 -1
- package/dist/lib/document.js +16 -12
- package/dist/lib/lsp.js +81 -79
- package/dist/lib/text.js +7 -14
- package/dist/mixin/elementLike.d.ts +1 -1
- package/dist/parser/commentAndExt.js +1 -1
- package/dist/src/atom.d.ts +1 -1
- package/dist/src/atom.js +0 -2
- package/dist/src/attribute.js +4 -2
- package/dist/src/attributes.d.ts +1 -0
- package/dist/src/attributes.js +8 -1
- package/dist/src/converter.js +1 -2
- package/dist/src/converterFlags.js +2 -1
- package/dist/src/converterRule.d.ts +8 -8
- package/dist/src/converterRule.js +34 -9
- package/dist/src/hidden.js +2 -1
- package/dist/src/imageParameter.d.ts +6 -1
- package/dist/src/imageParameter.js +308 -252
- package/dist/src/index.js +10 -8
- package/dist/src/link/base.js +2 -2
- package/dist/src/nowiki/index.js +35 -33
- package/dist/src/table/index.js +3 -2
- package/dist/src/tag/html.js +1 -1
- package/dist/src/tag/tvar.js +2 -1
- package/dist/src/transclude.d.ts +4 -2
- package/dist/src/transclude.js +8 -7
- package/dist/util/html.js +2 -4
- package/extensions/dist/base.js +1 -1
- package/package.json +2 -2
|
@@ -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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
38
|
};
|
|
@@ -9,6 +43,7 @@ const string_1 = require("../util/string");
|
|
|
9
43
|
const lint_1 = require("../util/lint");
|
|
10
44
|
const constants_1 = require("../util/constants");
|
|
11
45
|
const debug_1 = require("../util/debug");
|
|
46
|
+
const noEscape_1 = require("../mixin/noEscape");
|
|
12
47
|
const index_1 = __importDefault(require("../index"));
|
|
13
48
|
const index_2 = require("./index");
|
|
14
49
|
/^(?:ftp:\/\/|\/\/|\0\d+m\x7F)/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
|
|
@@ -72,292 +107,313 @@ function validate(key, val, config, halfParsed, ext) {
|
|
|
72
107
|
*
|
|
73
108
|
* 图片参数
|
|
74
109
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
110
|
+
let ImageParameterToken = (() => {
|
|
111
|
+
let _classDecorators = [noEscape_1.noEscape];
|
|
112
|
+
let _classDescriptor;
|
|
113
|
+
let _classExtraInitializers = [];
|
|
114
|
+
let _classThis;
|
|
115
|
+
let _classSuper = index_2.Token;
|
|
116
|
+
var ImageParameterToken = class extends _classSuper {
|
|
117
|
+
static { _classThis = this; }
|
|
118
|
+
static {
|
|
119
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
120
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
121
|
+
ImageParameterToken = _classThis = _classDescriptor.value;
|
|
122
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
123
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
124
|
+
}
|
|
125
|
+
#syntax = '';
|
|
126
|
+
#extension;
|
|
127
|
+
/* NOT FOR BROWSER END */
|
|
128
|
+
get type() {
|
|
129
|
+
return 'image-parameter';
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* thumbnail
|
|
133
|
+
*
|
|
134
|
+
* 缩略图
|
|
135
|
+
* @since v1.29.0
|
|
136
|
+
*/
|
|
137
|
+
get thumb() {
|
|
138
|
+
LINT: return this.name === 'manualthumb' // eslint-disable-line no-unused-labels
|
|
139
|
+
? this.normalizeTitle(`File:${super.text().trim()}`, 6, { page: '' })
|
|
140
|
+
: undefined;
|
|
141
|
+
}
|
|
142
|
+
/** image link / 图片链接 */
|
|
143
|
+
get link() {
|
|
144
|
+
LINT: { // eslint-disable-line no-unused-labels
|
|
145
|
+
if (this.name !== 'link') {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
const value = super.text().trim();
|
|
149
|
+
return debug_1.Shadow.run(() => {
|
|
150
|
+
const token = new index_2.Token(value, this.getAttribute('config'));
|
|
151
|
+
token.parseOnce(0, this.getAttribute('include')).parseOnce();
|
|
152
|
+
return /^\0\d+m\x7F/u.test(token.toString())
|
|
153
|
+
? value
|
|
154
|
+
: validate('link', value, this.getAttribute('config'));
|
|
155
|
+
});
|
|
93
156
|
}
|
|
94
|
-
const value = super.text().trim();
|
|
95
|
-
return debug_1.Shadow.run(() => {
|
|
96
|
-
const token = new index_2.Token(value, this.getAttribute('config'));
|
|
97
|
-
token.parseOnce(0, this.getAttribute('include')).parseOnce();
|
|
98
|
-
return /^\0\d+m\x7F/u.test(token.toString())
|
|
99
|
-
? value
|
|
100
|
-
: validate('link', value, this.getAttribute('config'));
|
|
101
|
-
});
|
|
102
157
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
158
|
+
/* NOT FOR BROWSER */
|
|
159
|
+
set link(value) {
|
|
160
|
+
if (this.name === 'link') {
|
|
161
|
+
this.setValue(value);
|
|
162
|
+
}
|
|
108
163
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
164
|
+
set thumb(value) {
|
|
165
|
+
if (this.name === 'manualthumb') {
|
|
166
|
+
this.setValue(value);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** parameter value / 参数值 */
|
|
170
|
+
get value() {
|
|
171
|
+
return this.getValue();
|
|
172
|
+
}
|
|
173
|
+
set value(value) {
|
|
112
174
|
this.setValue(value);
|
|
113
175
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return { width, height };
|
|
176
|
+
/** iamge size / 图片大小 */
|
|
177
|
+
get size() {
|
|
178
|
+
if (this.name === 'width') {
|
|
179
|
+
const size = this.getValue().trim().replace(/px$/u, '').trim();
|
|
180
|
+
if (!size.includes('{{')) {
|
|
181
|
+
const [width, height = ''] = size.split('x');
|
|
182
|
+
return { width, height };
|
|
183
|
+
}
|
|
184
|
+
const token = index_1.default.parseWithRef(size, this, 2, false), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
|
|
185
|
+
if (i === -1) {
|
|
186
|
+
return { width: size, height: '' };
|
|
187
|
+
}
|
|
188
|
+
const str = token.childNodes[i];
|
|
189
|
+
str.splitText(str.data.indexOf('x')).splitText(1);
|
|
190
|
+
return { width: (0, string_1.text)(token.childNodes.slice(0, i + 1)), height: (0, string_1.text)(token.childNodes.slice(i + 2)) };
|
|
129
191
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
set size(size) {
|
|
195
|
+
if (this.name === 'width') {
|
|
196
|
+
this.setValue(size && size.width + (size.height && 'x') + size.height);
|
|
133
197
|
}
|
|
134
|
-
const str = token.childNodes[i];
|
|
135
|
-
str.splitText(str.data.indexOf('x')).splitText(1);
|
|
136
|
-
return { width: (0, string_1.text)(token.childNodes.slice(0, i + 1)), height: (0, string_1.text)(token.childNodes.slice(i + 2)) };
|
|
137
198
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (this.name === 'width') {
|
|
142
|
-
this.setValue(size && size.width + (size.height && 'x') + size.height);
|
|
199
|
+
/** image width / 图片宽度 */
|
|
200
|
+
get width() {
|
|
201
|
+
return this.size?.width;
|
|
143
202
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
set width(width) {
|
|
150
|
-
if (this.name === 'width') {
|
|
151
|
-
const { height } = this;
|
|
152
|
-
this.setValue((width || '') + (height && 'x') + height);
|
|
203
|
+
set width(width) {
|
|
204
|
+
if (this.name === 'width') {
|
|
205
|
+
const { height } = this;
|
|
206
|
+
this.setValue((width || '') + (height && 'x') + height);
|
|
207
|
+
}
|
|
153
208
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return this.size?.height;
|
|
158
|
-
}
|
|
159
|
-
set height(height) {
|
|
160
|
-
if (this.name === 'width') {
|
|
161
|
-
this.setValue(this.width + (height ? `x${height}` : ''));
|
|
209
|
+
/** image height / 图片高度 */
|
|
210
|
+
get height() {
|
|
211
|
+
return this.size?.height;
|
|
162
212
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
constructor(str, extension, config, accum) {
|
|
167
|
-
let mt;
|
|
168
|
-
const regexes = Object.entries(config.img)
|
|
169
|
-
.map(([syntax, param]) => [syntax, param, getSyntaxRegex(syntax)]), param = regexes.find(([, key, regex]) => {
|
|
170
|
-
mt = regex.exec(str);
|
|
171
|
-
return mt
|
|
172
|
-
&& (mt.length !== 4
|
|
173
|
-
|| validate(key, mt[2], config, true, extension) !== false);
|
|
174
|
-
});
|
|
175
|
-
// @ts-expect-error mt already assigned
|
|
176
|
-
if (param && mt) {
|
|
177
|
-
if (mt.length === 3) {
|
|
178
|
-
super(undefined, config, accum);
|
|
179
|
-
this.#syntax = str;
|
|
213
|
+
set height(height) {
|
|
214
|
+
if (this.name === 'width') {
|
|
215
|
+
this.setValue(this.width + (height ? `x${height}` : ''));
|
|
180
216
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
217
|
+
}
|
|
218
|
+
/* NOT FOR BROWSER END */
|
|
219
|
+
/** @param str 图片参数 */
|
|
220
|
+
constructor(str, extension, config, accum) {
|
|
221
|
+
let mt;
|
|
222
|
+
const regexes = Object.entries(config.img)
|
|
223
|
+
.map(([syntax, param]) => [syntax, param, getSyntaxRegex(syntax)]), param = regexes.find(([, key, regex]) => {
|
|
224
|
+
mt = regex.exec(str);
|
|
225
|
+
return mt
|
|
226
|
+
&& (mt.length !== 4
|
|
227
|
+
|| validate(key, mt[2], config, true, extension) !== false);
|
|
228
|
+
});
|
|
229
|
+
// @ts-expect-error mt already assigned
|
|
230
|
+
if (param && mt) {
|
|
231
|
+
if (mt.length === 3) {
|
|
232
|
+
super(undefined, config, accum);
|
|
233
|
+
this.#syntax = str;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
super(mt[2], config, accum, {
|
|
237
|
+
'Stage-2': ':', '!HeadingToken': '',
|
|
238
|
+
});
|
|
239
|
+
this.#syntax = mt[1] + param[0] + mt[3];
|
|
240
|
+
}
|
|
241
|
+
this.setAttribute('name', param[1]);
|
|
242
|
+
if (param[1] === 'alt') {
|
|
243
|
+
this.setAttribute('stage', constants_1.MAX_STAGE - 1);
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
186
246
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
247
|
+
super(str, config.excludes.includes('list')
|
|
248
|
+
? config
|
|
249
|
+
: {
|
|
250
|
+
...config,
|
|
251
|
+
excludes: [...config.excludes, 'list'],
|
|
252
|
+
}, accum);
|
|
253
|
+
this.setAttribute('name', 'caption');
|
|
254
|
+
this.setAttribute('stage', 7);
|
|
255
|
+
/* NOT FOR BROWSER */
|
|
256
|
+
this.#extension = extension;
|
|
257
|
+
}
|
|
258
|
+
/** @private */
|
|
259
|
+
afterBuild() {
|
|
260
|
+
if (this.parentNode?.is('gallery-image') && !exports.galleryParams.has(this.name)) {
|
|
261
|
+
this.setAttribute('name', 'invalid');
|
|
190
262
|
}
|
|
191
|
-
|
|
263
|
+
super.afterBuild();
|
|
192
264
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
:
|
|
196
|
-
...config,
|
|
197
|
-
excludes: [...config.excludes, 'list'],
|
|
198
|
-
}, accum);
|
|
199
|
-
this.setAttribute('name', 'caption');
|
|
200
|
-
this.setAttribute('stage', 7);
|
|
201
|
-
/* NOT FOR BROWSER */
|
|
202
|
-
this.#extension = extension;
|
|
203
|
-
}
|
|
204
|
-
/** @private */
|
|
205
|
-
afterBuild() {
|
|
206
|
-
if (this.parentNode?.is('gallery-image') && !exports.galleryParams.has(this.name)) {
|
|
207
|
-
this.setAttribute('name', 'invalid');
|
|
265
|
+
/** @private */
|
|
266
|
+
toString(skip) {
|
|
267
|
+
return this.#syntax ? this.#syntax.replace('$1', super.toString(skip)) : super.toString(skip);
|
|
208
268
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
toString(skip) {
|
|
213
|
-
return this.#syntax ? this.#syntax.replace('$1', super.toString(skip)) : super.toString(skip);
|
|
214
|
-
}
|
|
215
|
-
/** @private */
|
|
216
|
-
text() {
|
|
217
|
-
return this.#syntax ? this.#syntax.replace('$1', super.text()).trim() : super.text().trim();
|
|
218
|
-
}
|
|
219
|
-
/** @private */
|
|
220
|
-
isPlain() {
|
|
221
|
-
return this.name === 'caption' || this.name === 'alt';
|
|
222
|
-
}
|
|
223
|
-
/** @private */
|
|
224
|
-
getAttribute(key) {
|
|
225
|
-
/* PRINT ONLY */
|
|
226
|
-
if (key === 'invalid') {
|
|
227
|
-
return (this.name === 'invalid');
|
|
269
|
+
/** @private */
|
|
270
|
+
text() {
|
|
271
|
+
return this.#syntax ? this.#syntax.replace('$1', super.text()).trim() : super.text().trim();
|
|
228
272
|
}
|
|
229
|
-
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (name === 'invalid' || value && value.endsWith('px')) {
|
|
239
|
-
const rule = 'invalid-gallery', s = lintConfig.getSeverity(rule, 'parameter');
|
|
240
|
-
if (s) {
|
|
241
|
-
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-image-parameter', s);
|
|
242
|
-
if (computeEditInfo || fix) {
|
|
243
|
-
e.fix = value ? (0, lint_1.fixByRemove)(e, 0, value) : (0, lint_1.fixByRemove)(e, -1);
|
|
244
|
-
}
|
|
245
|
-
errors.push(e);
|
|
246
|
-
}
|
|
273
|
+
/** @private */
|
|
274
|
+
isPlain() {
|
|
275
|
+
return this.name === 'caption' || this.name === 'alt';
|
|
276
|
+
}
|
|
277
|
+
/** @private */
|
|
278
|
+
getAttribute(key) {
|
|
279
|
+
/* PRINT ONLY */
|
|
280
|
+
if (key === 'invalid') {
|
|
281
|
+
return (this.name === 'invalid');
|
|
247
282
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
else if (link.encoded) {
|
|
261
|
-
const rule = 'url-encoding', s = lintConfig.getSeverity(rule, 'file');
|
|
283
|
+
/** PRINT ONLY END */
|
|
284
|
+
return key === 'padding'
|
|
285
|
+
? Math.max(0, this.#syntax.indexOf('$1'))
|
|
286
|
+
: super.getAttribute(key);
|
|
287
|
+
}
|
|
288
|
+
/** @private */
|
|
289
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
290
|
+
LINT: { // eslint-disable-line no-unused-labels
|
|
291
|
+
const errors = super.lint(start, re), { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, { link, name } = this, value = name === 'width' && this.getValue();
|
|
292
|
+
if (name === 'invalid' || value && value.endsWith('px')) {
|
|
293
|
+
const rule = 'invalid-gallery', s = lintConfig.getSeverity(rule, 'parameter');
|
|
262
294
|
if (s) {
|
|
263
|
-
const e = (0, lint_1.generateForSelf)(this, { start }, rule, '
|
|
295
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-image-parameter', s);
|
|
264
296
|
if (computeEditInfo || fix) {
|
|
265
|
-
e.fix = (0, lint_1.
|
|
297
|
+
e.fix = value ? (0, lint_1.fixByRemove)(e, 0, value) : (0, lint_1.fixByRemove)(e, -1);
|
|
266
298
|
}
|
|
267
299
|
errors.push(e);
|
|
268
300
|
}
|
|
269
301
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
302
|
+
else if (name === 'link') {
|
|
303
|
+
if (typeof link === 'string') {
|
|
304
|
+
const rule = 'invalid-url', s = lintConfig.getSeverity(rule);
|
|
305
|
+
if (s && !this.querySelector('magic-word')) {
|
|
306
|
+
try {
|
|
307
|
+
getUrl(link);
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
errors.push((0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-url', s));
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else if (link.encoded) {
|
|
315
|
+
const rule = 'url-encoding', s = lintConfig.getSeverity(rule, 'file');
|
|
316
|
+
if (s) {
|
|
317
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'unnecessary-encoding', s);
|
|
318
|
+
if (computeEditInfo || fix) {
|
|
319
|
+
e.fix = (0, lint_1.fixByDecode)(e, this);
|
|
320
|
+
}
|
|
321
|
+
errors.push(e);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (name === 'manualthumb') {
|
|
326
|
+
const rule = 'invalid-gallery', s = lintConfig.getSeverity(rule, 'thumb');
|
|
327
|
+
if (s && !this.querySelector('arg,magic-word,template')) {
|
|
328
|
+
const { valid, ns, extension,
|
|
329
|
+
/* NOT FOR BROWSER */
|
|
330
|
+
interwiki, } = this.thumb;
|
|
331
|
+
if (!valid || ns !== 6 || !exports.extensions.has(extension)
|
|
332
|
+
|| interwiki) {
|
|
333
|
+
errors.push((0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-thumb', s));
|
|
334
|
+
}
|
|
280
335
|
}
|
|
281
336
|
}
|
|
337
|
+
return errors;
|
|
282
338
|
}
|
|
283
|
-
return errors;
|
|
284
339
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
LINT: return this.#syntax && !this.#syntax.includes('$1'); // eslint-disable-line no-unused-labels
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Get the parameter value
|
|
292
|
-
*
|
|
293
|
-
* 获取参数值
|
|
294
|
-
*/
|
|
295
|
-
getValue() {
|
|
296
|
-
// eslint-disable-next-line no-unused-labels
|
|
297
|
-
LINT: return this.name === 'invalid' ? this.text() : this.#isVoid() || super.text();
|
|
298
|
-
}
|
|
299
|
-
/** @private */
|
|
300
|
-
print() {
|
|
301
|
-
if (this.#syntax) {
|
|
302
|
-
return `<span class="wpb-image-parameter${this.name === 'invalid' ? ' wpb-invalid' : ''}">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
|
|
340
|
+
/** 是否是不可变参数 */
|
|
341
|
+
#isVoid() {
|
|
342
|
+
LINT: return this.#syntax && !this.#syntax.includes('$1'); // eslint-disable-line no-unused-labels
|
|
303
343
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
//
|
|
311
|
-
|
|
312
|
-
token.safeReplaceChildren(cloned);
|
|
313
|
-
return token;
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
insertAt(token, i) {
|
|
317
|
-
if (!debug_1.Shadow.running && this.#isVoid()) {
|
|
318
|
-
throw new Error(`Image parameter ${this.name} does not accept custom input!`);
|
|
344
|
+
/**
|
|
345
|
+
* Get the parameter value
|
|
346
|
+
*
|
|
347
|
+
* 获取参数值
|
|
348
|
+
*/
|
|
349
|
+
getValue() {
|
|
350
|
+
// eslint-disable-next-line no-unused-labels
|
|
351
|
+
LINT: return this.name === 'invalid' ? this.text() : this.#isVoid() || super.text();
|
|
319
352
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
* @param value parameter value / 参数值
|
|
327
|
-
* @throws `Error` 无效参数
|
|
328
|
-
*/
|
|
329
|
-
setValue(value = false) {
|
|
330
|
-
const { name } = this;
|
|
331
|
-
if (value === false) {
|
|
332
|
-
this.remove();
|
|
333
|
-
return;
|
|
353
|
+
/** @private */
|
|
354
|
+
print() {
|
|
355
|
+
if (this.#syntax) {
|
|
356
|
+
return `<span class="wpb-image-parameter${this.name === 'invalid' ? ' wpb-invalid' : ''}">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
|
|
357
|
+
}
|
|
358
|
+
return super.print({ class: 'image-caption' });
|
|
334
359
|
}
|
|
335
|
-
|
|
336
|
-
|
|
360
|
+
/* NOT FOR BROWSER */
|
|
361
|
+
cloneNode() {
|
|
362
|
+
const cloned = this.cloneChildNodes();
|
|
363
|
+
return debug_1.Shadow.run(() => {
|
|
364
|
+
// @ts-expect-error abstract class
|
|
365
|
+
const token = new ImageParameterToken(this.#syntax.replace('$1', '1'), this.#extension, this.getAttribute('config'));
|
|
366
|
+
token.safeReplaceChildren(cloned);
|
|
367
|
+
return token;
|
|
368
|
+
});
|
|
337
369
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
370
|
+
insertAt(token, i) {
|
|
371
|
+
if (!debug_1.Shadow.running && this.#isVoid()) {
|
|
372
|
+
throw new Error(`Image parameter ${this.name} does not accept custom input!`);
|
|
373
|
+
}
|
|
374
|
+
return super.insertAt(token, i);
|
|
341
375
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
376
|
+
/**
|
|
377
|
+
* Set the parameter value
|
|
378
|
+
*
|
|
379
|
+
* 设置参数值
|
|
380
|
+
* @param value parameter value / 参数值
|
|
381
|
+
* @throws `Error` 无效参数
|
|
382
|
+
*/
|
|
383
|
+
setValue(value = false) {
|
|
384
|
+
const { name } = this;
|
|
385
|
+
if (value === false) {
|
|
386
|
+
this.remove();
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
else if (name === 'invalid') {
|
|
390
|
+
throw new Error('Invalid image parameter!');
|
|
391
|
+
}
|
|
392
|
+
const type = this.#isVoid() ? 'Boolean' : 'String';
|
|
393
|
+
if (typeof value !== type.toLowerCase()) { // eslint-disable-line valid-typeof
|
|
394
|
+
this.typeError('setValue', type);
|
|
395
|
+
}
|
|
396
|
+
else if (value !== true) {
|
|
397
|
+
const { childNodes } = index_1.default.parseWithRef(value, this, name === 'caption' ? undefined : 5);
|
|
398
|
+
this.safeReplaceChildren(childNodes);
|
|
399
|
+
}
|
|
345
400
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
401
|
+
/**
|
|
402
|
+
* Get the URL
|
|
403
|
+
*
|
|
404
|
+
* 获取网址
|
|
405
|
+
* @param articlePath article path / 条目路径
|
|
406
|
+
* @since v1.11.0
|
|
407
|
+
*/
|
|
408
|
+
getUrl(articlePath) {
|
|
409
|
+
const { link } = this;
|
|
410
|
+
if (!link) {
|
|
411
|
+
return link;
|
|
412
|
+
}
|
|
413
|
+
return typeof link === 'string' ? getUrl(link) : link.getUrl(articlePath);
|
|
358
414
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
415
|
+
};
|
|
416
|
+
return ImageParameterToken = _classThis;
|
|
417
|
+
})();
|
|
362
418
|
exports.ImageParameterToken = ImageParameterToken;
|
|
363
419
|
constants_1.classes['ImageParameterToken'] = __filename;
|
package/dist/src/index.js
CHANGED
|
@@ -165,20 +165,22 @@ let Token = (() => {
|
|
|
165
165
|
set type(value) {
|
|
166
166
|
/* NOT FOR BROWSER */
|
|
167
167
|
const plainTypes = [
|
|
168
|
-
'plain',
|
|
169
168
|
'root',
|
|
170
|
-
'
|
|
171
|
-
'
|
|
169
|
+
'plain',
|
|
170
|
+
'translate-inner',
|
|
172
171
|
'attr-value',
|
|
173
|
-
'ext-
|
|
174
|
-
'
|
|
172
|
+
'ext-inner',
|
|
173
|
+
'arg-default',
|
|
175
174
|
'parameter-key',
|
|
176
175
|
'parameter-value',
|
|
177
|
-
'
|
|
176
|
+
'heading-title',
|
|
177
|
+
'table-inter',
|
|
178
178
|
'td-inner',
|
|
179
|
-
'
|
|
179
|
+
'link-text',
|
|
180
|
+
'ext-link-text',
|
|
180
181
|
'list-range',
|
|
181
|
-
'
|
|
182
|
+
'converter-rule-to',
|
|
183
|
+
'converter-rule-from',
|
|
182
184
|
];
|
|
183
185
|
if (!plainTypes.includes(value)) {
|
|
184
186
|
throw new RangeError(`"${value}" is not a valid type for ${this.constructor.name}!`);
|