wikiparser-node 1.0.0-beta.2 → 1.0.0-beta.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/src/arg.js +5 -5
- package/dist/src/attribute.js +5 -5
- package/dist/src/converterRule.js +5 -5
- package/dist/src/extLink.js +5 -5
- package/dist/src/imageParameter.js +3 -3
- package/dist/src/index.js +4 -1
- package/dist/src/link/base.js +6 -6
- package/dist/src/link/file.js +3 -3
- package/dist/src/link/galleryImage.js +5 -5
- package/dist/src/magicLink.js +3 -3
- package/dist/src/parameter.js +5 -5
- package/dist/src/transclude.js +6 -6
- package/package.json +1 -1
package/dist/src/arg.js
CHANGED
|
@@ -168,12 +168,12 @@ class ArgToken extends _1.Token {
|
|
|
168
168
|
*/
|
|
169
169
|
setName(name) {
|
|
170
170
|
const root = index_1.default.parse(`{{{${name}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
|
|
171
|
-
if (length
|
|
172
|
-
|
|
173
|
-
arg.destroy();
|
|
174
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
171
|
+
if (length !== 1 || !(arg instanceof ArgToken) || arg.length !== 1) {
|
|
172
|
+
throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
|
|
175
173
|
}
|
|
176
|
-
|
|
174
|
+
const { firstChild } = arg;
|
|
175
|
+
arg.destroy();
|
|
176
|
+
this.firstChild.safeReplaceWith(firstChild);
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* 设置预设值
|
package/dist/src/attribute.js
CHANGED
|
@@ -424,12 +424,12 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
|
|
|
424
424
|
attrs = tag.firstChild;
|
|
425
425
|
}
|
|
426
426
|
const { firstChild: attr } = attrs;
|
|
427
|
-
if (attrs.length
|
|
428
|
-
|
|
429
|
-
attr.destroy();
|
|
430
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
427
|
+
if (attrs.length !== 1 || attr.type !== this.type || attr.value !== true) {
|
|
428
|
+
throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
|
|
431
429
|
}
|
|
432
|
-
|
|
430
|
+
const { firstChild } = attr;
|
|
431
|
+
attr.destroy();
|
|
432
|
+
this.firstChild.safeReplaceWith(firstChild);
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
exports.AttributeToken = AttributeToken;
|
|
@@ -187,12 +187,12 @@ class ConverterRuleToken extends _1.Token {
|
|
|
187
187
|
throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
|
|
188
188
|
}
|
|
189
189
|
const { lastChild: converterRule } = converter;
|
|
190
|
-
if (converter.length
|
|
191
|
-
|
|
192
|
-
converterRule.destroy();
|
|
193
|
-
this.lastChild.safeReplaceWith(lastChild);
|
|
190
|
+
if (converter.length !== 2 || converterRule.length !== 2) {
|
|
191
|
+
throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
|
|
194
192
|
}
|
|
195
|
-
|
|
193
|
+
const { lastChild } = converterRule;
|
|
194
|
+
converterRule.destroy();
|
|
195
|
+
this.lastChild.safeReplaceWith(lastChild);
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
198
|
* 设置语言变体
|
package/dist/src/extLink.js
CHANGED
|
@@ -126,12 +126,12 @@ class ExtLinkToken extends _1.Token {
|
|
|
126
126
|
*/
|
|
127
127
|
setTarget(url) {
|
|
128
128
|
const strUrl = String(url), root = index_1.default.parse(`[${strUrl}]`, this.getAttribute('include'), 8, this.getAttribute('config')), { length, firstChild: extLink } = root;
|
|
129
|
-
if (length
|
|
130
|
-
|
|
131
|
-
extLink.destroy();
|
|
132
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
129
|
+
if (length !== 1 || !(extLink instanceof ExtLinkToken) || extLink.length !== 1) {
|
|
130
|
+
throw new SyntaxError(`非法的外链目标:${strUrl}`);
|
|
133
131
|
}
|
|
134
|
-
|
|
132
|
+
const { firstChild } = extLink;
|
|
133
|
+
extLink.destroy();
|
|
134
|
+
this.firstChild.safeReplaceWith(firstChild);
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* 设置链接显示文字
|
|
@@ -246,10 +246,10 @@ class ImageParameterToken extends _1.Token {
|
|
|
246
246
|
throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
|
|
247
247
|
}
|
|
248
248
|
const { lastChild: imageParameter, name } = file;
|
|
249
|
-
if (name
|
|
250
|
-
this.
|
|
249
|
+
if (name !== 'File:F' || imageParameter.name !== this.name) {
|
|
250
|
+
throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
|
|
251
251
|
}
|
|
252
|
-
|
|
252
|
+
this.replaceChildren(...imageParameter.childNodes);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
exports.ImageParameterToken = ImageParameterToken;
|
package/dist/src/index.js
CHANGED
package/dist/src/link/base.js
CHANGED
|
@@ -192,13 +192,13 @@ class LinkBaseToken extends __1.Token {
|
|
|
192
192
|
strLink = `:${strLink}`;
|
|
193
193
|
}
|
|
194
194
|
const root = index_1.default.parse(`[[${strLink}]]`, this.getAttribute('include'), 6, this.getAttribute('config')), { length, firstChild: wikiLink } = root;
|
|
195
|
-
if (length
|
|
196
|
-
const {
|
|
197
|
-
|
|
198
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
195
|
+
if (length !== 1 || wikiLink?.type !== this.type || wikiLink.length !== 1) {
|
|
196
|
+
const msgs = { link: '内链', file: '文件链接', category: '分类' };
|
|
197
|
+
throw new SyntaxError(`非法的${msgs[this.type]}目标:${strLink}`);
|
|
199
198
|
}
|
|
200
|
-
const
|
|
201
|
-
|
|
199
|
+
const { firstChild } = wikiLink;
|
|
200
|
+
wikiLink.destroy();
|
|
201
|
+
this.firstChild.safeReplaceWith(firstChild);
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* 设置链接显示文字
|
package/dist/src/link/file.js
CHANGED
|
@@ -259,10 +259,10 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
259
259
|
throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
|
|
260
260
|
}
|
|
261
261
|
const { name, lastChild: imageParameter } = file;
|
|
262
|
-
if (name
|
|
263
|
-
|
|
262
|
+
if (name !== 'File:F' || imageParameter.name !== key) {
|
|
263
|
+
throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
|
|
264
264
|
}
|
|
265
|
-
|
|
265
|
+
this.insertAt(imageParameter);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
exports.FileToken = FileToken;
|
|
@@ -88,12 +88,12 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
|
|
|
88
88
|
throw new SyntaxError(`非法的图库文件名:${link}`);
|
|
89
89
|
}
|
|
90
90
|
const { lastChild: gallery } = ext, { firstChild: image } = gallery;
|
|
91
|
-
if (gallery.length
|
|
92
|
-
|
|
93
|
-
image.destroy();
|
|
94
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
91
|
+
if (gallery.length !== 1 || image.type !== 'gallery-image') {
|
|
92
|
+
throw new SyntaxError(`非法的图库文件名:${link}`);
|
|
95
93
|
}
|
|
96
|
-
|
|
94
|
+
const { firstChild } = image;
|
|
95
|
+
image.destroy();
|
|
96
|
+
this.firstChild.safeReplaceWith(firstChild);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
exports.GalleryImageToken = GalleryImageToken;
|
package/dist/src/magicLink.js
CHANGED
|
@@ -116,10 +116,10 @@ class MagicLinkToken extends _1.Token {
|
|
|
116
116
|
*/
|
|
117
117
|
setTarget(url) {
|
|
118
118
|
const strUrl = String(url), root = index_1.default.parse(strUrl, this.getAttribute('include'), 9, this.getAttribute('config')), { length, firstChild: freeExtLink } = root;
|
|
119
|
-
if (length
|
|
120
|
-
|
|
119
|
+
if (length !== 1 || freeExtLink.type !== 'free-ext-link') {
|
|
120
|
+
throw new SyntaxError(`非法的自由外链目标:${strUrl}`);
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
this.replaceChildren(...freeExtLink.childNodes);
|
|
123
123
|
}
|
|
124
124
|
/** 是否是模板或魔术字参数 */
|
|
125
125
|
isParamValue() {
|
package/dist/src/parameter.js
CHANGED
|
@@ -159,12 +159,12 @@ class ParameterToken extends (0, fixed_1.fixed)(_1.Token) {
|
|
|
159
159
|
throw new SyntaxError(`非法的模板参数:${(0, string_1.noWrap)(value)}`);
|
|
160
160
|
}
|
|
161
161
|
const { lastChild: parameter, name } = transclude, targetName = templateLike ? 'T' : 'lc';
|
|
162
|
-
if (name
|
|
163
|
-
|
|
164
|
-
parameter.destroy();
|
|
165
|
-
this.lastChild.safeReplaceWith(lastChild);
|
|
162
|
+
if (name !== targetName || transclude.length !== 2 || parameter.anon !== this.anon || parameter.name !== '1') {
|
|
163
|
+
throw new SyntaxError(`非法的模板参数:${(0, string_1.noWrap)(value)}`);
|
|
166
164
|
}
|
|
167
|
-
|
|
165
|
+
const { lastChild } = parameter;
|
|
166
|
+
parameter.destroy();
|
|
167
|
+
this.lastChild.safeReplaceWith(lastChild);
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
170
|
* 修改参数名
|
package/dist/src/transclude.js
CHANGED
|
@@ -527,10 +527,10 @@ class TranscludeToken extends _1.Token {
|
|
|
527
527
|
throw new SyntaxError(`非法的命名参数:${key}=${(0, string_1.noWrap)(value)}`);
|
|
528
528
|
}
|
|
529
529
|
const { name, lastChild: parameter } = template;
|
|
530
|
-
if (name
|
|
531
|
-
|
|
530
|
+
if (name !== 'T' || parameter.name !== key) {
|
|
531
|
+
throw new SyntaxError(`非法的命名参数:${key}=${(0, string_1.noWrap)(value)}`);
|
|
532
532
|
}
|
|
533
|
-
|
|
533
|
+
this.insertAt(parameter);
|
|
534
534
|
}
|
|
535
535
|
/**
|
|
536
536
|
* 将匿名参数改写为命名参数
|
|
@@ -555,10 +555,10 @@ class TranscludeToken extends _1.Token {
|
|
|
555
555
|
throw new Error(`${this.constructor.name}.replaceTemplate 方法仅用于更换模板!`);
|
|
556
556
|
}
|
|
557
557
|
const root = index_1.default.parse(`{{${title}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: template } = root;
|
|
558
|
-
if (length
|
|
559
|
-
|
|
558
|
+
if (length !== 1 || template.type !== 'template' || template.length !== 1) {
|
|
559
|
+
throw new SyntaxError(`非法的模板名称:${title}`);
|
|
560
560
|
}
|
|
561
|
-
|
|
561
|
+
this.firstChild.replaceChildren(...template.firstChild.childNodes);
|
|
562
562
|
}
|
|
563
563
|
/**
|
|
564
564
|
* 替换模块名
|