wikiparser-node 1.41.0 → 1.43.0
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/README.md +43 -18
- package/bundle/bundle-es8.min.js +27 -27
- package/bundle/bundle-lsp.min.js +28 -28
- package/bundle/bundle.min.js +19 -19
- package/dist/addon/attribute.js +5 -7
- package/dist/addon/link.js +3 -2
- package/dist/addon/transclude.js +17 -29
- package/dist/bin/config.js +1 -1
- package/dist/extensions/typings.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/lib/document.js +5 -5
- package/dist/lib/element.d.ts +3 -8
- package/dist/lib/element.js +2 -26
- package/dist/lib/lsp.d.ts +2 -0
- package/dist/lib/lsp.js +8 -20
- package/dist/lib/node.d.ts +2 -0
- package/dist/lib/node.js +0 -7
- package/dist/lib/range.d.ts +0 -7
- package/dist/lib/range.js +5 -14
- package/dist/lib/ranges.js +2 -2
- package/dist/lib/text.js +3 -5
- package/dist/map.d.ts +66 -0
- package/dist/map.js +2 -0
- package/dist/mixin/attributesParent.d.ts +4 -3
- package/dist/mixin/elementLike.d.ts +13 -0
- package/dist/mixin/elementLike.js +66 -53
- package/dist/parser/selector.js +3 -3
- package/dist/render/expand.js +4 -2
- package/dist/render/extension.js +139 -8
- package/dist/render/html.js +72 -3
- package/dist/render/magicWords.js +24 -131
- package/dist/src/arg.js +1 -2
- package/dist/src/atom.js +1 -1
- package/dist/src/attribute.d.ts +2 -2
- package/dist/src/attribute.js +17 -13
- package/dist/src/attributes.d.ts +3 -3
- package/dist/src/attributes.js +30 -14
- package/dist/src/converterRule.js +3 -5
- package/dist/src/extLink.js +5 -4
- package/dist/src/heading.js +12 -5
- package/dist/src/imageParameter.js +1 -2
- package/dist/src/index.js +4 -5
- package/dist/src/link/base.js +3 -5
- package/dist/src/link/file.js +7 -8
- package/dist/src/link/galleryImage.js +1 -3
- package/dist/src/magicLink.js +7 -7
- package/dist/src/multiLine/gallery.js +2 -3
- package/dist/src/nowiki/doubleUnderscore.d.ts +1 -0
- package/dist/src/nowiki/doubleUnderscore.js +4 -1
- package/dist/src/nowiki/quote.js +1 -3
- package/dist/src/onlyinclude.js +1 -2
- package/dist/src/parameter.js +6 -4
- package/dist/src/table/index.js +1 -2
- package/dist/src/table/td.d.ts +2 -2
- package/dist/src/table/td.js +5 -7
- package/dist/src/tag/html.js +29 -12
- package/dist/src/tagPair/ext.js +4 -1
- package/dist/src/tagPair/translate.d.ts +1 -1
- package/dist/src/tagPair/translate.js +1 -1
- package/dist/src/transclude.js +4 -2
- package/dist/util/debug.js +5 -7
- package/dist/util/html.js +3 -11
- package/extensions/dist/base.js +1 -1
- package/package.json +57 -21
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.expandMagicWord =
|
|
6
|
+
exports.expandMagicWord = void 0;
|
|
7
7
|
/* eslint-disable jsdoc/require-jsdoc */
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const string_1 = require("../util/string");
|
|
@@ -11,132 +11,6 @@ const constants_1 = require("../util/constants");
|
|
|
11
11
|
const html_1 = require("../util/html");
|
|
12
12
|
const index_1 = __importDefault(require("../index"));
|
|
13
13
|
const index_2 = require("../src/index");
|
|
14
|
-
const magicWords = [
|
|
15
|
-
'currentmonth',
|
|
16
|
-
'currentmonth1',
|
|
17
|
-
'currentmonthname',
|
|
18
|
-
'currentmonthnamegen',
|
|
19
|
-
'currentmonthabbrev',
|
|
20
|
-
'currentday',
|
|
21
|
-
'currentday2',
|
|
22
|
-
'currentdayname',
|
|
23
|
-
'currentyear',
|
|
24
|
-
'currenttime',
|
|
25
|
-
'currenthour',
|
|
26
|
-
'currentweek',
|
|
27
|
-
'currentdow',
|
|
28
|
-
'currenttimestamp',
|
|
29
|
-
'localmonth',
|
|
30
|
-
'localmonth1',
|
|
31
|
-
'localmonthname',
|
|
32
|
-
'localmonthnamegen',
|
|
33
|
-
'localmonthabbrev',
|
|
34
|
-
'localday',
|
|
35
|
-
'localday2',
|
|
36
|
-
'localdayname',
|
|
37
|
-
'localyear',
|
|
38
|
-
'localtime',
|
|
39
|
-
'localhour',
|
|
40
|
-
'localweek',
|
|
41
|
-
'localdow',
|
|
42
|
-
'localtimestamp',
|
|
43
|
-
'articlepath',
|
|
44
|
-
'server',
|
|
45
|
-
'servername',
|
|
46
|
-
'directionmark',
|
|
47
|
-
'contentlanguage',
|
|
48
|
-
'pagelanguage',
|
|
49
|
-
'userlanguage',
|
|
50
|
-
'revisionsize',
|
|
51
|
-
'numberofarticles',
|
|
52
|
-
'numberoffiles',
|
|
53
|
-
'numberofusers',
|
|
54
|
-
'numberofactiveusers',
|
|
55
|
-
'numberofpages',
|
|
56
|
-
'numberofadmins',
|
|
57
|
-
'numberofedits',
|
|
58
|
-
'numberingroup',
|
|
59
|
-
'pagesincategory',
|
|
60
|
-
'pagesize',
|
|
61
|
-
'ns',
|
|
62
|
-
'nse',
|
|
63
|
-
'urlencode',
|
|
64
|
-
'lcfirst',
|
|
65
|
-
'ucfirst',
|
|
66
|
-
'lc',
|
|
67
|
-
'uc',
|
|
68
|
-
'localurl',
|
|
69
|
-
'localurle',
|
|
70
|
-
'fullurl',
|
|
71
|
-
'fullurle',
|
|
72
|
-
'canonicalurl',
|
|
73
|
-
'canonicalurle',
|
|
74
|
-
'gender',
|
|
75
|
-
'formal',
|
|
76
|
-
'displaytitle',
|
|
77
|
-
'defaultsort',
|
|
78
|
-
'revisionuser',
|
|
79
|
-
'translation',
|
|
80
|
-
'revisionid',
|
|
81
|
-
'revisionday',
|
|
82
|
-
'revisionday2',
|
|
83
|
-
'revisionmonth',
|
|
84
|
-
'revisionmonth1',
|
|
85
|
-
'revisionyear',
|
|
86
|
-
'revisiontimestamp',
|
|
87
|
-
'namespace',
|
|
88
|
-
'namespacee',
|
|
89
|
-
'namespacenumber',
|
|
90
|
-
'talkspace',
|
|
91
|
-
'talkspacee',
|
|
92
|
-
'subjectspace',
|
|
93
|
-
'subjectspacee',
|
|
94
|
-
'pagename',
|
|
95
|
-
'pagenamee',
|
|
96
|
-
'fullpagename',
|
|
97
|
-
'fullpagenamee',
|
|
98
|
-
'subpagename',
|
|
99
|
-
'subpagenamee',
|
|
100
|
-
'rootpagename',
|
|
101
|
-
'rootpagenamee',
|
|
102
|
-
'basepagename',
|
|
103
|
-
'basepagenamee',
|
|
104
|
-
'talkpagename',
|
|
105
|
-
'talkpagenamee',
|
|
106
|
-
'subjectpagename',
|
|
107
|
-
'subjectpagenamee',
|
|
108
|
-
'language',
|
|
109
|
-
'dir',
|
|
110
|
-
'padleft',
|
|
111
|
-
'padright',
|
|
112
|
-
'anchorencode',
|
|
113
|
-
'special',
|
|
114
|
-
'speciale',
|
|
115
|
-
'pageid',
|
|
116
|
-
'contentmodel',
|
|
117
|
-
'tag',
|
|
118
|
-
'rel2abs',
|
|
119
|
-
'titleparts',
|
|
120
|
-
'len',
|
|
121
|
-
'pos',
|
|
122
|
-
'rpos',
|
|
123
|
-
'sub',
|
|
124
|
-
'count',
|
|
125
|
-
'replace',
|
|
126
|
-
'explode',
|
|
127
|
-
'urldecode',
|
|
128
|
-
'if',
|
|
129
|
-
'ifeq',
|
|
130
|
-
'ifexist',
|
|
131
|
-
'iferror',
|
|
132
|
-
'switch',
|
|
133
|
-
'plural',
|
|
134
|
-
'expr',
|
|
135
|
-
'!',
|
|
136
|
-
'=',
|
|
137
|
-
'filepath',
|
|
138
|
-
];
|
|
139
|
-
exports.expandedMagicWords = new Set(magicWords);
|
|
140
14
|
function urlFunction(config, args, local) {
|
|
141
15
|
const [value, query] = args, fallback = (local ? '' : []);
|
|
142
16
|
if (value.includes('\0')) {
|
|
@@ -297,7 +171,15 @@ const parseUrl = ({ server = '', articlePath = '' }) => {
|
|
|
297
171
|
}, isError = (s) => /<(?:strong|span|p|div)\s+(?:[^\s>]+\s+)*?class="\s*(?:[^"\s>]+\s+)*?error(?:\s[^">]*)?"/u.test(s), splitArg = (arg) => {
|
|
298
172
|
const i = arg.indexOf('=');
|
|
299
173
|
return i !== -1 && [arg.slice(0, i).trim(), arg.slice(i + 1).trim()];
|
|
300
|
-
}, isKnown = (s) => !/\0\d+[tm]\x7F/u.test(s)
|
|
174
|
+
}, isKnown = (s) => !/\0\d+[tm]\x7F/u.test(s), expr = (s) => {
|
|
175
|
+
try {
|
|
176
|
+
const { evaluateExpr } = require('mediawiki-expr');
|
|
177
|
+
return evaluateExpr(s);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
throw new Error('Magic words "#expr" and "#ifexpr" require NPM package mediawiki-expr');
|
|
181
|
+
}
|
|
182
|
+
};
|
|
301
183
|
/**
|
|
302
184
|
* 展开魔术字
|
|
303
185
|
* @param name 魔术字名称
|
|
@@ -682,11 +564,12 @@ const expandMagicWord = (name, args, page = '', config = index_1.default.getConf
|
|
|
682
564
|
? ''
|
|
683
565
|
: isKnown(arg0) && isKnown(args[1]) && (args[cmp(arg0, args[1], true) ? 2 : 3] ?? '');
|
|
684
566
|
case 'if':
|
|
685
|
-
case 'iferror':
|
|
686
567
|
if (args.length === 1) {
|
|
687
568
|
return '';
|
|
688
569
|
}
|
|
689
|
-
return
|
|
570
|
+
return strip((0, string_1.decodeHtml)(arg0)) ? args[1] : isKnown(arg0) && (args[2] ?? '');
|
|
571
|
+
case 'iferror':
|
|
572
|
+
return isError((0, string_1.decodeHtml)(arg0)) ? args[1] ?? '' : isKnown(arg0) && (args[2] ?? arg0);
|
|
690
573
|
case 'ifexist': {
|
|
691
574
|
if (args.length === 1) {
|
|
692
575
|
return '';
|
|
@@ -751,7 +634,17 @@ const expandMagicWord = (name, args, page = '', config = index_1.default.getConf
|
|
|
751
634
|
return args[n === 1 || n === -1 ? 1 : 2] ?? '';
|
|
752
635
|
}
|
|
753
636
|
case 'expr':
|
|
754
|
-
return
|
|
637
|
+
return arg0 && isKnown(arg0) && String(expr(arg0));
|
|
638
|
+
case 'ifexpr': {
|
|
639
|
+
if (!isKnown(arg0)) {
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
const evaluated = arg0 && expr(arg0);
|
|
643
|
+
if (evaluated && typeof evaluated === 'string') {
|
|
644
|
+
return evaluated;
|
|
645
|
+
}
|
|
646
|
+
return evaluated ? args[1] ?? '' : args[2] ?? '';
|
|
647
|
+
}
|
|
755
648
|
case '!':
|
|
756
649
|
return '|';
|
|
757
650
|
case '=':
|
package/dist/src/arg.js
CHANGED
|
@@ -265,8 +265,7 @@ let ArgToken = (() => {
|
|
|
265
265
|
* @param name new argument name / 新参数名
|
|
266
266
|
*/
|
|
267
267
|
setName(name) {
|
|
268
|
-
|
|
269
|
-
this.firstChild.safeReplaceChildren(childNodes);
|
|
268
|
+
this.firstChild.safeReplaceChildren(index_1.default.parseWithRef(name, this, 2).childNodes);
|
|
270
269
|
}
|
|
271
270
|
/**
|
|
272
271
|
* Set the default value
|
package/dist/src/atom.js
CHANGED
|
@@ -79,7 +79,7 @@ let AtomToken = (() => {
|
|
|
79
79
|
/* NOT FOR BROWSER */
|
|
80
80
|
/* c8 ignore next 3 */
|
|
81
81
|
if (!atomTypes.includes(value)) {
|
|
82
|
-
throw new RangeError(
|
|
82
|
+
throw new RangeError(`${JSON.stringify(value)} is not a valid type for AtomToken!`);
|
|
83
83
|
}
|
|
84
84
|
/* NOT FOR BROWSER END */
|
|
85
85
|
this.#type = value;
|
package/dist/src/attribute.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare abstract class AttributeToken extends Token {
|
|
|
39
39
|
get balanced(): boolean;
|
|
40
40
|
set balanced(value: boolean);
|
|
41
41
|
/** attribute value / 属性值 */
|
|
42
|
-
get value(): string
|
|
42
|
+
get value(): string;
|
|
43
43
|
set value(value: string | true);
|
|
44
44
|
/**
|
|
45
45
|
* @param type 标签类型
|
|
@@ -55,7 +55,7 @@ export declare abstract class AttributeToken extends Token {
|
|
|
55
55
|
*
|
|
56
56
|
* 获取属性值
|
|
57
57
|
*/
|
|
58
|
-
getValue(): string
|
|
58
|
+
getValue(): string;
|
|
59
59
|
cloneNode(): this;
|
|
60
60
|
/**
|
|
61
61
|
* Close the quote
|
package/dist/src/attribute.js
CHANGED
|
@@ -231,7 +231,7 @@ let AttributeToken = (() => {
|
|
|
231
231
|
&& !parentNode?.hasAttr('itemscope')) {
|
|
232
232
|
/* PRINT ONLY */
|
|
233
233
|
if (start === undefined) {
|
|
234
|
-
return
|
|
234
|
+
return 2;
|
|
235
235
|
}
|
|
236
236
|
/* PRINT ONLY END */
|
|
237
237
|
LINT: {
|
|
@@ -245,10 +245,10 @@ let AttributeToken = (() => {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
else if (name === 'style' &&
|
|
248
|
+
else if (name === 'style' && insecureStyle.test(value)) {
|
|
249
249
|
/* PRINT ONLY */
|
|
250
250
|
if (start === undefined) {
|
|
251
|
-
return
|
|
251
|
+
return 1;
|
|
252
252
|
}
|
|
253
253
|
/* PRINT ONLY END */
|
|
254
254
|
LINT: {
|
|
@@ -257,10 +257,10 @@ let AttributeToken = (() => {
|
|
|
257
257
|
return s && (0, lint_1.generateForChild)(lastChild, rect, rule, 'insecure-style', s);
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
else if (name === 'tabindex' &&
|
|
260
|
+
else if (name === 'tabindex' && value !== '0') {
|
|
261
261
|
/* PRINT ONLY */
|
|
262
262
|
if (start === undefined) {
|
|
263
|
-
return
|
|
263
|
+
return 2;
|
|
264
264
|
}
|
|
265
265
|
/* PRINT ONLY END */
|
|
266
266
|
LINT: {
|
|
@@ -277,14 +277,14 @@ let AttributeToken = (() => {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
else if (
|
|
280
|
+
else if ((/^xmlns:[\w:.-]+$/u.test(name) || urlAttrs.has(name)) && evil.test(value)
|
|
281
281
|
|| simple
|
|
282
282
|
&& (name === 'href' || type === 'ext-attr' && tag === 'img' && name === 'src')
|
|
283
283
|
&& !new RegExp(String.raw `^(?:${this.getAttribute('config').protocol}|//)\S+$`, 'iu')
|
|
284
|
-
.test(value))
|
|
284
|
+
.test(value)) {
|
|
285
285
|
/* PRINT ONLY */
|
|
286
286
|
if (start === undefined) {
|
|
287
|
-
return
|
|
287
|
+
return 2;
|
|
288
288
|
}
|
|
289
289
|
/* PRINT ONLY END */
|
|
290
290
|
LINT: {
|
|
@@ -293,11 +293,11 @@ let AttributeToken = (() => {
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
else if (simple && type !== 'ext-attr') {
|
|
296
|
-
const data = (0, lint_1.provideValues)(tag, name), v =
|
|
296
|
+
const data = (0, lint_1.provideValues)(tag, name), v = value.toLowerCase();
|
|
297
297
|
if (data.length > 0 && data.every(n => n !== v)) {
|
|
298
298
|
/* PRINT ONLY */
|
|
299
299
|
if (start === undefined) {
|
|
300
|
-
return
|
|
300
|
+
return 2;
|
|
301
301
|
}
|
|
302
302
|
/* PRINT ONLY END */
|
|
303
303
|
LINT: {
|
|
@@ -363,7 +363,7 @@ let AttributeToken = (() => {
|
|
|
363
363
|
* 获取属性值
|
|
364
364
|
*/
|
|
365
365
|
getValue() {
|
|
366
|
-
return this.#equal ? this.lastChild.text().
|
|
366
|
+
return this.#equal ? this.lastChild.text().replace(/[\t\r\n ]+/gu, ' ').trim() : '';
|
|
367
367
|
}
|
|
368
368
|
/** @private */
|
|
369
369
|
escape() {
|
|
@@ -380,7 +380,7 @@ let AttributeToken = (() => {
|
|
|
380
380
|
return this.#quotes;
|
|
381
381
|
}
|
|
382
382
|
/* NOT FOR BROWSER END */
|
|
383
|
-
return key === 'invalid' ? this.#lint() : super.getAttribute(key);
|
|
383
|
+
return key === 'invalid' ? Boolean(this.#lint()) : super.getAttribute(key);
|
|
384
384
|
}
|
|
385
385
|
/** @private */
|
|
386
386
|
print() {
|
|
@@ -464,9 +464,13 @@ let AttributeToken = (() => {
|
|
|
464
464
|
/** @private */
|
|
465
465
|
toHtmlInternal() {
|
|
466
466
|
const { type, name, tag, lastChild } = this;
|
|
467
|
-
if (type === 'ext-attr' && sharable_1.extAttrs[tag]?.has(name)
|
|
467
|
+
if (type === 'ext-attr' && sharable_1.extAttrs[tag]?.has(name)) {
|
|
468
468
|
return '';
|
|
469
469
|
}
|
|
470
|
+
const linted = this.#lint();
|
|
471
|
+
if (linted) {
|
|
472
|
+
return linted === 1 ? 'style="/* insecure input */"' : '';
|
|
473
|
+
}
|
|
470
474
|
const value = lastChild.toHtmlInternal().trim();
|
|
471
475
|
if (name === 'id' && !value) {
|
|
472
476
|
return '';
|
package/dist/src/attributes.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare abstract class AttributesToken extends Token {
|
|
|
32
32
|
abstract get previousElementSibling(): SyntaxToken | undefined;
|
|
33
33
|
get type(): AttributesTypes;
|
|
34
34
|
/** all attributes / 全部属性 */
|
|
35
|
-
get attributes(): Record<string, string
|
|
35
|
+
get attributes(): Record<string, string>;
|
|
36
36
|
set attributes(attrs: Record<string, string | true>);
|
|
37
37
|
/** class attribute in string / 以字符串表示的class属性 */
|
|
38
38
|
get className(): string;
|
|
@@ -78,7 +78,7 @@ export declare abstract class AttributesToken extends Token {
|
|
|
78
78
|
* 获取指定属性
|
|
79
79
|
* @param key attribute name / 属性键
|
|
80
80
|
*/
|
|
81
|
-
getAttr(key: string): string |
|
|
81
|
+
getAttr(key: string): string | undefined;
|
|
82
82
|
/**
|
|
83
83
|
* Sanitize invalid attributes
|
|
84
84
|
*
|
|
@@ -115,7 +115,7 @@ export declare abstract class AttributesToken extends Token {
|
|
|
115
115
|
*
|
|
116
116
|
* 获取全部属性
|
|
117
117
|
*/
|
|
118
|
-
getAttrs(): Record<string, string
|
|
118
|
+
getAttrs(): Record<string, string>;
|
|
119
119
|
/**
|
|
120
120
|
* Remove an attribute
|
|
121
121
|
*
|
package/dist/src/attributes.js
CHANGED
|
@@ -82,6 +82,17 @@ const required = new Map([
|
|
|
82
82
|
['section', [['begin', 'end']]],
|
|
83
83
|
['templatestyles', ['src']],
|
|
84
84
|
]);
|
|
85
|
+
/* NOT FOR BROWSER */
|
|
86
|
+
/**
|
|
87
|
+
* 处理不显示的`<ref>`
|
|
88
|
+
* @param token 不显示的节点
|
|
89
|
+
*/
|
|
90
|
+
const renderRefs = (token) => {
|
|
91
|
+
for (const ref of token.querySelectorAll('ext#ref')) {
|
|
92
|
+
ref.toHtmlInternal();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/* NOT FOR BROWSER END */
|
|
85
96
|
/**
|
|
86
97
|
* attributes of extension and HTML tags
|
|
87
98
|
*
|
|
@@ -120,8 +131,7 @@ let AttributesToken = (() => {
|
|
|
120
131
|
}
|
|
121
132
|
/** class attribute in string / 以字符串表示的class属性 */
|
|
122
133
|
get className() {
|
|
123
|
-
|
|
124
|
-
return typeof attr === 'string' ? attr : '';
|
|
134
|
+
return this.getAttr('class') || '';
|
|
125
135
|
}
|
|
126
136
|
set className(className) {
|
|
127
137
|
this.setAttr('class', className || false);
|
|
@@ -151,8 +161,7 @@ let AttributesToken = (() => {
|
|
|
151
161
|
}
|
|
152
162
|
/** id attribute / id属性 */
|
|
153
163
|
get id() {
|
|
154
|
-
|
|
155
|
-
return typeof attr === 'string' ? attr : '';
|
|
164
|
+
return this.getAttr('id') || '';
|
|
156
165
|
}
|
|
157
166
|
set id(id) {
|
|
158
167
|
this.setAttr('id', id || false);
|
|
@@ -302,11 +311,8 @@ let AttributesToken = (() => {
|
|
|
302
311
|
const severity = lintConfig.getSeverity(rules[1], tag);
|
|
303
312
|
if (severity) {
|
|
304
313
|
for (const key of required.get(tag)) {
|
|
305
|
-
const keys = typeof key === 'string' ? [key] : key
|
|
306
|
-
|
|
307
|
-
return value === true || !value;
|
|
308
|
-
});
|
|
309
|
-
if (missing) {
|
|
314
|
+
const keys = typeof key === 'string' ? [key] : key;
|
|
315
|
+
if (!keys.some(k => this.getAttr(k))) {
|
|
310
316
|
errors.push((0, lint_1.generateForSelf)(this, rect, rules[1], index_1.default.msg('required-attribute', keys.join('/')), severity));
|
|
311
317
|
}
|
|
312
318
|
}
|
|
@@ -315,10 +321,7 @@ let AttributesToken = (() => {
|
|
|
315
321
|
const severity = lintConfig.getSeverity(rules[2], 'attribute');
|
|
316
322
|
if (severity && duplicated.size > 0) {
|
|
317
323
|
for (const key of duplicated) {
|
|
318
|
-
const pairs = attrs.get(key).map(attr =>
|
|
319
|
-
const value = attr.getValue();
|
|
320
|
-
return [attr, value === true ? '' : value];
|
|
321
|
-
});
|
|
324
|
+
const pairs = attrs.get(key).map(attr => [attr, attr.getValue()]);
|
|
322
325
|
Array.prototype.push.apply(errors, pairs.map(([attr, value], i) => {
|
|
323
326
|
const e = (0, lint_1.generateForChild)(attr, rect, rules[2], index_1.default.msg('duplicate-attribute', key), severity);
|
|
324
327
|
if (computeEditInfo || fix) {
|
|
@@ -488,7 +491,20 @@ let AttributesToken = (() => {
|
|
|
488
491
|
}
|
|
489
492
|
/** @private */
|
|
490
493
|
toHtmlInternal() {
|
|
491
|
-
const map = new Map(
|
|
494
|
+
const map = new Map();
|
|
495
|
+
for (const child of this.childNodes) {
|
|
496
|
+
if (child instanceof attribute_1.AttributeToken) {
|
|
497
|
+
const last = map.get(child.name);
|
|
498
|
+
if (last) {
|
|
499
|
+
renderRefs(last);
|
|
500
|
+
}
|
|
501
|
+
map.set(child.name, child);
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
renderRefs(child);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
const output = map.size === 0 ? '' : (0, html_1.html)([...map.values()], ' ', { removeBlank: true });
|
|
492
508
|
return output && ` ${output}`;
|
|
493
509
|
}
|
|
494
510
|
/* c8 ignore start */
|
|
@@ -259,8 +259,7 @@ let ConverterRuleToken = (() => {
|
|
|
259
259
|
* @param to target of language conversion / 转换目标
|
|
260
260
|
*/
|
|
261
261
|
setTo(to) {
|
|
262
|
-
|
|
263
|
-
this.lastChild.safeReplaceChildren(childNodes);
|
|
262
|
+
this.lastChild.safeReplaceChildren(index_1.default.parseWithRef(to, this).childNodes);
|
|
264
263
|
}
|
|
265
264
|
/**
|
|
266
265
|
* Set the language variant
|
|
@@ -288,11 +287,10 @@ let ConverterRuleToken = (() => {
|
|
|
288
287
|
if (!variant) {
|
|
289
288
|
throw new Error('Please specify the language variant first!');
|
|
290
289
|
}
|
|
291
|
-
|
|
292
|
-
if (!unidirectional) {
|
|
290
|
+
else if (!unidirectional) {
|
|
293
291
|
super.insertAt(debug_1.Shadow.run(() => getRuleFromTo(undefined, 'from', this.getAttribute('config'))), 0);
|
|
294
292
|
}
|
|
295
|
-
this.firstChild.safeReplaceChildren(childNodes);
|
|
293
|
+
this.firstChild.safeReplaceChildren(index_1.default.parseWithRef(from, this).childNodes);
|
|
296
294
|
}
|
|
297
295
|
/**
|
|
298
296
|
* Make the language conversion unidirectional
|
package/dist/src/extLink.js
CHANGED
|
@@ -217,26 +217,27 @@ let ExtLinkToken = (() => {
|
|
|
217
217
|
/** @private */
|
|
218
218
|
toHtmlInternal(opt) {
|
|
219
219
|
const { length, lastChild } = this;
|
|
220
|
-
let innerText, href;
|
|
220
|
+
let innerText, linkType, href;
|
|
221
221
|
if (length > 1) {
|
|
222
222
|
lastChild.normalize();
|
|
223
223
|
const { childNodes } = lastChild, i = childNodes.findIndex(child => child.is('link')
|
|
224
|
-
|| child.is('file')
|
|
225
|
-
&& child.getValue('link')?.trim() !== '');
|
|
224
|
+
|| child.is('file') && child.getValue('link')?.trim() !== '');
|
|
226
225
|
if (i !== -1) {
|
|
227
226
|
const after = childNodes.slice(i);
|
|
228
227
|
this.insertAdjacent(after, 1);
|
|
229
228
|
}
|
|
230
229
|
innerText = lastChild.toHtmlInternal(opt);
|
|
230
|
+
linkType = 'text';
|
|
231
231
|
}
|
|
232
232
|
else {
|
|
233
233
|
({ innerText } = this);
|
|
234
|
+
linkType = 'autonumber';
|
|
234
235
|
}
|
|
235
236
|
try {
|
|
236
237
|
({ href } = this.getUrl());
|
|
237
238
|
}
|
|
238
239
|
catch { }
|
|
239
|
-
return `<a rel="nofollow" class="external"${href === undefined ? '' : ` href="${href}"`}>${innerText}</a>`;
|
|
240
|
+
return `<a rel="nofollow" class="external ${linkType}"${href === undefined ? '' : ` href="${href}"`}>${innerText}</a>`;
|
|
240
241
|
}
|
|
241
242
|
/**
|
|
242
243
|
* Get the URL
|
package/dist/src/heading.js
CHANGED
|
@@ -67,12 +67,15 @@ let HeadingToken = (() => {
|
|
|
67
67
|
let _classThis;
|
|
68
68
|
let _classSuper = index_2.Token;
|
|
69
69
|
let _instanceExtraInitializers = [];
|
|
70
|
+
let _getRenderedId_decorators;
|
|
70
71
|
let _toHtmlInternal_decorators;
|
|
71
72
|
var HeadingToken = class extends _classSuper {
|
|
72
73
|
static { _classThis = this; }
|
|
73
74
|
static {
|
|
74
75
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
76
|
+
_getRenderedId_decorators = [(0, cached_1.cached)()];
|
|
75
77
|
_toHtmlInternal_decorators = [(0, cached_1.cached)()];
|
|
78
|
+
__esDecorate(this, null, _getRenderedId_decorators, { kind: "method", name: "getRenderedId", static: false, private: false, access: { has: obj => "getRenderedId" in obj, get: obj => obj.getRenderedId }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
76
79
|
__esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
77
80
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
78
81
|
HeadingToken = _classThis = _classDescriptor.value;
|
|
@@ -101,8 +104,7 @@ let HeadingToken = (() => {
|
|
|
101
104
|
if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
|
|
102
105
|
throw new Error('Please use HeadingToken.setLevel method to change the level of the heading!');
|
|
103
106
|
}
|
|
104
|
-
|
|
105
|
-
this.firstChild.safeReplaceChildren(childNodes);
|
|
107
|
+
this.firstChild.safeReplaceChildren(index_1.default.parseWithRef(text, this).childNodes);
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
110
|
* id attribute
|
|
@@ -296,9 +298,9 @@ let HeadingToken = (() => {
|
|
|
296
298
|
return (0, html_1.getId)(this.firstChild[expand ? 'expand' : 'cloneNode']());
|
|
297
299
|
}
|
|
298
300
|
/** @private */
|
|
299
|
-
|
|
301
|
+
getRenderedId() {
|
|
300
302
|
let id = this.#getId();
|
|
301
|
-
const
|
|
303
|
+
const lcId = id.toLowerCase(), headings = constants_1.states.get(this.getRootNode())?.headings;
|
|
302
304
|
if (headings?.has(lcId)) {
|
|
303
305
|
let i = 2;
|
|
304
306
|
for (; headings.has(`${lcId}_${i}`); i++) {
|
|
@@ -310,7 +312,12 @@ let HeadingToken = (() => {
|
|
|
310
312
|
else {
|
|
311
313
|
headings?.add(lcId);
|
|
312
314
|
}
|
|
313
|
-
return
|
|
315
|
+
return (0, string_1.sanitizeId)(id);
|
|
316
|
+
}
|
|
317
|
+
/** @private */
|
|
318
|
+
toHtmlInternal() {
|
|
319
|
+
const { level, firstChild } = this;
|
|
320
|
+
return `${this.tocData ?? ''}<div class="mw-heading mw-heading${level}"><h${level} id="${this.getRenderedId()}">${firstChild.toHtmlInternal().trim()}</h${level}></div>`;
|
|
314
321
|
}
|
|
315
322
|
/**
|
|
316
323
|
* Get the section led by this heading
|
|
@@ -421,8 +421,7 @@ let ImageParameterToken = (() => {
|
|
|
421
421
|
this.typeError('setValue', type);
|
|
422
422
|
}
|
|
423
423
|
else if (value !== true) {
|
|
424
|
-
|
|
425
|
-
this.safeReplaceChildren(childNodes);
|
|
424
|
+
this.safeReplaceChildren(index_1.default.parseWithRef(value, this, name === 'caption' ? undefined : 5).childNodes);
|
|
426
425
|
}
|
|
427
426
|
}
|
|
428
427
|
/**
|
package/dist/src/index.js
CHANGED
|
@@ -183,7 +183,7 @@ let Token = (() => {
|
|
|
183
183
|
];
|
|
184
184
|
/* c8 ignore next 3 */
|
|
185
185
|
if (!plainTypes.includes(value)) {
|
|
186
|
-
throw new RangeError(
|
|
186
|
+
throw new RangeError(`${JSON.stringify(value)} is not a valid type for ${this.constructor.name}!`);
|
|
187
187
|
}
|
|
188
188
|
/* NOT FOR BROWSER END */
|
|
189
189
|
this.#type = value;
|
|
@@ -532,9 +532,8 @@ let Token = (() => {
|
|
|
532
532
|
}
|
|
533
533
|
/** @private */
|
|
534
534
|
inTableAttrs() {
|
|
535
|
-
return this.isInside('table-attrs')
|
|
536
|
-
? 2
|
|
537
|
-
: 1);
|
|
535
|
+
return this.isInside('table-attrs')
|
|
536
|
+
&& (this.closest('table-attrs,arg,parameter')?.is('table-attrs') ? 2 : 1);
|
|
538
537
|
}
|
|
539
538
|
/** @private */
|
|
540
539
|
inHtmlAttrs() {
|
|
@@ -555,7 +554,7 @@ let Token = (() => {
|
|
|
555
554
|
}
|
|
556
555
|
else {
|
|
557
556
|
const value = cat.getValue();
|
|
558
|
-
if (value
|
|
557
|
+
if (value) {
|
|
559
558
|
key = `#${value}`;
|
|
560
559
|
}
|
|
561
560
|
}
|
package/dist/src/link/base.js
CHANGED
|
@@ -108,7 +108,7 @@ let LinkBaseToken = (() => {
|
|
|
108
108
|
const { prefix, main, fragment } = this.#title, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
|
|
109
109
|
/* c8 ignore next 3 */
|
|
110
110
|
if (interwiki && !this.isInterwiki(link)) {
|
|
111
|
-
throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
|
|
111
|
+
throw new RangeError(`${JSON.stringify(interwiki)} is not a valid interwiki prefix!`);
|
|
112
112
|
}
|
|
113
113
|
this.setTarget(link);
|
|
114
114
|
}
|
|
@@ -326,9 +326,7 @@ let LinkBaseToken = (() => {
|
|
|
326
326
|
}
|
|
327
327
|
/** @private */
|
|
328
328
|
toHtmlInternal(opt) {
|
|
329
|
-
if (this.is('link')
|
|
330
|
-
|| this.is('redirect-target')
|
|
331
|
-
|| this.is('category')) {
|
|
329
|
+
if (this.is('link') || this.is('redirect-target') || this.is('category')) {
|
|
332
330
|
const { link, length, lastChild, type, pageName } = this;
|
|
333
331
|
let attr;
|
|
334
332
|
if (type === 'link' && link.title === pageName && !link.fragment) {
|
|
@@ -336,7 +334,7 @@ let LinkBaseToken = (() => {
|
|
|
336
334
|
}
|
|
337
335
|
else {
|
|
338
336
|
const title = link.getTitleAttr();
|
|
339
|
-
attr = `${link.interwiki && 'class="extiw" '}href="${link.getUrl()}"${title && ` title="${title}"`}`;
|
|
337
|
+
attr = `${link.interwiki && 'class="extiw" '}href="${link.getUrl()}"${link.ns === -2 ? ' class="internal"' : ''}${title && ` title="${title}"`}`;
|
|
340
338
|
}
|
|
341
339
|
return `<a ${attr}>${type === 'link' && length > 1
|
|
342
340
|
? lastChild.toHtmlInternal({
|