wikiparser-node 0.2.3 → 0.3.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/.eslintrc.json +98 -8
- package/config/default.json +45 -13
- package/config/llwiki.json +11 -11
- package/config/moegirl.json +44 -12
- package/index.js +11 -11
- package/lib/element.js +8 -8
- package/lib/node.js +2 -2
- package/lib/ranges.js +1 -1
- package/lib/title.js +7 -3
- package/mixin/attributeParent.js +2 -2
- package/mixin/fixedToken.js +1 -1
- package/mixin/hidden.js +1 -1
- package/mixin/sol.js +2 -2
- package/package.json +6 -3
- package/parser/brackets.js +11 -6
- package/parser/commentAndExt.js +9 -9
- package/parser/converter.js +5 -5
- package/parser/externalLinks.js +4 -4
- package/parser/hrAndDoubleUnderscore.js +4 -4
- package/parser/html.js +4 -4
- package/parser/links.js +9 -9
- package/parser/list.js +7 -7
- package/parser/magicLinks.js +5 -5
- package/parser/quotes.js +3 -3
- package/parser/table.js +8 -8
- package/src/attribute.js +5 -5
- package/src/converterFlags.js +6 -6
- package/src/converterRule.js +1 -1
- package/src/extLink.js +2 -1
- package/src/gallery.js +59 -11
- package/src/heading.js +1 -1
- package/src/imageParameter.js +5 -5
- package/src/index.js +7 -7
- package/src/link/category.js +1 -1
- package/src/link/file.js +1 -1
- package/src/link/galleryImage.js +47 -0
- package/src/link/index.js +15 -14
- package/src/magicLink.js +14 -4
- package/src/nowiki/dd.js +1 -1
- package/src/syntax.js +3 -0
- package/src/table/index.js +7 -7
- package/src/table/td.js +18 -15
- package/src/table/tr.js +4 -4
- package/src/tagPair/ext.js +11 -3
- package/src/transclude.js +9 -7
- package/util/debug.js +1 -1
- package/util/string.js +7 -7
- package/errors/2022-12-07T10:07:09.577Z +0 -1
- package/errors/2022-12-07T10:07:09.577Z.err +0 -11
- package/errors/2022-12-07T10:07:09.577Z.json +0 -5
- package/errors/2022-12-07T10:22:31.325Z +0 -1
- package/errors/2022-12-07T10:22:31.325Z.err +0 -11
- package/errors/2022-12-07T10:22:31.325Z.json +0 -5
package/src/transclude.js
CHANGED
|
@@ -59,7 +59,7 @@ class TranscludeToken extends Token {
|
|
|
59
59
|
isSensitive = sensitive.includes(name);
|
|
60
60
|
if (isSensitive || insensitive.includes(name.toLowerCase())) {
|
|
61
61
|
this.setAttribute('name', name.toLowerCase().replace(/^#/, '')).type = 'magic-word';
|
|
62
|
-
const pattern =
|
|
62
|
+
const pattern = RegExp(`^\\s*${name}\\s*$`, isSensitive ? '' : 'i'),
|
|
63
63
|
token = new SyntaxToken(magicWord, pattern, 'magic-word-name', config, accum, {
|
|
64
64
|
'Stage-1': ':', '!ExtToken': '',
|
|
65
65
|
});
|
|
@@ -85,7 +85,7 @@ class TranscludeToken extends Token {
|
|
|
85
85
|
}
|
|
86
86
|
if (this.type === 'template') {
|
|
87
87
|
const [name] = removeComment(title).split('#');
|
|
88
|
-
if (/\
|
|
88
|
+
if (/\0\d+[eh!+-]\x7f|[<>[\]{}]/.test(name)) {
|
|
89
89
|
accum.pop();
|
|
90
90
|
throw new SyntaxError(`非法的模板名称:${name}`);
|
|
91
91
|
}
|
|
@@ -123,7 +123,7 @@ class TranscludeToken extends Token {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
afterBuild() {
|
|
126
|
-
if (this.name.includes('\
|
|
126
|
+
if (this.name.includes('\0')) {
|
|
127
127
|
this.setAttribute('name', text(this.buildFromStr(this.name)));
|
|
128
128
|
}
|
|
129
129
|
if (this.matches('template, magic-word#invoke')) {
|
|
@@ -470,7 +470,9 @@ class TranscludeToken extends Token {
|
|
|
470
470
|
} else if (this.childNodes.length < 2) {
|
|
471
471
|
throw new Error('尚未指定模块名称!');
|
|
472
472
|
}
|
|
473
|
-
const root = Parser.parse(
|
|
473
|
+
const root = Parser.parse(
|
|
474
|
+
`{{#invoke:M|${func}}}`, this.getAttribute('include'), 2, this.getAttribute('config'),
|
|
475
|
+
),
|
|
474
476
|
{childNodes: {length}, firstElementChild} = root;
|
|
475
477
|
if (length !== 1 || !firstElementChild?.matches('magic-word#invoke')
|
|
476
478
|
|| firstElementChild.childNodes.length !== 3
|
|
@@ -553,8 +555,8 @@ class TranscludeToken extends Token {
|
|
|
553
555
|
continue;
|
|
554
556
|
} else if (aggressive && (anonCount ? /\D\d+$/ : /(?:^|\D)\d+$/).test(key)) {
|
|
555
557
|
let /** @type {number} */ last;
|
|
556
|
-
const str = key.slice(0,
|
|
557
|
-
regex =
|
|
558
|
+
const str = key.slice(0, -/(?<!\d)\d+$/.exec(key)[0].length),
|
|
559
|
+
regex = RegExp(`^${escapeRegExp(str)}\\d+$`),
|
|
558
560
|
series = this.getAllArgs().filter(({name}) => regex.test(name)),
|
|
559
561
|
ordered = series.every(({name}, i) => {
|
|
560
562
|
const j = Number(name.slice(str.length)),
|
|
@@ -595,7 +597,7 @@ class TranscludeToken extends Token {
|
|
|
595
597
|
*/
|
|
596
598
|
escapeTables() {
|
|
597
599
|
const count = this.hasDuplicatedArgs();
|
|
598
|
-
if (!/\n\s
|
|
600
|
+
if (!/\n[^\S\n]*(?::+\s*)?\{\|[^\n]*\n\s*(?:\S[^\n]*\n\s*)*\|\}/.test(this.text()) || !count) {
|
|
599
601
|
return this;
|
|
600
602
|
}
|
|
601
603
|
const stripped = this.toString().slice(2, -2),
|
package/util/debug.js
CHANGED
|
@@ -17,7 +17,7 @@ const externalUse = (name, proxy = false) => {
|
|
|
17
17
|
if (!proxy && require('..').running) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
const regex =
|
|
20
|
+
const regex = RegExp(`^${
|
|
21
21
|
proxy ? 'Proxy' : 'new \\w*Token$|^(?:AstNode|AstElement|\\w*Token)'
|
|
22
22
|
}\\.(?!${name}$)`);
|
|
23
23
|
try {
|
package/util/string.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* optionally convert to lower cases
|
|
5
5
|
* @param {string} val
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {string|undefined} i
|
|
7
7
|
*/
|
|
8
8
|
const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
|
11
11
|
* remove half-parsed comment-like tokens
|
|
12
12
|
* @param {string} str
|
|
13
13
|
*/
|
|
14
|
-
const removeComment = str => str.replace(/\
|
|
14
|
+
const removeComment = str => str.replace(/\0\d+c\x7f/g, '');
|
|
15
15
|
|
|
16
16
|
/** @param {string} str */
|
|
17
17
|
const ucfirst = str => str && `${str[0].toUpperCase()}${str.slice(1)}`;
|
|
@@ -21,7 +21,7 @@ const escapeRegExp = str => str.replace(/[\\{}()|.?*+\-^$[\]]/g, '\\$&');
|
|
|
21
21
|
|
|
22
22
|
/** @param {(string|AstNode)[]} childNodes */
|
|
23
23
|
const text = (childNodes, separator = '') => {
|
|
24
|
-
const AstNode = require('../lib/node');
|
|
24
|
+
const AstNode = require('../lib/node');
|
|
25
25
|
return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -35,7 +35,7 @@ const explode = (start, end, separator, str) => {
|
|
|
35
35
|
if (str === undefined) {
|
|
36
36
|
return [];
|
|
37
37
|
}
|
|
38
|
-
const regex =
|
|
38
|
+
const regex = RegExp(`${[start, end, separator].map(escapeRegExp).join('|')}`, 'g'),
|
|
39
39
|
/** @type {string[]} */ exploded = [];
|
|
40
40
|
let mt = regex.exec(str),
|
|
41
41
|
depth = 0,
|
|
@@ -62,14 +62,14 @@ const noWrap = str => str.replaceAll('\n', '\\n');
|
|
|
62
62
|
* @returns {string}
|
|
63
63
|
*/
|
|
64
64
|
const normalizeSpace = (token = '', separator = '') => {
|
|
65
|
-
const Token = require('../src');
|
|
65
|
+
const Token = require('../src');
|
|
66
66
|
return typeof token === 'string'
|
|
67
67
|
? token.replaceAll('\n', ' ')
|
|
68
68
|
: token.childNodes.map(child => typeof child === 'string' ? normalizeSpace(child) : child.toString())
|
|
69
69
|
.join(separator);
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
const extUrlChar = '(
|
|
73
|
-
+ '(?:[^[\\]<>"\\
|
|
72
|
+
const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1f\\x7f\\p{Zs}\\ufffd])'
|
|
73
|
+
+ '(?:[^[\\]<>"\\0-\\x1f\\x7f\\p{Zs}\\ufffd]|\\0\\d+c\\x7f)*';
|
|
74
74
|
|
|
75
75
|
module.exports = {toCase, removeComment, ucfirst, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<!---->:
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Error: ListToken 不可删除元素!
|
|
2
|
-
at ListToken.removeAt (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/mixin/fixedToken.js:14:9)
|
|
3
|
-
at ListToken.replaceChildren (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/lib/element.js:232:9)
|
|
4
|
-
at ListToken.build (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:500:8)
|
|
5
|
-
at Token.build (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:504:11)
|
|
6
|
-
at Token.parse (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:533:19)
|
|
7
|
-
at /Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/index.js:135:11
|
|
8
|
-
at Object.run (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/index.js:33:19)
|
|
9
|
-
at Object.parse (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/index.js:125:8)
|
|
10
|
-
at REPL8:1:10
|
|
11
|
-
at Script.runInThisContext (node:vm:130:12)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<!---->:
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Error: ListToken 不可删除元素!
|
|
2
|
-
at ListToken.removeAt (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/mixin/fixedToken.js:14:9)
|
|
3
|
-
at ListToken.replaceChildren (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/lib/element.js:232:9)
|
|
4
|
-
at ListToken.build (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:500:8)
|
|
5
|
-
at Token.build (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:504:11)
|
|
6
|
-
at Token.parse (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:533:19)
|
|
7
|
-
at /Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/index.js:135:11
|
|
8
|
-
at Object.run (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/index.js:33:19)
|
|
9
|
-
at Object.parse (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/index.js:125:8)
|
|
10
|
-
at REPL68:1:10
|
|
11
|
-
at Script.runInThisContext (node:vm:130:12)
|