wikiparser-node 1.4.1 → 1.4.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/dist/base.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -12
- package/dist/lib/element.d.ts +5 -5
- package/dist/lib/element.js +45 -37
- package/dist/lib/node.js +6 -0
- package/dist/lib/text.js +81 -40
- package/dist/lib/title.d.ts +1 -1
- package/dist/lib/title.js +13 -4
- package/dist/mixin/flagsParent.d.ts +1 -1
- package/dist/mixin/flagsParent.js +2 -0
- package/dist/mixin/magicLinkParent.d.ts +1 -1
- package/dist/mixin/magicLinkParent.js +2 -0
- package/dist/mixin/singleLine.js +2 -2
- package/dist/mixin/sol.js +2 -4
- package/dist/parser/braces.js +2 -2
- package/dist/parser/commentAndExt.js +2 -2
- package/dist/parser/converter.js +2 -2
- package/dist/parser/externalLinks.js +2 -2
- package/dist/parser/hrAndDoubleUnderscore.js +2 -2
- package/dist/parser/html.js +2 -2
- package/dist/parser/links.js +7 -5
- package/dist/parser/list.js +2 -2
- package/dist/parser/magicLinks.js +2 -2
- package/dist/parser/quotes.js +3 -3
- package/dist/parser/selector.js +2 -2
- package/dist/parser/table.js +7 -7
- package/dist/src/arg.d.ts +1 -1
- package/dist/src/arg.js +10 -9
- package/dist/src/atom.d.ts +1 -1
- package/dist/src/atom.js +4 -4
- package/dist/src/attribute.d.ts +1 -1
- package/dist/src/attribute.js +16 -17
- package/dist/src/attributes.d.ts +1 -1
- package/dist/src/attributes.js +8 -8
- package/dist/src/converter.d.ts +1 -1
- package/dist/src/converter.js +7 -8
- package/dist/src/converterFlags.d.ts +1 -1
- package/dist/src/converterFlags.js +9 -7
- package/dist/src/converterRule.d.ts +1 -1
- package/dist/src/converterRule.js +11 -10
- package/dist/src/extLink.d.ts +1 -1
- package/dist/src/extLink.js +18 -14
- package/dist/src/gallery.d.ts +2 -2
- package/dist/src/gallery.js +7 -7
- package/dist/src/heading.d.ts +1 -1
- package/dist/src/heading.js +12 -13
- package/dist/src/html.d.ts +1 -1
- package/dist/src/html.js +15 -14
- package/dist/src/imageParameter.d.ts +2 -2
- package/dist/src/imageParameter.js +12 -13
- package/dist/src/imagemap.d.ts +2 -2
- package/dist/src/imagemap.js +11 -7
- package/dist/src/imagemapLink.d.ts +1 -1
- package/dist/src/imagemapLink.js +6 -6
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +22 -9
- package/dist/src/link/base.d.ts +1 -1
- package/dist/src/link/base.js +18 -15
- package/dist/src/link/file.d.ts +1 -1
- package/dist/src/link/file.js +9 -5
- package/dist/src/link/galleryImage.d.ts +1 -1
- package/dist/src/link/galleryImage.js +10 -6
- package/dist/src/link/index.js +1 -1
- package/dist/src/magicLink.d.ts +2 -2
- package/dist/src/magicLink.js +8 -7
- package/dist/src/nested.d.ts +1 -1
- package/dist/src/nested.js +6 -5
- package/dist/src/nowiki/base.d.ts +1 -1
- package/dist/src/nowiki/base.js +4 -4
- package/dist/src/nowiki/comment.d.ts +1 -1
- package/dist/src/nowiki/comment.js +9 -6
- package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
- package/dist/src/nowiki/doubleUnderscore.js +5 -4
- package/dist/src/nowiki/hr.js +1 -0
- package/dist/src/nowiki/index.js +2 -2
- package/dist/src/nowiki/list.js +1 -0
- package/dist/src/nowiki/quote.js +3 -3
- package/dist/src/onlyinclude.js +6 -6
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +7 -7
- package/dist/src/paramTag/inputbox.d.ts +1 -1
- package/dist/src/paramTag/inputbox.js +4 -4
- package/dist/src/parameter.d.ts +1 -1
- package/dist/src/parameter.js +18 -20
- package/dist/src/pre.d.ts +1 -1
- package/dist/src/pre.js +5 -5
- package/dist/src/syntax.d.ts +1 -1
- package/dist/src/syntax.js +5 -4
- package/dist/src/table/base.d.ts +1 -1
- package/dist/src/table/base.js +6 -5
- package/dist/src/table/index.d.ts +1 -1
- package/dist/src/table/index.js +11 -6
- package/dist/src/table/td.d.ts +1 -1
- package/dist/src/table/td.js +28 -17
- package/dist/src/table/tr.d.ts +1 -1
- package/dist/src/table/tr.js +2 -2
- package/dist/src/table/trBase.js +2 -2
- package/dist/src/tagPair/ext.d.ts +1 -1
- package/dist/src/tagPair/ext.js +8 -6
- package/dist/src/tagPair/include.d.ts +1 -1
- package/dist/src/tagPair/include.js +6 -6
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +16 -13
- package/dist/src/transclude.d.ts +1 -1
- package/dist/src/transclude.js +35 -20
- package/dist/util/debug.js +7 -0
- package/dist/util/diff.js +11 -1
- package/dist/util/lint.js +2 -2
- package/package.json +1 -1
package/dist/base.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export interface Config {
|
|
|
8
8
|
readonly protocol: string;
|
|
9
9
|
readonly img: Record<string, string>;
|
|
10
10
|
readonly variants: string[];
|
|
11
|
-
readonly interwiki: string[];
|
|
12
11
|
readonly excludes?: string[];
|
|
12
|
+
readonly interwiki: string[];
|
|
13
13
|
readonly conversionTable?: [string, string][];
|
|
14
14
|
readonly redirects?: [string, string][];
|
|
15
15
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Shadow } from './util/debug';
|
|
2
|
+
import type { log } from './util/diff';
|
|
2
3
|
import type { Config, LintError, Parser as ParserBase } from './base';
|
|
3
4
|
import type { Title } from './lib/title';
|
|
4
5
|
import type { Token } from './internal';
|
|
5
|
-
declare type log = (msg: string, ...args: unknown[]) => void;
|
|
6
6
|
declare interface Parser extends ParserBase {
|
|
7
7
|
readonly Shadow: typeof Shadow;
|
|
8
8
|
conversionTable: Map<string, string>;
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
/* eslint n/exports-style: 0 */
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const diff_1 = require("./util/diff");
|
|
6
5
|
const debug_1 = require("./util/debug");
|
|
7
6
|
const constants_1 = require("./util/constants");
|
|
8
7
|
const string_1 = require("./util/string");
|
|
8
|
+
const diff_1 = require("./util/diff");
|
|
9
9
|
/**
|
|
10
10
|
* 从根路径require
|
|
11
11
|
* @param file 文件名
|
|
@@ -27,6 +27,7 @@ const Parser = {
|
|
|
27
27
|
getConfig() {
|
|
28
28
|
if (typeof this.config === 'string') {
|
|
29
29
|
this.config = rootRequire(this.config, 'config/');
|
|
30
|
+
/* NOT FOR BROWSER */
|
|
30
31
|
const { config: { conversionTable, redirects } } = this;
|
|
31
32
|
if (conversionTable) {
|
|
32
33
|
this.conversionTable = new Map(conversionTable);
|
|
@@ -34,6 +35,7 @@ const Parser = {
|
|
|
34
35
|
if (redirects) {
|
|
35
36
|
this.redirects = new Map(redirects);
|
|
36
37
|
}
|
|
38
|
+
/* NOT FOR BROWSER END */
|
|
37
39
|
return this.getConfig();
|
|
38
40
|
}
|
|
39
41
|
return {
|
|
@@ -57,6 +59,7 @@ const Parser = {
|
|
|
57
59
|
}
|
|
58
60
|
const { Token } = require('./src/index');
|
|
59
61
|
const token = debug_1.Shadow.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
|
|
62
|
+
/* NOT FOR BROWSER */
|
|
60
63
|
debug_1.Shadow.run(() => {
|
|
61
64
|
for (const key of ['main', 'fragment']) {
|
|
62
65
|
if (titleObj[key]?.includes('\0')) {
|
|
@@ -66,6 +69,7 @@ const Parser = {
|
|
|
66
69
|
});
|
|
67
70
|
titleObj.conversionTable = this.conversionTable;
|
|
68
71
|
titleObj.redirects = this.redirects;
|
|
72
|
+
/* NOT FOR BROWSER END */
|
|
69
73
|
return titleObj;
|
|
70
74
|
},
|
|
71
75
|
/** @implements */
|
|
@@ -89,6 +93,7 @@ const Parser = {
|
|
|
89
93
|
throw e;
|
|
90
94
|
}
|
|
91
95
|
});
|
|
96
|
+
/* NOT FOR BROWSER */
|
|
92
97
|
if (this.debugging) {
|
|
93
98
|
let restored = String(root), process = '解析';
|
|
94
99
|
if (restored === wikitext) {
|
|
@@ -106,6 +111,7 @@ const Parser = {
|
|
|
106
111
|
})());
|
|
107
112
|
}
|
|
108
113
|
}
|
|
114
|
+
/* NOT FOR BROWSER END */
|
|
109
115
|
return root;
|
|
110
116
|
},
|
|
111
117
|
/* NOT FOR BROWSER */
|
|
@@ -121,14 +127,8 @@ const Parser = {
|
|
|
121
127
|
console.debug('\x1B[34m%s\x1B[0m', msg, ...args);
|
|
122
128
|
}
|
|
123
129
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
console.error('\x1B[31m%s\x1B[0m', msg, ...args);
|
|
127
|
-
},
|
|
128
|
-
/** @implements */
|
|
129
|
-
info(msg, ...args) {
|
|
130
|
-
console.info('\x1B[32m%s\x1B[0m', msg, ...args);
|
|
131
|
-
},
|
|
130
|
+
error: diff_1.error,
|
|
131
|
+
info: diff_1.info,
|
|
132
132
|
/** @implements */
|
|
133
133
|
log(f) {
|
|
134
134
|
if (typeof f === 'function') {
|
|
@@ -190,13 +190,16 @@ const Parser = {
|
|
|
190
190
|
});
|
|
191
191
|
},
|
|
192
192
|
};
|
|
193
|
-
const def = {
|
|
193
|
+
const def = {
|
|
194
|
+
default: { value: Parser },
|
|
195
|
+
}, enumerable = new Set([
|
|
196
|
+
'normalizeTitle',
|
|
197
|
+
'parse',
|
|
198
|
+
/* NOT FOR BROWSER */
|
|
194
199
|
'conversionTable',
|
|
195
200
|
'redirects',
|
|
196
201
|
'warning',
|
|
197
202
|
'debugging',
|
|
198
|
-
'normalizeTitle',
|
|
199
|
-
'parse',
|
|
200
203
|
'isInterwiki',
|
|
201
204
|
]);
|
|
202
205
|
for (const key in Parser) {
|
package/dist/lib/element.d.ts
CHANGED
|
@@ -55,11 +55,6 @@ export declare abstract class AstElement extends AstNode {
|
|
|
55
55
|
* @param selector 选择器
|
|
56
56
|
*/
|
|
57
57
|
closest<T = Token>(selector: string): T | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* 符合选择器的所有后代节点
|
|
60
|
-
* @param selector 选择器
|
|
61
|
-
*/
|
|
62
|
-
querySelectorAll<T = Token>(selector: string): T[];
|
|
63
58
|
/**
|
|
64
59
|
* 在末尾批量插入子节点
|
|
65
60
|
* @param elements 插入节点
|
|
@@ -114,6 +109,11 @@ export declare abstract class AstElement extends AstNode {
|
|
|
114
109
|
* @param id id名
|
|
115
110
|
*/
|
|
116
111
|
getElementById<T = Token>(id: string): T | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* 符合选择器的所有后代节点
|
|
114
|
+
* @param selector 选择器
|
|
115
|
+
*/
|
|
116
|
+
querySelectorAll<T = Token>(selector: string): T[];
|
|
117
117
|
/**
|
|
118
118
|
* 类选择器
|
|
119
119
|
* @param className 类名之一
|
package/dist/lib/element.js
CHANGED
|
@@ -4,12 +4,12 @@ exports.AstElement = void 0;
|
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const string_1 = require("../util/string");
|
|
7
|
-
const constants_1 = require("../util/constants");
|
|
8
7
|
const debug_1 = require("../util/debug");
|
|
8
|
+
const constants_1 = require("../util/constants");
|
|
9
9
|
const selector_1 = require("../parser/selector");
|
|
10
10
|
const ranges_1 = require("./ranges");
|
|
11
11
|
const title_1 = require("./title");
|
|
12
|
-
const
|
|
12
|
+
const index_1 = require("../index");
|
|
13
13
|
const node_1 = require("./node");
|
|
14
14
|
/**
|
|
15
15
|
* optionally convert to lower cases
|
|
@@ -134,7 +134,9 @@ class AstElement extends node_1.AstNode {
|
|
|
134
134
|
* @param i 移除位置
|
|
135
135
|
*/
|
|
136
136
|
removeAt(i) {
|
|
137
|
+
/* NOT FOR BROWSER */
|
|
137
138
|
this.verifyChild(i);
|
|
139
|
+
/* NOT FOR BROWSER END */
|
|
138
140
|
return (0, debug_1.setChildNodes)(this, i, 1)[0];
|
|
139
141
|
}
|
|
140
142
|
/**
|
|
@@ -144,6 +146,7 @@ class AstElement extends node_1.AstNode {
|
|
|
144
146
|
* @throws `RangeError` 不能插入祖先或子节点
|
|
145
147
|
*/
|
|
146
148
|
insertAt(node, i = this.length) {
|
|
149
|
+
/* NOT FOR BROWSER */
|
|
147
150
|
if (node.contains(this)) {
|
|
148
151
|
throw new RangeError('不能插入祖先节点!');
|
|
149
152
|
}
|
|
@@ -152,6 +155,7 @@ class AstElement extends node_1.AstNode {
|
|
|
152
155
|
}
|
|
153
156
|
this.verifyChild(i, 1);
|
|
154
157
|
node.parentNode?.removeChild(node);
|
|
158
|
+
/* NOT FOR BROWSER END */
|
|
155
159
|
(0, debug_1.setChildNodes)(this, i, 0, [node]);
|
|
156
160
|
return node;
|
|
157
161
|
}
|
|
@@ -161,11 +165,13 @@ class AstElement extends node_1.AstNode {
|
|
|
161
165
|
*/
|
|
162
166
|
#getCondition(selector) {
|
|
163
167
|
let condition;
|
|
168
|
+
/* NOT FOR BROWSER */
|
|
164
169
|
if (/[^a-z\-,\s]/u.test(selector)) {
|
|
165
170
|
const stack = (0, selector_1.parseSelector)(selector);
|
|
166
171
|
condition = (token => stack.some(copy => token.#matchesArray(copy)));
|
|
167
172
|
}
|
|
168
173
|
else {
|
|
174
|
+
/* NOT FOR BROWSER END */
|
|
169
175
|
const types = new Set(selector.split(',').map(str => str.trim()));
|
|
170
176
|
condition = (token => types.has(token.type));
|
|
171
177
|
}
|
|
@@ -186,31 +192,6 @@ class AstElement extends node_1.AstNode {
|
|
|
186
192
|
}
|
|
187
193
|
return undefined;
|
|
188
194
|
}
|
|
189
|
-
/**
|
|
190
|
-
* 符合条件的所有后代节点
|
|
191
|
-
* @param condition 条件
|
|
192
|
-
*/
|
|
193
|
-
#getElementsBy(condition) {
|
|
194
|
-
const descendants = [];
|
|
195
|
-
for (const child of this.childNodes) {
|
|
196
|
-
if (child.type === 'text') {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
else if (condition(child)) {
|
|
200
|
-
descendants.push(child);
|
|
201
|
-
}
|
|
202
|
-
descendants.push(...child.#getElementsBy(condition));
|
|
203
|
-
}
|
|
204
|
-
return descendants;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* 符合选择器的所有后代节点
|
|
208
|
-
* @param selector 选择器
|
|
209
|
-
*/
|
|
210
|
-
querySelectorAll(selector) {
|
|
211
|
-
const condition = this.#getCondition(selector);
|
|
212
|
-
return this.#getElementsBy(condition);
|
|
213
|
-
}
|
|
214
195
|
/**
|
|
215
196
|
* 在末尾批量插入子节点
|
|
216
197
|
* @param elements 插入节点
|
|
@@ -237,21 +218,24 @@ class AstElement extends node_1.AstNode {
|
|
|
237
218
|
* @throws `RangeError` 对应位置的子节点不是文本节点
|
|
238
219
|
*/
|
|
239
220
|
setText(str, i = 0) {
|
|
240
|
-
this.verifyChild(i);
|
|
241
221
|
i += i < 0 ? this.length : 0;
|
|
242
|
-
|
|
243
|
-
|
|
222
|
+
/* NOT FOR BROWSER */
|
|
223
|
+
this.verifyChild(i);
|
|
224
|
+
/* NOT FOR BROWSER END */
|
|
225
|
+
const oldText = this.childNodes[i];
|
|
226
|
+
/* NOT FOR BROWSER */
|
|
227
|
+
if (oldText.type === 'text') {
|
|
228
|
+
/* NOT FOR BROWSER END */
|
|
244
229
|
const { data } = oldText;
|
|
245
230
|
oldText.replaceData(str);
|
|
246
231
|
return data;
|
|
247
232
|
}
|
|
248
|
-
|
|
233
|
+
/* NOT FOR BROWSER */
|
|
234
|
+
throw new RangeError(`第 ${i} 个子节点是 ${oldText.constructor.name}!`);
|
|
249
235
|
}
|
|
250
236
|
/** @private */
|
|
251
|
-
toString(
|
|
252
|
-
return
|
|
253
|
-
? ''
|
|
254
|
-
: this.childNodes.map(child => child.toString(omit)).join(separator);
|
|
237
|
+
toString(separator = '') {
|
|
238
|
+
return this.childNodes.map(String).join(separator);
|
|
255
239
|
}
|
|
256
240
|
/**
|
|
257
241
|
* @override
|
|
@@ -282,9 +266,11 @@ class AstElement extends node_1.AstNode {
|
|
|
282
266
|
...this,
|
|
283
267
|
childNodes: this.childNodes.map(child => child.type === 'text' ? { data: child.data } : child.json()),
|
|
284
268
|
};
|
|
269
|
+
/* NOT FOR BROWSER */
|
|
285
270
|
if (typeof file === 'string') {
|
|
286
271
|
fs.writeFileSync(path.join(__dirname.slice(0, -4), '..', 'printed', `${file}${file.endsWith('.json') ? '' : '.json'}`), JSON.stringify(json, null, 2));
|
|
287
272
|
}
|
|
273
|
+
/* NOT FOR BROWSER END */
|
|
288
274
|
return json;
|
|
289
275
|
}
|
|
290
276
|
/* NOT FOR BROWSER */
|
|
@@ -538,6 +524,28 @@ class AstElement extends node_1.AstNode {
|
|
|
538
524
|
getElementById(id) {
|
|
539
525
|
return this.#getElementBy((token => 'id' in token && token.id === id));
|
|
540
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* 符合条件的所有后代节点
|
|
529
|
+
* @param condition 条件
|
|
530
|
+
*/
|
|
531
|
+
#getElementsBy(condition) {
|
|
532
|
+
const descendants = [];
|
|
533
|
+
for (const child of this.children) {
|
|
534
|
+
if (condition(child)) {
|
|
535
|
+
descendants.push(child);
|
|
536
|
+
}
|
|
537
|
+
descendants.push(...child.#getElementsBy(condition));
|
|
538
|
+
}
|
|
539
|
+
return descendants;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* 符合选择器的所有后代节点
|
|
543
|
+
* @param selector 选择器
|
|
544
|
+
*/
|
|
545
|
+
querySelectorAll(selector) {
|
|
546
|
+
const condition = this.#getCondition(selector);
|
|
547
|
+
return this.#getElementsBy(condition);
|
|
548
|
+
}
|
|
541
549
|
/**
|
|
542
550
|
* 类选择器
|
|
543
551
|
* @param className 类名之一
|
|
@@ -603,7 +611,7 @@ class AstElement extends node_1.AstNode {
|
|
|
603
611
|
console.log(`${indent}\x1B[32m<%s>\x1B[0m${(0, string_1.noWrap)(str)}\x1B[32m</%s>\x1B[0m`, type, type);
|
|
604
612
|
return;
|
|
605
613
|
}
|
|
606
|
-
|
|
614
|
+
index_1.default.info(`${indent}<${type}>`);
|
|
607
615
|
let i = this.getAttribute('padding');
|
|
608
616
|
if (i) {
|
|
609
617
|
console.log(`${indent} ${(0, string_1.noWrap)(str.slice(0, i))}`);
|
|
@@ -628,7 +636,7 @@ class AstElement extends node_1.AstNode {
|
|
|
628
636
|
if (i < str.length) {
|
|
629
637
|
console.log(`${indent} ${(0, string_1.noWrap)(str.slice(i))}`);
|
|
630
638
|
}
|
|
631
|
-
|
|
639
|
+
index_1.default.info(`${indent}</${type}>`);
|
|
632
640
|
}
|
|
633
641
|
}
|
|
634
642
|
exports.AstElement = AstElement;
|
package/dist/lib/node.js
CHANGED
|
@@ -105,9 +105,11 @@ class AstNode {
|
|
|
105
105
|
getAttribute(key) {
|
|
106
106
|
if (key === 'padding') {
|
|
107
107
|
return 0;
|
|
108
|
+
/* NOT FOR BROWSER */
|
|
108
109
|
}
|
|
109
110
|
else if (key === 'optional') {
|
|
110
111
|
return new Set(this.#optional);
|
|
112
|
+
/* NOT FOR BROWSER END */
|
|
111
113
|
}
|
|
112
114
|
return key in this
|
|
113
115
|
? String(this[key])
|
|
@@ -117,6 +119,7 @@ class AstNode {
|
|
|
117
119
|
setAttribute(key, value) {
|
|
118
120
|
if (key === 'parentNode') {
|
|
119
121
|
this.#parentNode = value;
|
|
122
|
+
/* NOT FOR BROWSER */
|
|
120
123
|
}
|
|
121
124
|
else if (Object.prototype.hasOwnProperty.call(this, key)) {
|
|
122
125
|
const descriptor = Object.getOwnPropertyDescriptor(this, key);
|
|
@@ -128,6 +131,7 @@ class AstNode {
|
|
|
128
131
|
if (frozen && typeof value === 'object') {
|
|
129
132
|
Object.freeze(value);
|
|
130
133
|
}
|
|
134
|
+
/* NOT FOR BROWSER END */
|
|
131
135
|
}
|
|
132
136
|
else {
|
|
133
137
|
this[key] = value; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
@@ -184,7 +188,9 @@ class AstNode {
|
|
|
184
188
|
}
|
|
185
189
|
return 0;
|
|
186
190
|
}
|
|
191
|
+
/* NOT FOR BROWSER */
|
|
187
192
|
this.verifyChild(j, 1);
|
|
193
|
+
/* NOT FOR BROWSER END */
|
|
188
194
|
({ childNodes } = this);
|
|
189
195
|
return getIndex(j, this);
|
|
190
196
|
}
|
package/dist/lib/text.js
CHANGED
|
@@ -3,9 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AstText = void 0;
|
|
4
4
|
const constants_1 = require("../util/constants");
|
|
5
5
|
const debug_1 = require("../util/debug");
|
|
6
|
-
const
|
|
6
|
+
const index_1 = require("../index");
|
|
7
7
|
const node_1 = require("./node");
|
|
8
|
-
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
9
|
+
/<\s*(?:\/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu;
|
|
10
|
+
const source = '<\\s*(?:\\/\\s*)?([a-z]\\w*)' // 疑似标签
|
|
11
|
+
+ '|'
|
|
12
|
+
+ '\\{+|\\}+' // `{`、`}`
|
|
13
|
+
+ '|'
|
|
14
|
+
+ '\\[{2,}|\\[(?![^[]*?\\])' // `[`
|
|
15
|
+
+ '|'
|
|
16
|
+
+ '((?:^|\\])[^[]*?)\\]+', // `]`
|
|
17
|
+
errorSyntax = new RegExp(`${source}|https?[:/]\\/+`, 'giu'), errorSyntaxUrl = new RegExp(source, 'giu'), regexes = {
|
|
18
|
+
'[': /[[\]]/u,
|
|
19
|
+
'{': /[{}]/u,
|
|
20
|
+
']': /[[\]](?=[^[\]]*$)/u,
|
|
21
|
+
'}': /[{}](?=[^{}]*$)/u,
|
|
22
|
+
}, disallowedTags = [
|
|
9
23
|
'html',
|
|
10
24
|
'base',
|
|
11
25
|
'head',
|
|
@@ -73,8 +87,10 @@ class AstText extends node_1.AstNode {
|
|
|
73
87
|
Object.defineProperties(this, {
|
|
74
88
|
data: {
|
|
75
89
|
value: text,
|
|
90
|
+
/* NOT FOR BROWSER */
|
|
76
91
|
writable: false,
|
|
77
92
|
},
|
|
93
|
+
/* NOT FOR BROWSER */
|
|
78
94
|
childNodes: { enumerable: false, configurable: false },
|
|
79
95
|
type: { enumerable: false, writable: false },
|
|
80
96
|
});
|
|
@@ -94,11 +110,13 @@ class AstText extends node_1.AstNode {
|
|
|
94
110
|
*/
|
|
95
111
|
lint(start = this.getAbsoluteIndex()) {
|
|
96
112
|
const { data, parentNode, nextSibling, previousSibling } = this;
|
|
113
|
+
/* NOT FOR BROWSER */
|
|
97
114
|
if (!parentNode) {
|
|
98
115
|
throw new Error('无法对孤立文本节点进行语法分析!');
|
|
99
116
|
}
|
|
117
|
+
/* NOT FOR BROWSER END */
|
|
100
118
|
const { NowikiToken } = require('../src/nowiki');
|
|
101
|
-
const { type, name } = parentNode, nowiki = name === 'nowiki' || name === 'pre'
|
|
119
|
+
const { type, name } = parentNode, nowiki = name === 'nowiki' || name === 'pre';
|
|
102
120
|
let errorRegex;
|
|
103
121
|
if (type === 'ext-inner' && (name === 'pre' || parentNode instanceof NowikiToken)) {
|
|
104
122
|
errorRegex = new RegExp(`<\\s*(?:\\/\\s*)${nowiki ? '' : '?'}(${name})\\b`, 'giu');
|
|
@@ -112,61 +130,84 @@ class AstText extends node_1.AstNode {
|
|
|
112
130
|
else {
|
|
113
131
|
errorRegex = errorSyntax;
|
|
114
132
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
133
|
+
if (data.search(errorRegex) === -1) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
errorRegex.lastIndex = 0;
|
|
137
|
+
const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), { ext, html } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), tags = new Set(['onlyinclude', 'noinclude', 'includeonly', ext, html, disallowedTags].flat(2));
|
|
138
|
+
for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
|
|
139
|
+
const [, tag, prefix] = mt;
|
|
140
|
+
let { 0: error, index } = mt;
|
|
141
|
+
if (prefix && prefix !== ']') {
|
|
142
|
+
const { length } = prefix;
|
|
143
|
+
index += length;
|
|
144
|
+
error = error.slice(length);
|
|
145
|
+
}
|
|
146
|
+
const { 0: char, length } = error;
|
|
147
|
+
if (char === '<' && !tags.has(tag.toLowerCase())
|
|
148
|
+
|| char === '['
|
|
129
149
|
&& type === 'ext-link-text'
|
|
130
150
|
&& (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
131
151
|
|| nextType === 'ext'
|
|
132
152
|
&& nextName === 'nowiki'
|
|
133
153
|
&& nextSibling.innerText?.includes(']'))) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
else if (char === ']' && (index || length > 1)) {
|
|
157
|
+
errorRegex.lastIndex--;
|
|
158
|
+
}
|
|
159
|
+
const startIndex = start + index, endIndex = startIndex + length, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || !nowiki && /[\s/>]/u.test(nextChar ?? ''))
|
|
160
|
+
|| char === '{' && (nextChar === char || previousChar === '-')
|
|
161
|
+
|| char === '}' && (previousChar === char || nextChar === '-')
|
|
162
|
+
|| char === '[' && (nextChar === char
|
|
163
|
+
|| type === 'ext-link-text'
|
|
164
|
+
|| !data.slice(index + 1).trim() && nextType === 'free-ext-link')
|
|
165
|
+
|| char === ']' && (previousChar === char
|
|
166
|
+
|| !data.slice(0, index).trim() && previousType === 'free-ext-link')
|
|
167
|
+
? 'error'
|
|
168
|
+
: 'warning';
|
|
169
|
+
const leftBracket = char === '{' || char === '[', rightBracket = char === ']' || char === '}';
|
|
170
|
+
if (severity === 'warning' && (leftBracket || rightBracket)) {
|
|
171
|
+
const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
|
|
172
|
+
if (char === '{' && regex.exec(remains)?.[0] === '}'
|
|
173
|
+
|| char === '}' && regex.exec(remains)?.[0] === '{') {
|
|
134
174
|
continue;
|
|
135
175
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
: 'warning';
|
|
146
|
-
if (char !== '<' || tags.has(tag.toLowerCase())) {
|
|
147
|
-
errors.push({
|
|
148
|
-
message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
|
|
149
|
-
severity,
|
|
150
|
-
startIndex,
|
|
151
|
-
endIndex,
|
|
152
|
-
startLine,
|
|
153
|
-
endLine: startLine,
|
|
154
|
-
startCol,
|
|
155
|
-
endCol: startCol + length,
|
|
156
|
-
});
|
|
176
|
+
else if (!remains.includes(char)) {
|
|
177
|
+
const sibling = leftBracket ? 'nextSibling' : 'previousSibling';
|
|
178
|
+
let cur = this[sibling];
|
|
179
|
+
while (cur && (cur.type !== 'text' || !regex.test(cur.data))) {
|
|
180
|
+
cur = cur[sibling];
|
|
181
|
+
}
|
|
182
|
+
if (cur && regex.exec(cur.data)[0] !== char) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
157
185
|
}
|
|
158
186
|
}
|
|
159
|
-
|
|
187
|
+
const lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines[lines.length - 1], startCol = lines.length === 1 ? left + line.length : line.length;
|
|
188
|
+
errors.push({
|
|
189
|
+
message: index_1.default.msg('lonely "$1"', char === 'h' ? error : char),
|
|
190
|
+
severity,
|
|
191
|
+
startIndex,
|
|
192
|
+
endIndex,
|
|
193
|
+
startLine,
|
|
194
|
+
endLine: startLine,
|
|
195
|
+
startCol,
|
|
196
|
+
endCol: startCol + length,
|
|
197
|
+
});
|
|
160
198
|
}
|
|
161
|
-
return
|
|
199
|
+
return errors;
|
|
162
200
|
}
|
|
163
201
|
/**
|
|
164
202
|
* 修改内容
|
|
165
203
|
* @param text 新内容
|
|
166
204
|
*/
|
|
167
205
|
#setData(text) {
|
|
206
|
+
/* NOT FOR BROWSER */
|
|
168
207
|
const { data } = this, e = new Event('text', { bubbles: true });
|
|
208
|
+
/* NOT FOR BROWSER END */
|
|
169
209
|
this.setAttribute('data', text);
|
|
210
|
+
/* NOT FOR BROWSER */
|
|
170
211
|
if (data !== text) {
|
|
171
212
|
this.dispatchEvent(e, { type: 'text', oldText: data });
|
|
172
213
|
}
|
package/dist/lib/title.d.ts
CHANGED
package/dist/lib/title.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Title = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
5
|
const constants_1 = require("../util/constants");
|
|
6
|
-
const
|
|
6
|
+
const index_1 = require("../index");
|
|
7
7
|
/** MediaWiki页面标题对象 */
|
|
8
8
|
class Title {
|
|
9
9
|
valid;
|
|
@@ -60,9 +60,13 @@ class Title {
|
|
|
60
60
|
* @param decode 是否需要解码
|
|
61
61
|
* @param selfLink 是否允许selfLink
|
|
62
62
|
*/
|
|
63
|
-
constructor(title, defaultNs = 0, config =
|
|
64
|
-
const {
|
|
63
|
+
constructor(title, defaultNs = 0, config = index_1.default.getConfig(), decode = false, selfLink = false) {
|
|
64
|
+
const { nsid,
|
|
65
|
+
/* NOT FOR BROWSER */
|
|
66
|
+
namespaces, } = config;
|
|
67
|
+
/* NOT FOR BROWSER */
|
|
65
68
|
this.#namespaces = namespaces;
|
|
69
|
+
/* NOT FOR BROWSER END */
|
|
66
70
|
title = (0, string_1.decodeHtml)(title);
|
|
67
71
|
if (decode && title.includes('%')) {
|
|
68
72
|
try {
|
|
@@ -78,11 +82,13 @@ class Title {
|
|
|
78
82
|
ns = 0;
|
|
79
83
|
title = title.slice(1).trim();
|
|
80
84
|
}
|
|
81
|
-
|
|
85
|
+
/* NOT FOR BROWSER */
|
|
86
|
+
const iw = defaultNs ? null : index_1.default.isInterwiki(title, config);
|
|
82
87
|
if (iw) {
|
|
83
88
|
this.interwiki = iw[1].toLowerCase();
|
|
84
89
|
title = title.slice(iw.indices[0][1]);
|
|
85
90
|
}
|
|
91
|
+
/* NOT FOR BROWSER END */
|
|
86
92
|
const m = title.split(':');
|
|
87
93
|
if (m.length > 1) {
|
|
88
94
|
const id = nsid[m[0].trim().toLowerCase()];
|
|
@@ -111,8 +117,11 @@ class Title {
|
|
|
111
117
|
title = title.slice(0, i).trim();
|
|
112
118
|
}
|
|
113
119
|
this.valid = Boolean(title
|
|
120
|
+
/* NOT FOR BROWSER */
|
|
114
121
|
|| this.interwiki
|
|
122
|
+
/* NOT FOR BROWSER END */
|
|
115
123
|
|| selfLink && this.fragment !== undefined) && !/^:|\0\d+[eh!+-]\x7F|[<>[\]{}|]|%[\da-f]{2}/iu.test(title);
|
|
124
|
+
/* NOT FOR BROWSER */
|
|
116
125
|
this.main = title;
|
|
117
126
|
Object.defineProperties(this, {
|
|
118
127
|
valid: { writable: false },
|
|
@@ -50,7 +50,7 @@ export declare const flagsParent: <T extends AstConstructor>(constructor: T) =>
|
|
|
50
50
|
* @param flag 转换类型标记
|
|
51
51
|
*/
|
|
52
52
|
toggleFlag(flag: string): void;
|
|
53
|
-
toString(
|
|
53
|
+
toString(separator?: string | undefined): string;
|
|
54
54
|
text(separator?: string | undefined): string;
|
|
55
55
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
56
56
|
getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.flagsParent = void 0;
|
|
4
4
|
const constants_1 = require("../util/constants");
|
|
5
|
+
/* NOT FOR BROWSER END */
|
|
5
6
|
/**
|
|
6
7
|
* ConverterToken
|
|
7
8
|
* @param constructor 基类
|
|
@@ -9,6 +10,7 @@ const constants_1 = require("../util/constants");
|
|
|
9
10
|
const flagsParent = (constructor) => {
|
|
10
11
|
/** 子节点含有ConverterFlagsToken的类 */
|
|
11
12
|
class FlagsParent extends constructor {
|
|
13
|
+
/* NOT FOR BROWSER */
|
|
12
14
|
/** 所有转换类型标记 */
|
|
13
15
|
get flags() {
|
|
14
16
|
return this.firstChild.flags;
|
|
@@ -23,7 +23,7 @@ export declare const magicLinkParent: <T extends AstConstructor>(constructor: T)
|
|
|
23
23
|
* @param url 网址
|
|
24
24
|
*/
|
|
25
25
|
setTarget(url: string): void;
|
|
26
|
-
toString(
|
|
26
|
+
toString(separator?: string | undefined): string;
|
|
27
27
|
text(separator?: string | undefined): string;
|
|
28
28
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
29
29
|
getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.magicLinkParent = void 0;
|
|
4
4
|
const constants_1 = require("../util/constants");
|
|
5
|
+
/* NOT FOR BROWSER END */
|
|
5
6
|
/**
|
|
6
7
|
* ExtLinkToken
|
|
7
8
|
* @param constructor 基类
|
|
@@ -9,6 +10,7 @@ const constants_1 = require("../util/constants");
|
|
|
9
10
|
const magicLinkParent = (constructor) => {
|
|
10
11
|
/** 子节点含有MagicLinkParent的类 */
|
|
11
12
|
class MagicLinkParent extends constructor {
|
|
13
|
+
/* NOT FOR BROWSER */
|
|
12
14
|
/** 协议 */
|
|
13
15
|
get protocol() {
|
|
14
16
|
return this.firstChild.protocol;
|
package/dist/mixin/singleLine.js
CHANGED
|
@@ -10,8 +10,8 @@ const singleLine = (constructor) => {
|
|
|
10
10
|
/** 不可包含换行符的类 */
|
|
11
11
|
class SingleLineToken extends constructor {
|
|
12
12
|
/** @private */
|
|
13
|
-
toString(
|
|
14
|
-
return super.toString(
|
|
13
|
+
toString() {
|
|
14
|
+
return super.toString().replace(/\n/gu, ' ');
|
|
15
15
|
}
|
|
16
16
|
/** @override */
|
|
17
17
|
text() {
|
package/dist/mixin/sol.js
CHANGED
|
@@ -21,10 +21,8 @@ const sol = (constructor) => {
|
|
|
21
21
|
: '\n';
|
|
22
22
|
}
|
|
23
23
|
/** @private */
|
|
24
|
-
toString(
|
|
25
|
-
return
|
|
26
|
-
? ''
|
|
27
|
-
: `${this.prependNewLine()}${super.toString(omit)}`;
|
|
24
|
+
toString() {
|
|
25
|
+
return `${this.prependNewLine()}${super.toString()}`;
|
|
28
26
|
}
|
|
29
27
|
/** @private */
|
|
30
28
|
getAttribute(key) {
|