wikiparser-node 1.13.0 → 1.13.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/config/default.json +1 -9
- package/config/enwiki.json +2 -10
- package/dist/base.d.ts +1 -0
- package/dist/src/paramTag/index.js +1 -1
- package/dist/src/paramTag/inputbox.js +15 -1
- package/dist/src/pre.js +18 -10
- package/dist/src/tagPair/include.js +24 -11
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +2 -2
package/config/default.json
CHANGED
|
@@ -140,10 +140,6 @@
|
|
|
140
140
|
"711": "TimedText talk",
|
|
141
141
|
"828": "Module",
|
|
142
142
|
"829": "Module talk",
|
|
143
|
-
"2300": "Gadget",
|
|
144
|
-
"2301": "Gadget talk",
|
|
145
|
-
"2302": "Gadget definition",
|
|
146
|
-
"2303": "Gadget definition talk",
|
|
147
143
|
"2600": "Topic"
|
|
148
144
|
},
|
|
149
145
|
"nsid": {
|
|
@@ -300,11 +296,7 @@
|
|
|
300
296
|
"模組討論": 829,
|
|
301
297
|
"模组对话": 829,
|
|
302
298
|
"模组讨论": 829,
|
|
303
|
-
"モジュール・トーク": 829
|
|
304
|
-
"gadget": 2300,
|
|
305
|
-
"gadget talk": 2301,
|
|
306
|
-
"gadget definition": 2302,
|
|
307
|
-
"gadget definition talk": 2303
|
|
299
|
+
"モジュール・トーク": 829
|
|
308
300
|
},
|
|
309
301
|
"parserFunction": [
|
|
310
302
|
{
|
package/config/enwiki.json
CHANGED
|
@@ -125,11 +125,7 @@
|
|
|
125
125
|
"710": "TimedText",
|
|
126
126
|
"711": "TimedText talk",
|
|
127
127
|
"828": "Module",
|
|
128
|
-
"829": "Module talk"
|
|
129
|
-
"2300": "Gadget",
|
|
130
|
-
"2301": "Gadget talk",
|
|
131
|
-
"2302": "Gadget definition",
|
|
132
|
-
"2303": "Gadget definition talk"
|
|
128
|
+
"829": "Module talk"
|
|
133
129
|
},
|
|
134
130
|
"nsid": {
|
|
135
131
|
"": 0,
|
|
@@ -165,11 +161,7 @@
|
|
|
165
161
|
"timedtext": 710,
|
|
166
162
|
"timedtext talk": 711,
|
|
167
163
|
"module": 828,
|
|
168
|
-
"module talk": 829
|
|
169
|
-
"gadget": 2300,
|
|
170
|
-
"gadget talk": 2301,
|
|
171
|
-
"gadget definition": 2302,
|
|
172
|
-
"gadget definition talk": 2303
|
|
164
|
+
"module talk": 829
|
|
173
165
|
},
|
|
174
166
|
"parserFunction": [
|
|
175
167
|
{
|
package/dist/base.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ class ParamTagToken extends index_2.Token {
|
|
|
48
48
|
lint(start = this.getAbsoluteIndex()) {
|
|
49
49
|
const rect = new rect_1.BoundingRect(this, start);
|
|
50
50
|
return this.childNodes.filter(child => {
|
|
51
|
-
const
|
|
51
|
+
const childNodes = child.childNodes.filter(({ type }) => type !== 'comment'), i = childNodes.findIndex(({ type }) => type !== 'text'), str = childNodes.slice(0, i >= 0 ? i : undefined).map(String).join('');
|
|
52
52
|
return str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str);
|
|
53
53
|
}).map(child => {
|
|
54
54
|
const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', index_1.default.msg('invalid parameter of <$1>', this.name));
|
|
@@ -4,19 +4,33 @@ exports.InputboxToken = void 0;
|
|
|
4
4
|
const braces_1 = require("../../parser/braces");
|
|
5
5
|
const index_1 = require("../../index");
|
|
6
6
|
const index_2 = require("./index");
|
|
7
|
+
const comment_1 = require("../nowiki/comment");
|
|
7
8
|
/* NOT FOR BROWSER */
|
|
8
9
|
const constants_1 = require("../../util/constants");
|
|
9
10
|
/* NOT FOR BROWSER END */
|
|
11
|
+
/**
|
|
12
|
+
* 解析注释
|
|
13
|
+
* @param wikitext 维基文本
|
|
14
|
+
* @param config
|
|
15
|
+
* @param accum
|
|
16
|
+
*/
|
|
17
|
+
const parseComment = (wikitext, config, accum) => wikitext.replace(/<!--.*?(?:-->|$)/gsu, comment => {
|
|
18
|
+
const str = `\0${accum.length + 1}c\x7F`, closed = comment.endsWith('-->');
|
|
19
|
+
// @ts-expect-error abstract class
|
|
20
|
+
new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
|
|
21
|
+
return str;
|
|
22
|
+
});
|
|
10
23
|
/** `<inputbox>` */
|
|
11
24
|
class InputboxToken extends index_2.ParamTagToken {
|
|
12
25
|
/** @class */
|
|
13
26
|
constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
|
|
27
|
+
wikitext &&= parseComment(wikitext, config, accum);
|
|
14
28
|
const placeholder = Symbol('InputboxToken'), { length } = accum;
|
|
15
29
|
accum.push(placeholder);
|
|
16
30
|
wikitext &&= (0, braces_1.parseBraces)(wikitext, config, accum);
|
|
17
31
|
accum.splice(length, 1);
|
|
18
32
|
super(wikitext, config, accum, {
|
|
19
|
-
ArgToken: ':', TranscludeToken: ':',
|
|
33
|
+
CommentToken: ':', ArgToken: ':', TranscludeToken: ':',
|
|
20
34
|
});
|
|
21
35
|
}
|
|
22
36
|
}
|
package/dist/src/pre.js
CHANGED
|
@@ -20,19 +20,27 @@ class PreToken extends index_2.Token {
|
|
|
20
20
|
/** @class */
|
|
21
21
|
constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
|
|
22
22
|
if (wikitext) {
|
|
23
|
-
const opening =
|
|
24
|
-
let i =
|
|
25
|
-
|
|
23
|
+
const opening = /<nowiki>/giu, closing = /<\/nowiki>/giu, { length } = opening.source;
|
|
24
|
+
let i = opening.exec(wikitext);
|
|
25
|
+
if (i) {
|
|
26
|
+
closing.lastIndex = i.index + length;
|
|
27
|
+
}
|
|
28
|
+
let j = closing.exec(wikitext), lastIndex = 0, str = '';
|
|
29
|
+
while (i && j) {
|
|
26
30
|
// @ts-expect-error abstract class
|
|
27
|
-
new noinclude_1.NoincludeToken(
|
|
31
|
+
new noinclude_1.NoincludeToken(i[0], config, accum);
|
|
28
32
|
// @ts-expect-error abstract class
|
|
29
|
-
new noinclude_1.NoincludeToken(
|
|
30
|
-
str += `${wikitext.slice(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
new noinclude_1.NoincludeToken(j[0], config, accum);
|
|
34
|
+
str += `${wikitext.slice(lastIndex, i.index)}\0${accum.length - 1}n\x7F${wikitext.slice(i.index + length, j.index)}\0${accum.length}n\x7F`;
|
|
35
|
+
lastIndex = j.index + length + 1;
|
|
36
|
+
opening.lastIndex = lastIndex;
|
|
37
|
+
i = opening.exec(wikitext);
|
|
38
|
+
if (i) {
|
|
39
|
+
closing.lastIndex = i.index + length;
|
|
40
|
+
}
|
|
41
|
+
j = closing.exec(wikitext);
|
|
34
42
|
}
|
|
35
|
-
wikitext = str + wikitext;
|
|
43
|
+
wikitext = str + wikitext.slice(lastIndex);
|
|
36
44
|
}
|
|
37
45
|
super(wikitext, config, accum, {
|
|
38
46
|
AstText: ':', NoincludeToken: ':', ConverterToken: ':',
|
|
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.IncludeToken = void 0;
|
|
38
38
|
const lint_1 = require("../../util/lint");
|
|
39
|
+
const rect_1 = require("../../lib/rect");
|
|
39
40
|
const hidden_1 = require("../../mixin/hidden");
|
|
40
41
|
const index_1 = require("../../index");
|
|
41
42
|
const index_2 = require("./index");
|
|
@@ -95,18 +96,30 @@ let IncludeToken = (() => {
|
|
|
95
96
|
}
|
|
96
97
|
/** @private */
|
|
97
98
|
lint(start = this.getAbsoluteIndex()) {
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
const errors = [], { firstChild, closed, name } = this, rect = new rect_1.BoundingRect(this, start);
|
|
100
|
+
if (firstChild.data.trim()) {
|
|
101
|
+
const e = (0, lint_1.generateForChild)(firstChild, rect, 'no-ignored', 'useless attribute', 'warning');
|
|
102
|
+
e.suggestions = [
|
|
103
|
+
{
|
|
104
|
+
desc: 'remove',
|
|
105
|
+
range: [e.startIndex, e.endIndex],
|
|
106
|
+
text: '',
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
errors.push(e);
|
|
100
110
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
if (!closed) {
|
|
112
|
+
const e = (0, lint_1.generateForSelf)(this, rect, 'unclosed-comment', index_1.default.msg('unclosed $1', `<${name}>`));
|
|
113
|
+
e.suggestions = [
|
|
114
|
+
{
|
|
115
|
+
desc: 'close',
|
|
116
|
+
range: [e.endIndex, e.endIndex],
|
|
117
|
+
text: `</${name}>`,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
errors.push(e);
|
|
121
|
+
}
|
|
122
|
+
return errors;
|
|
110
123
|
}
|
|
111
124
|
/* NOT FOR BROWSER */
|
|
112
125
|
cloneNode() {
|
package/i18n/zh-hans.json
CHANGED
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"unexpected template argument": "未预期的模板参数",
|
|
54
54
|
"unmatched closing tag": "未匹配的闭合标签",
|
|
55
55
|
"unnecessary URL encoding in an internal link": "内链中不必要的URL编码",
|
|
56
|
+
"useless attribute": "无用的属性",
|
|
56
57
|
"useless fragment": "无用的fragment",
|
|
57
58
|
"useless link text": "无用的链接文字",
|
|
58
59
|
"variable anchor in a section header": "段落标题中可变的锚点",
|
package/i18n/zh-hant.json
CHANGED
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"unexpected template argument": "未預期的模板參數",
|
|
54
54
|
"unmatched closing tag": "未匹配的閉合標籤",
|
|
55
55
|
"unnecessary URL encoding in an internal link": "內部連結中不必要的URL編碼",
|
|
56
|
+
"useless attribute": "無用的屬性",
|
|
56
57
|
"useless fragment": "無用的fragment",
|
|
57
58
|
"useless link text": "無用的連結文字",
|
|
58
59
|
"variable anchor in a section header": "段落標題中可變的錨點",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiparser-node",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "A Node.js parser for MediaWiki markup with AST",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"chalk": "^4.1.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@bhsd/common": "^0.
|
|
51
|
+
"@bhsd/common": "^0.3.0",
|
|
52
52
|
"@codemirror/lint": "^6.8.0",
|
|
53
53
|
"@types/node": "^20.11.6",
|
|
54
54
|
"codejar-async": "^4.2.3",
|