wikiparser-node 0.5.0 → 0.6.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 +129 -66
- package/config/zhwiki.json +4 -4
- package/index.js +74 -65
- package/lib/element.js +125 -152
- package/lib/node.js +251 -223
- package/lib/ranges.js +2 -2
- package/lib/text.js +64 -64
- package/lib/title.js +8 -7
- package/mixin/hidden.js +2 -0
- package/mixin/sol.js +1 -2
- package/package.json +4 -3
- package/parser/brackets.js +8 -2
- package/parser/externalLinks.js +1 -1
- package/parser/hrAndDoubleUnderscore.js +4 -4
- package/parser/links.js +7 -7
- package/parser/table.js +12 -10
- package/src/arg.js +53 -48
- package/src/atom/index.js +7 -5
- package/src/attribute.js +91 -80
- package/src/charinsert.js +91 -0
- package/src/converter.js +22 -11
- package/src/converterFlags.js +72 -62
- package/src/converterRule.js +49 -49
- package/src/extLink.js +30 -28
- package/src/gallery.js +56 -32
- package/src/hasNowiki/index.js +42 -0
- package/src/hasNowiki/pre.js +40 -0
- package/src/heading.js +15 -11
- package/src/html.js +38 -38
- package/src/imageParameter.js +64 -48
- package/src/imagemap.js +205 -0
- package/src/imagemapLink.js +43 -0
- package/src/index.js +222 -124
- package/src/link/category.js +4 -8
- package/src/link/file.js +95 -59
- package/src/link/galleryImage.js +74 -10
- package/src/link/index.js +61 -39
- package/src/magicLink.js +21 -22
- package/src/nested/choose.js +24 -0
- package/src/nested/combobox.js +23 -0
- package/src/nested/index.js +88 -0
- package/src/nested/references.js +23 -0
- package/src/nowiki/comment.js +17 -17
- package/src/nowiki/dd.js +2 -2
- package/src/nowiki/doubleUnderscore.js +14 -14
- package/src/nowiki/index.js +12 -0
- package/src/onlyinclude.js +10 -8
- package/src/paramTag/index.js +83 -0
- package/src/paramTag/inputbox.js +42 -0
- package/src/parameter.js +32 -18
- package/src/syntax.js +9 -1
- package/src/table/index.js +33 -32
- package/src/table/td.js +51 -57
- package/src/table/tr.js +6 -6
- package/src/tagPair/ext.js +58 -40
- package/src/tagPair/include.js +1 -1
- package/src/tagPair/index.js +21 -20
- package/src/transclude.js +158 -143
- package/tool/index.js +720 -439
- package/util/base.js +17 -0
- package/util/debug.js +1 -1
- package/util/diff.js +1 -1
- package/util/string.js +20 -20
package/util/base.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 是否是普通对象
|
|
5
|
+
* @param {*} obj 对象
|
|
6
|
+
*/
|
|
7
|
+
const isPlainObject = obj => Boolean(obj) && Object.getPrototypeOf(obj).constructor === Object;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 延时
|
|
11
|
+
* @param {number} t 秒数
|
|
12
|
+
*/
|
|
13
|
+
const sleep = t => new Promise(resolve => {
|
|
14
|
+
setTimeout(resolve, t * 1000);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
module.exports = {isPlainObject, sleep};
|
package/util/debug.js
CHANGED
package/util/diff.js
CHANGED
package/util/string.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @param {string} val 属性值
|
|
6
|
-
* @param {string|undefined} i 是否对大小写不敏感
|
|
7
|
-
*/
|
|
8
|
-
const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
3
|
+
const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])'
|
|
4
|
+
+ '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* remove half-parsed comment-like tokens
|
|
@@ -36,16 +32,6 @@ const print = (childNodes, opt = {}) => {
|
|
|
36
32
|
*/
|
|
37
33
|
const escapeRegExp = str => str.replaceAll(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
|
|
38
34
|
|
|
39
|
-
/**
|
|
40
|
-
* extract effective wikitext
|
|
41
|
-
* @param {(string|AstNode)[]} childNodes a Token's contents
|
|
42
|
-
* @param {string} separator delimiter between nodes
|
|
43
|
-
*/
|
|
44
|
-
const text = (childNodes, separator = '') => {
|
|
45
|
-
const AstNode = require('../lib/node');
|
|
46
|
-
return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
35
|
/**
|
|
50
36
|
* a more sophisticated string-explode function
|
|
51
37
|
* @param {string} start start syntax of a nested AST node
|
|
@@ -76,6 +62,23 @@ const explode = (start, end, separator, str) => {
|
|
|
76
62
|
return exploded;
|
|
77
63
|
};
|
|
78
64
|
|
|
65
|
+
/**
|
|
66
|
+
* optionally convert to lower cases
|
|
67
|
+
* @param {string} val 属性值
|
|
68
|
+
* @param {string|undefined} i 是否对大小写不敏感
|
|
69
|
+
*/
|
|
70
|
+
const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* extract effective wikitext
|
|
74
|
+
* @param {(string|AstNode)[]} childNodes a Token's contents
|
|
75
|
+
* @param {string} separator delimiter between nodes
|
|
76
|
+
*/
|
|
77
|
+
const text = (childNodes, separator = '') => {
|
|
78
|
+
const AstNode = require('../lib/node');
|
|
79
|
+
return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
80
|
+
};
|
|
81
|
+
|
|
79
82
|
/**
|
|
80
83
|
* escape newlines
|
|
81
84
|
* @param {string} str 原字符串
|
|
@@ -99,7 +102,4 @@ const normalizeSpace = token => {
|
|
|
99
102
|
}
|
|
100
103
|
};
|
|
101
104
|
|
|
102
|
-
|
|
103
|
-
+ '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
|
|
104
|
-
|
|
105
|
-
module.exports = {toCase, removeComment, print, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};
|
|
105
|
+
module.exports = {extUrlChar, removeComment, print, escapeRegExp, explode, toCase, text, noWrap, normalizeSpace};
|