wikiparser-node 1.35.0 → 1.35.1
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 +29 -28
- package/bundle/bundle-es8.min.js +29 -29
- package/bundle/bundle-lsp.min.js +34 -34
- package/bundle/bundle.min.js +24 -24
- package/config/default.json +3 -0
- package/config/enwiki.json +3 -0
- package/config/jawiki.json +3 -0
- package/config/minimum.json +1 -0
- package/config/zhwiki.json +3 -0
- package/coverage/badge.svg +1 -1
- package/data/signatures.json +13 -0
- package/dist/addon/attribute.js +13 -12
- package/dist/addon/link.js +3 -3
- package/dist/addon/token.js +4 -4
- package/dist/addon/transclude.js +8 -8
- package/dist/base.d.mts +3 -1
- package/dist/base.d.ts +3 -1
- package/dist/bin/config.js +3 -3
- package/dist/index.js +21 -13
- package/dist/lib/document.js +14 -12
- package/dist/lib/element.d.ts +2 -1
- package/dist/lib/element.js +17 -13
- package/dist/lib/lintConfig.js +7 -6
- package/dist/lib/lsp.js +10 -8
- package/dist/lib/node.js +8 -6
- package/dist/lib/range.js +17 -13
- package/dist/lib/ranges.js +25 -26
- package/dist/lib/text.js +14 -13
- package/dist/lib/title.js +7 -6
- package/dist/parser/braces.js +5 -7
- package/dist/parser/hrAndDoubleUnderscore.js +2 -2
- package/dist/parser/list.js +1 -1
- package/dist/parser/magicLinks.js +2 -1
- package/dist/parser/selector.js +15 -15
- package/dist/src/arg.js +4 -4
- package/dist/src/atom.js +1 -1
- package/dist/src/attribute.js +5 -4
- package/dist/src/attributes.js +10 -7
- package/dist/src/converter.js +4 -4
- package/dist/src/converterRule.js +2 -2
- package/dist/src/heading.js +2 -2
- package/dist/src/imageParameter.js +12 -3
- package/dist/src/index.js +15 -10
- package/dist/src/link/base.js +10 -7
- package/dist/src/link/category.js +3 -3
- package/dist/src/link/file.js +6 -5
- package/dist/src/link/index.js +5 -3
- package/dist/src/multiLine/gallery.js +2 -2
- package/dist/src/nowiki/comment.js +4 -3
- package/dist/src/nowiki/doubleUnderscore.js +1 -1
- package/dist/src/nowiki/listBase.js +2 -2
- package/dist/src/nowiki/noinclude.js +1 -1
- package/dist/src/nowiki/quote.js +3 -3
- package/dist/src/onlyinclude.js +1 -1
- package/dist/src/parameter.js +2 -2
- package/dist/src/table/index.js +9 -8
- package/dist/src/table/td.js +5 -5
- package/dist/src/table/trBase.js +4 -4
- package/dist/src/tag/html.js +9 -9
- package/dist/src/tag/index.js +6 -5
- package/dist/src/tag/tvar.js +4 -3
- package/dist/src/tagPair/index.js +6 -4
- package/dist/src/transclude.js +3 -3
- package/dist/util/debug.js +3 -2
- package/dist/util/diff.js +11 -6
- package/dist/util/selector.js +1 -1
- package/dist/util/string.js +2 -2
- package/extensions/dist/base.js +12 -4
- package/extensions/dist/codejar.js +1 -1
- package/package.json +27 -27
- package/logo.png +0 -0
package/config/default.json
CHANGED
|
@@ -496,6 +496,7 @@
|
|
|
496
496
|
"revisionuser",
|
|
497
497
|
"cascadingsources",
|
|
498
498
|
"namespace",
|
|
499
|
+
"isbn",
|
|
499
500
|
"int",
|
|
500
501
|
"special",
|
|
501
502
|
"speciale",
|
|
@@ -659,6 +660,7 @@
|
|
|
659
660
|
"contentmodel",
|
|
660
661
|
"dir",
|
|
661
662
|
"language",
|
|
663
|
+
"isbn",
|
|
662
664
|
"numberofwikis",
|
|
663
665
|
"pendingchangelevel",
|
|
664
666
|
"noexternallanglinks",
|
|
@@ -1331,6 +1333,7 @@
|
|
|
1331
1333
|
"#interwikilink": "interwikilink",
|
|
1332
1334
|
"#interlanguagelink": "interlanguagelink",
|
|
1333
1335
|
"#contentmodel": "contentmodel",
|
|
1336
|
+
"#isbn": "isbn",
|
|
1334
1337
|
"#timef": "timef",
|
|
1335
1338
|
"#timefl": "timefl",
|
|
1336
1339
|
"USERLANGUAGE": "userlanguage"
|
package/config/enwiki.json
CHANGED
|
@@ -243,6 +243,7 @@
|
|
|
243
243
|
"interwikilink",
|
|
244
244
|
"interlanguagelink",
|
|
245
245
|
"contentmodel",
|
|
246
|
+
"isbn",
|
|
246
247
|
"int",
|
|
247
248
|
"special",
|
|
248
249
|
"speciale",
|
|
@@ -367,6 +368,7 @@
|
|
|
367
368
|
"contentmodel",
|
|
368
369
|
"dir",
|
|
369
370
|
"language",
|
|
371
|
+
"isbn",
|
|
370
372
|
"numberofwikis",
|
|
371
373
|
"pendingchangelevel",
|
|
372
374
|
"noexternallanglinks",
|
|
@@ -502,6 +504,7 @@
|
|
|
502
504
|
"#interwikilink": "interwikilink",
|
|
503
505
|
"#interlanguagelink": "interlanguagelink",
|
|
504
506
|
"#contentmodel": "contentmodel",
|
|
507
|
+
"#isbn": "isbn",
|
|
505
508
|
"DISPLAYTITLE": "displaytitle",
|
|
506
509
|
"#timef": "timef",
|
|
507
510
|
"#timefl": "timefl",
|
package/config/jawiki.json
CHANGED
|
@@ -272,6 +272,7 @@
|
|
|
272
272
|
"interwikilink",
|
|
273
273
|
"interlanguagelink",
|
|
274
274
|
"contentmodel",
|
|
275
|
+
"isbn",
|
|
275
276
|
"int",
|
|
276
277
|
"special",
|
|
277
278
|
"speciale",
|
|
@@ -393,6 +394,7 @@
|
|
|
393
394
|
"contentmodel",
|
|
394
395
|
"dir",
|
|
395
396
|
"language",
|
|
397
|
+
"isbn",
|
|
396
398
|
"numberofwikis",
|
|
397
399
|
"noexternallanglinks",
|
|
398
400
|
"wbreponame"
|
|
@@ -682,6 +684,7 @@
|
|
|
682
684
|
"#interwikilink": "interwikilink",
|
|
683
685
|
"#interlanguagelink": "interlanguagelink",
|
|
684
686
|
"#contentmodel": "contentmodel",
|
|
687
|
+
"#isbn": "isbn",
|
|
685
688
|
"表示タイトル": "displaytitle",
|
|
686
689
|
"DISPLAYTITLE": "displaytitle",
|
|
687
690
|
"#timef": "timef",
|
package/config/minimum.json
CHANGED
package/config/zhwiki.json
CHANGED
|
@@ -384,6 +384,7 @@
|
|
|
384
384
|
"interwikilink",
|
|
385
385
|
"interlanguagelink",
|
|
386
386
|
"contentmodel",
|
|
387
|
+
"isbn",
|
|
387
388
|
"int",
|
|
388
389
|
"special",
|
|
389
390
|
"speciale",
|
|
@@ -506,6 +507,7 @@
|
|
|
506
507
|
"contentmodel",
|
|
507
508
|
"dir",
|
|
508
509
|
"language",
|
|
510
|
+
"isbn",
|
|
509
511
|
"numberofwikis",
|
|
510
512
|
"noexternallanglinks",
|
|
511
513
|
"wbreponame"
|
|
@@ -793,6 +795,7 @@
|
|
|
793
795
|
"#interwikilink": "interwikilink",
|
|
794
796
|
"#interlanguagelink": "interlanguagelink",
|
|
795
797
|
"#contentmodel": "contentmodel",
|
|
798
|
+
"#isbn": "isbn",
|
|
796
799
|
"DISPLAYTITLE": "displaytitle",
|
|
797
800
|
"显示标题": "displaytitle",
|
|
798
801
|
"顯示標題": "displaytitle",
|
package/coverage/badge.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="98" height="20" role="img" aria-label="Coverage:
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="98" height="20" role="img" aria-label="Coverage: 95%"><title>Coverage: 95%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="98" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="35" height="20" fill="#4c1"/><rect width="98" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="795" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">95%</text><text x="795" y="140" transform="scale(.1)" fill="#fff" textLength="250">95%</text></g></svg>
|
package/data/signatures.json
CHANGED
|
@@ -784,6 +784,19 @@
|
|
|
784
784
|
],
|
|
785
785
|
"description": "Creates an interlanguage link."
|
|
786
786
|
},
|
|
787
|
+
{
|
|
788
|
+
"aliases": [
|
|
789
|
+
"#isbn"
|
|
790
|
+
],
|
|
791
|
+
"signatures": [
|
|
792
|
+
[
|
|
793
|
+
{
|
|
794
|
+
"label": "ISBN number"
|
|
795
|
+
}
|
|
796
|
+
]
|
|
797
|
+
],
|
|
798
|
+
"description": "Create a link to [Special:Booksources](https://www.mediawiki.org/wiki/Special:Booksources) with the given ISBN number. This provides the same functionality as the deprecated [ISBN magic link](https://en.wikipedia.org/wiki/Help:Magic_links)."
|
|
799
|
+
},
|
|
787
800
|
{
|
|
788
801
|
"aliases": [
|
|
789
802
|
"#special"
|
package/dist/addon/attribute.js
CHANGED
|
@@ -24,11 +24,11 @@ attribute_1.AttributeToken.prototype.setValue =
|
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
const { type, lastChild } = this;
|
|
27
|
-
/*
|
|
27
|
+
/* c8 ignore next 6 */
|
|
28
28
|
if (type === 'ext-attr' && value.includes('>')) {
|
|
29
29
|
throw new RangeError('Attributes of an extension tag cannot contain ">"!');
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
if (value.includes('"') && value.includes(`'`)) {
|
|
32
32
|
throw new RangeError('Attribute values cannot contain single and double quotes simultaneously!');
|
|
33
33
|
}
|
|
34
34
|
const { childNodes } = index_1.default.parseWithRef(value, this, attribute_1.stages[type] + 1);
|
|
@@ -48,7 +48,7 @@ attribute_1.AttributeToken.prototype.rename =
|
|
|
48
48
|
/** @implements */
|
|
49
49
|
function (key) {
|
|
50
50
|
const { type, name, tag, firstChild } = this;
|
|
51
|
-
/*
|
|
51
|
+
/* c8 ignore next 3 */
|
|
52
52
|
if (name === 'title' || name === 'alt' && tag === 'img') {
|
|
53
53
|
throw new Error(`${name} attribute cannot be renamed!`);
|
|
54
54
|
}
|
|
@@ -59,19 +59,19 @@ attribute_1.AttributeToken.prototype.css =
|
|
|
59
59
|
/** @implements */
|
|
60
60
|
function (key, value) {
|
|
61
61
|
const { name, lastChild } = this;
|
|
62
|
-
/*
|
|
62
|
+
/* c8 ignore next 6 */
|
|
63
63
|
if (name !== 'style') {
|
|
64
64
|
throw new Error('Not a style attribute!');
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
if (lastChild.length > 1 || lastChild.length === 1 && lastChild.firstChild.type !== 'text') {
|
|
67
67
|
throw new Error('Complex style attribute!');
|
|
68
68
|
}
|
|
69
69
|
const cssLSP = (0, document_1.loadCssLSP)();
|
|
70
|
-
/*
|
|
70
|
+
/* c8 ignore next 3 */
|
|
71
71
|
if (!cssLSP) {
|
|
72
72
|
throw new Error('CSS language service is not available!');
|
|
73
73
|
}
|
|
74
|
-
const doc = new document_1.EmbeddedCSSDocument(this.getRootNode(), lastChild), styleSheet = doc.styleSheet,
|
|
74
|
+
const doc = new document_1.EmbeddedCSSDocument(this.getRootNode(), lastChild), styleSheet = doc.styleSheet, [{ declarations: { children } }] = styleSheet.children, declaration = children?.filter(({ property }) => property.getText() === key) ?? [];
|
|
75
75
|
if (value === undefined) {
|
|
76
76
|
return declaration.at(-1)?.value.getText();
|
|
77
77
|
}
|
|
@@ -95,12 +95,13 @@ attribute_1.AttributeToken.prototype.css =
|
|
|
95
95
|
return undefined;
|
|
96
96
|
}
|
|
97
97
|
const hasQuote = value.includes('"'), [quot] = this.getAttribute('quotes');
|
|
98
|
-
/*
|
|
98
|
+
/* c8 ignore start */
|
|
99
99
|
if (quot && value.includes(quot) || hasQuote && value.includes(`'`)) {
|
|
100
100
|
const quote = quot || '"';
|
|
101
101
|
throw new RangeError(`Please consider replacing \`${quote}\` with \`${quote === '"' ? `'` : '"'}\`!`);
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
/* c8 ignore stop */
|
|
104
|
+
if (declaration.length > 0) {
|
|
104
105
|
const { offset, length } = declaration.at(-1).value;
|
|
105
106
|
this.setValue(style.slice(doc.pre.length, offset) + value + style.slice(offset + length));
|
|
106
107
|
}
|
|
@@ -140,7 +141,7 @@ attributes_1.AttributesToken.prototype.setAttr =
|
|
|
140
141
|
return;
|
|
141
142
|
}
|
|
142
143
|
const { type, name } = this;
|
|
143
|
-
/*
|
|
144
|
+
/* c8 ignore next 3 */
|
|
144
145
|
if (type === 'ext-attrs' && typeof value === 'string' && value.includes('>')) {
|
|
145
146
|
throw new RangeError('Attributes of an extension tag cannot contain ">"!');
|
|
146
147
|
}
|
|
@@ -161,11 +162,11 @@ attributes_1.AttributesToken.prototype.toggleAttr =
|
|
|
161
162
|
function (key, force) {
|
|
162
163
|
key = (0, string_1.trimLc)(key);
|
|
163
164
|
const attr = this.getAttrToken(key);
|
|
164
|
-
/*
|
|
165
|
+
/* c8 ignore next 3 */
|
|
165
166
|
if (attr && attr.getValue() !== true) {
|
|
166
167
|
throw new RangeError(`${key} attribute is not Boolean!`);
|
|
167
168
|
}
|
|
168
|
-
|
|
169
|
+
if (attr) {
|
|
169
170
|
attr.setValue(force === true);
|
|
170
171
|
}
|
|
171
172
|
else if (force !== false) {
|
package/dist/addon/link.js
CHANGED
|
@@ -50,7 +50,7 @@ index_3.LinkToken.prototype.setLangLink =
|
|
|
50
50
|
/** @implements */
|
|
51
51
|
function (lang, link) {
|
|
52
52
|
link = link.trim();
|
|
53
|
-
/*
|
|
53
|
+
/* c8 ignore next 3 */
|
|
54
54
|
if (link.startsWith('#')) {
|
|
55
55
|
throw new SyntaxError('An interlanguage link cannot be fragment only!');
|
|
56
56
|
}
|
|
@@ -60,7 +60,7 @@ index_3.LinkToken.prototype.asSelfLink =
|
|
|
60
60
|
/** @implements */
|
|
61
61
|
function (fragment) {
|
|
62
62
|
fragment ??= this.fragment;
|
|
63
|
-
/*
|
|
63
|
+
/* c8 ignore next 3 */
|
|
64
64
|
if (!fragment?.trim()) {
|
|
65
65
|
throw new RangeError('LinkToken.asSelfLink method must specify a non-empty fragment!');
|
|
66
66
|
}
|
|
@@ -70,7 +70,7 @@ index_3.LinkToken.prototype.pipeTrick =
|
|
|
70
70
|
/** @implements */
|
|
71
71
|
function () {
|
|
72
72
|
const linkText = this.firstChild.text();
|
|
73
|
-
/*
|
|
73
|
+
/* c8 ignore next 3 */
|
|
74
74
|
if (linkText.includes('#') || linkText.includes('%')) {
|
|
75
75
|
throw new Error('Pipe trick cannot be used with "#" or "%"!');
|
|
76
76
|
}
|
package/dist/addon/token.js
CHANGED
|
@@ -34,11 +34,11 @@ index_1.Token.prototype.createElement = /** @implements */ function (tagName, {
|
|
|
34
34
|
return new html_1.HtmlToken(tagName, attr, Boolean(closing), Boolean(selfClosing), config);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
/*
|
|
37
|
+
/* c8 ignore next */
|
|
38
38
|
throw new RangeError(`Invalid tag name: ${tagName}`);
|
|
39
39
|
};
|
|
40
40
|
index_1.Token.prototype.sections = /** @implements */ function () {
|
|
41
|
-
/*
|
|
41
|
+
/* c8 ignore next 3 */
|
|
42
42
|
if (this.type !== 'root') {
|
|
43
43
|
return undefined;
|
|
44
44
|
}
|
|
@@ -73,11 +73,11 @@ index_1.Token.prototype.sections = /** @implements */ function () {
|
|
|
73
73
|
index_1.Token.prototype.findEnclosingHtml = /** @implements */ function (tag) {
|
|
74
74
|
tag &&= tag.toLowerCase();
|
|
75
75
|
const { html } = this.getAttribute('config'), normalTags = new Set(html[0]), voidTags = new Set(html[2]);
|
|
76
|
-
/*
|
|
76
|
+
/* c8 ignore next 6 */
|
|
77
77
|
if (voidTags.has(tag)) {
|
|
78
78
|
throw new RangeError(`Void tag: ${tag}`);
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
if (tag && !normalTags.has(tag) && !html[1].includes(tag)) {
|
|
81
81
|
throw new RangeError(`Invalid tag name: ${tag}`);
|
|
82
82
|
}
|
|
83
83
|
const { parentNode } = this;
|
package/dist/addon/transclude.js
CHANGED
|
@@ -38,7 +38,7 @@ transclude_1.TranscludeToken.prototype.newAnonArg =
|
|
|
38
38
|
transclude_1.TranscludeToken.prototype.setValue =
|
|
39
39
|
/** @implements */
|
|
40
40
|
function (key, value, newline) {
|
|
41
|
-
/*
|
|
41
|
+
/* c8 ignore next 3 */
|
|
42
42
|
if (!this.isTemplate()) {
|
|
43
43
|
throw new Error('TranscludeToken.setValue method is only for templates!');
|
|
44
44
|
}
|
|
@@ -61,7 +61,7 @@ transclude_1.TranscludeToken.prototype.replaceTemplate =
|
|
|
61
61
|
/** @implements */
|
|
62
62
|
function (title) {
|
|
63
63
|
const { type, firstChild } = this;
|
|
64
|
-
/*
|
|
64
|
+
/* c8 ignore next 3 */
|
|
65
65
|
if (type === 'magic-word') {
|
|
66
66
|
throw new Error('TranscludeToken.replaceTemplate method is only for templates!');
|
|
67
67
|
}
|
|
@@ -72,11 +72,11 @@ transclude_1.TranscludeToken.prototype.replaceModule =
|
|
|
72
72
|
/** @implements */
|
|
73
73
|
function (title) {
|
|
74
74
|
const { type, name, length, childNodes: [, mod] } = this;
|
|
75
|
-
/*
|
|
75
|
+
/* c8 ignore next 3 */
|
|
76
76
|
if (type !== 'magic-word' || name !== 'invoke') {
|
|
77
77
|
throw new Error('TranscludeToken.replaceModule method is only for modules!');
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
if (length === 1) {
|
|
80
80
|
index_2.Token.prototype.insertAt.call(this, debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'invoke-module', this.getAttribute('config'), [], { 'Stage-1': ':', '!ExtToken': '' })));
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
@@ -87,14 +87,14 @@ transclude_1.TranscludeToken.prototype.replaceFunction =
|
|
|
87
87
|
/** @implements */
|
|
88
88
|
function (func) {
|
|
89
89
|
const { type, name, length, childNodes: [, , fun] } = this;
|
|
90
|
-
/*
|
|
90
|
+
/* c8 ignore next 6 */
|
|
91
91
|
if (type !== 'magic-word' || name !== 'invoke') {
|
|
92
92
|
throw new Error('TranscludeToken.replaceModule method is only for modules!');
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
if (length < 2) {
|
|
95
95
|
throw new Error('No module name specified!');
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
if (length === 2) {
|
|
98
98
|
index_2.Token.prototype.insertAt.call(this, debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'invoke-function', this.getAttribute('config'), [], { 'Stage-1': ':', '!ExtToken': '' })));
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
@@ -195,7 +195,7 @@ transclude_1.TranscludeToken.prototype.escapeTables =
|
|
|
195
195
|
return token;
|
|
196
196
|
}, index_1.default);
|
|
197
197
|
const { firstChild, length } = index_1.default.parseWithRef(`{{${parsed.toString()}}}`, this);
|
|
198
|
-
/*
|
|
198
|
+
/* c8 ignore next 3 */
|
|
199
199
|
if (length !== 1 || !(firstChild instanceof transclude_1.TranscludeToken)) {
|
|
200
200
|
throw new Error('Failed to escape tables!');
|
|
201
201
|
}
|
package/dist/base.d.mts
CHANGED
|
@@ -119,8 +119,10 @@ interface Token extends AstNode {
|
|
|
119
119
|
* Save in JSON format
|
|
120
120
|
*
|
|
121
121
|
* 保存为JSON
|
|
122
|
+
* @param file file name / 文件名
|
|
123
|
+
* @param depth depth of the node / 节点深度
|
|
122
124
|
*/
|
|
123
|
-
json(): AST;
|
|
125
|
+
json(file?: string, depth?: number): AST;
|
|
124
126
|
/**
|
|
125
127
|
* Generate HTML
|
|
126
128
|
*
|
package/dist/base.d.ts
CHANGED
|
@@ -119,8 +119,10 @@ interface Token extends AstNode {
|
|
|
119
119
|
* Save in JSON format
|
|
120
120
|
*
|
|
121
121
|
* 保存为JSON
|
|
122
|
+
* @param file file name / 文件名
|
|
123
|
+
* @param depth depth of the node / 节点深度
|
|
122
124
|
*/
|
|
123
|
-
json(): AST;
|
|
125
|
+
json(file?: string, depth?: number): AST;
|
|
124
126
|
/**
|
|
125
127
|
* Generate HTML
|
|
126
128
|
*
|
package/dist/bin/config.js
CHANGED
|
@@ -77,7 +77,7 @@ const mw = {
|
|
|
77
77
|
},
|
|
78
78
|
},
|
|
79
79
|
};
|
|
80
|
-
const pkg = "wikiparser-node", version = "1.35.
|
|
80
|
+
const pkg = "wikiparser-node", version = "1.35.1";
|
|
81
81
|
let mwConfig;
|
|
82
82
|
/**
|
|
83
83
|
* Get the parser configuration for a Wikimedia Foundation project.
|
|
@@ -122,7 +122,7 @@ exports.default = async (site, url, user, force, internal) => {
|
|
|
122
122
|
siprop: 'general|magicwords|functionhooks|namespaces|namespacealiases',
|
|
123
123
|
format: 'json',
|
|
124
124
|
formatversion: '2',
|
|
125
|
-
}, {
|
|
125
|
+
}, { general: { articlepath, variants, langconversion }, magicwords, namespaces, namespacealiases, functionhooks, } = (await (await fetch(`${url}/api.php?${new URLSearchParams(params).toString()}`, headers)).json()).query;
|
|
126
126
|
try {
|
|
127
127
|
eval(m); // eslint-disable-line no-eval
|
|
128
128
|
}
|
|
@@ -157,7 +157,7 @@ exports.default = async (site, url, user, force, internal) => {
|
|
|
157
157
|
Object.assign(config, { functionHook: [...functionhooks.map(s => s.toLowerCase()), 'msgnw'] });
|
|
158
158
|
}
|
|
159
159
|
if (!mwConfig.variableIDs) {
|
|
160
|
-
const {
|
|
160
|
+
const { variables } = (await (await fetch(`${url}/api.php?${new URLSearchParams({ ...params, siprop: 'variables' }).toString()}`, headers)).json()).query;
|
|
161
161
|
Object.assign(config, { variable: [...new Set([...variables, '='])] });
|
|
162
162
|
}
|
|
163
163
|
if ('#choose' in parserFunction[0]) {
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const re = new RegExp(String.raw `^https?:\/\/([^./]+)\.(${common_1.wmf})\.org`,
|
|
|
26
26
|
* @param dir 子路径
|
|
27
27
|
*/
|
|
28
28
|
const rootRequire = (file, dir) => require(path_1.default.isAbsolute(file)
|
|
29
|
-
? /*
|
|
29
|
+
? /* c8 ignore next */ file
|
|
30
30
|
: path_1.default.join('..', file.includes('/') ? '' : dir, file));
|
|
31
31
|
/* NOT FOR BROWSER ONLY END */
|
|
32
32
|
let viewOnly = false;
|
|
@@ -125,7 +125,7 @@ const Parser = {
|
|
|
125
125
|
if (typeof this.config === 'string') {
|
|
126
126
|
this.config = rootRequire(this.config, 'config');
|
|
127
127
|
}
|
|
128
|
-
/*
|
|
128
|
+
/* c8 ignore next 3 */
|
|
129
129
|
if (this.config.doubleUnderscore.length < 3 || !('functionHook' in this.config)) {
|
|
130
130
|
(0, diff_1.error)(`The schema (${path_1.default.join(__dirname, '..', 'config', '.schema.json')}) of parser configuration is updated.`);
|
|
131
131
|
}
|
|
@@ -230,7 +230,7 @@ const Parser = {
|
|
|
230
230
|
return token.parse(maxStage, include);
|
|
231
231
|
/* NOT FOR BROWSER ONLY */
|
|
232
232
|
}
|
|
233
|
-
catch (e) /*
|
|
233
|
+
catch (e) /* c8 ignore start */ {
|
|
234
234
|
if (e instanceof Error) {
|
|
235
235
|
const file = path_1.default.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
|
|
236
236
|
for (const k of Object.keys(config)) {
|
|
@@ -244,13 +244,14 @@ const Parser = {
|
|
|
244
244
|
}
|
|
245
245
|
throw e;
|
|
246
246
|
}
|
|
247
|
+
/* c8 ignore stop */
|
|
247
248
|
/* NOT FOR BROWSER ONLY END */
|
|
248
249
|
});
|
|
249
250
|
/* NOT FOR BROWSER */
|
|
250
251
|
if (types?.includes('list-range')) {
|
|
251
252
|
root.buildLists();
|
|
252
253
|
}
|
|
253
|
-
/*
|
|
254
|
+
/* c8 ignore start */
|
|
254
255
|
if (this.debugging) {
|
|
255
256
|
let restored = root.toString(), proc = 'parsing';
|
|
256
257
|
if (restored === wikitext) {
|
|
@@ -267,6 +268,7 @@ const Parser = {
|
|
|
267
268
|
})());
|
|
268
269
|
}
|
|
269
270
|
}
|
|
271
|
+
/* c8 ignore stop */
|
|
270
272
|
/* NOT FOR BROWSER END */
|
|
271
273
|
return root;
|
|
272
274
|
},
|
|
@@ -300,19 +302,20 @@ const Parser = {
|
|
|
300
302
|
/** @implements */
|
|
301
303
|
getWMFSite(url) {
|
|
302
304
|
const mt = re.exec(url);
|
|
303
|
-
/*
|
|
305
|
+
/* c8 ignore next 3 */
|
|
304
306
|
if (!mt) {
|
|
305
307
|
throw new RangeError('Not a recognizable WMF site!');
|
|
306
308
|
}
|
|
307
309
|
const type = mt[2].toLowerCase();
|
|
308
310
|
return [mt[1].toLowerCase() + (type === 'wikipedia' ? 'wiki' : type), mt[0]];
|
|
309
311
|
},
|
|
310
|
-
/*
|
|
312
|
+
/* c8 ignore start */
|
|
311
313
|
/** @implements */
|
|
312
314
|
async fetchConfig(site, url, user) {
|
|
313
315
|
const { default: fetchConfig } = require('./bin/config');
|
|
314
316
|
return this.getConfig(await fetchConfig(site, url, user, false, true));
|
|
315
317
|
},
|
|
318
|
+
/* c8 ignore stop */
|
|
316
319
|
/* NOT FOR BROWSER ONLY END */
|
|
317
320
|
/* NOT FOR BROWSER */
|
|
318
321
|
/** @implements */
|
|
@@ -352,7 +355,7 @@ const Parser = {
|
|
|
352
355
|
if (!canonicalName) {
|
|
353
356
|
const [insensitive, sensitive] = parserFunction, entry = Object.entries(sensitive).find(([, v]) => v === lcName)
|
|
354
357
|
|| Object.entries(insensitive).find(([, v]) => v === lcName);
|
|
355
|
-
/*
|
|
358
|
+
/* c8 ignore next 3 */
|
|
356
359
|
if (!entry) {
|
|
357
360
|
throw new RangeError(`Unable to resolve parser function: ${name}`);
|
|
358
361
|
}
|
|
@@ -365,7 +368,7 @@ const Parser = {
|
|
|
365
368
|
else {
|
|
366
369
|
result = expandMagicWord(lcName, args);
|
|
367
370
|
}
|
|
368
|
-
/*
|
|
371
|
+
/* c8 ignore next 3 */
|
|
369
372
|
if (result === false) {
|
|
370
373
|
throw new RangeError(`Unable to resolve parser function: ${name}`);
|
|
371
374
|
}
|
|
@@ -373,35 +376,38 @@ const Parser = {
|
|
|
373
376
|
},
|
|
374
377
|
/** @implements */
|
|
375
378
|
warn(msg, ...args) {
|
|
376
|
-
/*
|
|
379
|
+
/* c8 ignore start */
|
|
377
380
|
if (this.warning) {
|
|
378
381
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
379
382
|
console.warn(util_1.default.styleText?.('yellow', msg) ?? msg, ...args);
|
|
380
383
|
}
|
|
384
|
+
/* c8 ignore stop */
|
|
381
385
|
},
|
|
382
386
|
/** @implements */
|
|
383
387
|
debug(msg, ...args) {
|
|
384
|
-
/*
|
|
388
|
+
/* c8 ignore start */
|
|
385
389
|
if (this.debugging) {
|
|
386
390
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
387
391
|
console.debug(util_1.default.styleText?.('blue', msg) ?? msg, ...args);
|
|
388
392
|
}
|
|
393
|
+
/* c8 ignore stop */
|
|
389
394
|
},
|
|
390
395
|
error: diff_1.error,
|
|
391
396
|
info: diff_1.info,
|
|
392
|
-
/*
|
|
397
|
+
/* c8 ignore start */
|
|
393
398
|
/** @implements */
|
|
394
399
|
log(f) {
|
|
395
400
|
if (typeof f === 'function') {
|
|
396
401
|
console.log(String(f));
|
|
397
402
|
}
|
|
398
403
|
},
|
|
404
|
+
/* c8 ignore stop */
|
|
399
405
|
/** @implements */
|
|
400
406
|
require(name) {
|
|
401
407
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
402
408
|
return Object.hasOwn(constants_1.classes, name) ? require(constants_1.classes[name])[name] : require(path_1.default.join(__dirname, name));
|
|
403
409
|
},
|
|
404
|
-
/*
|
|
410
|
+
/* c8 ignore start */
|
|
405
411
|
/** @implements */
|
|
406
412
|
async clearCache() {
|
|
407
413
|
await (0, diff_1.cmd)('npm', ['--prefix', path_1.default.join(__dirname, '..'), 'run', 'build:core']);
|
|
@@ -420,11 +426,12 @@ const Parser = {
|
|
|
420
426
|
}
|
|
421
427
|
this.info('已重新加载Parser');
|
|
422
428
|
},
|
|
429
|
+
/* c8 ignore stop */
|
|
423
430
|
/** @implements */
|
|
424
431
|
isInterwiki(title, config = Parser.getConfig()) {
|
|
425
432
|
return (0, string_1.isInterwiki)(title, config);
|
|
426
433
|
},
|
|
427
|
-
/*
|
|
434
|
+
/* c8 ignore start */
|
|
428
435
|
/** @implements */
|
|
429
436
|
reparse(date = '') {
|
|
430
437
|
const dir = path_1.default.join(__dirname, '..', 'errors'), main = fs_1.default.readdirSync(dir).find(name => name.startsWith(date) && name.endsWith('Z'));
|
|
@@ -449,6 +456,7 @@ const Parser = {
|
|
|
449
456
|
fs_1.default.unlinkSync(`${file}.json`);
|
|
450
457
|
}, this);
|
|
451
458
|
},
|
|
459
|
+
/* c8 ignore stop */
|
|
452
460
|
};
|
|
453
461
|
const def = {
|
|
454
462
|
default: { value: Parser },
|
package/dist/lib/document.js
CHANGED
|
@@ -15,10 +15,10 @@ const loadTexvcjs = () => {
|
|
|
15
15
|
try {
|
|
16
16
|
texcvjs = require('mathoid-texvcjs');
|
|
17
17
|
}
|
|
18
|
-
catch {
|
|
19
|
-
/* istanbul ignore next */
|
|
18
|
+
catch /* c8 ignore start */ {
|
|
20
19
|
texcvjs = null;
|
|
21
20
|
}
|
|
21
|
+
/* c8 ignore stop */
|
|
22
22
|
}
|
|
23
23
|
return texcvjs;
|
|
24
24
|
}
|
|
@@ -31,10 +31,12 @@ const loadJsonLSP = () => {
|
|
|
31
31
|
try {
|
|
32
32
|
jsonLSP = require('vscode-json-languageservice')
|
|
33
33
|
.getLanguageService({
|
|
34
|
+
/* c8 ignore start */
|
|
34
35
|
/** @implements */
|
|
35
36
|
async schemaRequestService(uri) {
|
|
36
37
|
return (await fetch(uri)).text();
|
|
37
38
|
},
|
|
39
|
+
/* c8 ignore stop */
|
|
38
40
|
});
|
|
39
41
|
const dir = path_1.default.join('..', '..', 'data', 'ext');
|
|
40
42
|
jsonLSP.configure({
|
|
@@ -48,17 +50,17 @@ const loadJsonLSP = () => {
|
|
|
48
50
|
schema,
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
|
-
catch {
|
|
52
|
-
/* istanbul ignore next */
|
|
53
|
+
catch /* c8 ignore start */ {
|
|
53
54
|
return false;
|
|
54
55
|
}
|
|
56
|
+
/* c8 ignore stop */
|
|
55
57
|
}).filter(schema => schema !== false),
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
|
-
catch {
|
|
59
|
-
/* istanbul ignore next */
|
|
60
|
+
catch /* c8 ignore start */ {
|
|
60
61
|
jsonLSP = null;
|
|
61
62
|
}
|
|
63
|
+
/* c8 ignore stop */
|
|
62
64
|
}
|
|
63
65
|
return jsonLSP;
|
|
64
66
|
};
|
|
@@ -70,10 +72,10 @@ const loadCssLSP = () => {
|
|
|
70
72
|
cssLSP = require('vscode-css-languageservice')
|
|
71
73
|
.getCSSLanguageService();
|
|
72
74
|
}
|
|
73
|
-
catch {
|
|
74
|
-
/* istanbul ignore next */
|
|
75
|
+
catch /* c8 ignore start */ {
|
|
75
76
|
cssLSP = null;
|
|
76
77
|
}
|
|
78
|
+
/* c8 ignore stop */
|
|
77
79
|
}
|
|
78
80
|
return cssLSP;
|
|
79
81
|
};
|
|
@@ -85,10 +87,10 @@ const loadHtmlData = () => {
|
|
|
85
87
|
htmlData = require('vscode-html-languageservice')
|
|
86
88
|
.getDefaultHTMLDataProvider();
|
|
87
89
|
}
|
|
88
|
-
catch {
|
|
89
|
-
/* istanbul ignore next */
|
|
90
|
+
catch /* c8 ignore start */ {
|
|
90
91
|
htmlData = null;
|
|
91
92
|
}
|
|
93
|
+
/* c8 ignore stop */
|
|
92
94
|
}
|
|
93
95
|
return htmlData;
|
|
94
96
|
};
|
|
@@ -100,10 +102,10 @@ const loadStylelint = () => {
|
|
|
100
102
|
try {
|
|
101
103
|
return (await import('stylelint')).default;
|
|
102
104
|
}
|
|
103
|
-
catch {
|
|
104
|
-
/* istanbul ignore next */
|
|
105
|
+
catch /* c8 ignore start */ {
|
|
105
106
|
return null;
|
|
106
107
|
}
|
|
108
|
+
/* c8 ignore stop */
|
|
107
109
|
})();
|
|
108
110
|
return stylelint;
|
|
109
111
|
}
|
package/dist/lib/element.d.ts
CHANGED
|
@@ -104,9 +104,10 @@ export declare abstract class AstElement extends AstNode {
|
|
|
104
104
|
*
|
|
105
105
|
* 保存为JSON
|
|
106
106
|
* @param file file name / 文件名
|
|
107
|
+
* @param depth depth of the node / 节点深度
|
|
107
108
|
* @param start
|
|
108
109
|
*/
|
|
109
|
-
json(file?: string, start?: number): AST;
|
|
110
|
+
json(file?: string, depth?: number, start?: number): AST;
|
|
110
111
|
/**
|
|
111
112
|
* Merge adjacent text child nodes
|
|
112
113
|
*
|