wikiparser-node 0.4.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 +97 -65
- package/lib/element.js +159 -302
- package/lib/node.js +384 -198
- package/lib/ranges.js +3 -4
- package/lib/text.js +65 -36
- package/lib/title.js +9 -8
- package/mixin/fixedToken.js +4 -4
- package/mixin/hidden.js +2 -0
- package/mixin/sol.js +16 -7
- package/package.json +14 -3
- package/parser/brackets.js +8 -2
- package/parser/commentAndExt.js +1 -1
- package/parser/converter.js +1 -1
- package/parser/externalLinks.js +2 -2
- package/parser/hrAndDoubleUnderscore.js +8 -7
- package/parser/links.js +8 -9
- package/parser/magicLinks.js +1 -1
- package/parser/selector.js +5 -5
- package/parser/table.js +18 -16
- package/src/arg.js +71 -42
- package/src/atom/index.js +7 -5
- package/src/attribute.js +102 -64
- package/src/charinsert.js +91 -0
- package/src/converter.js +34 -15
- package/src/converterFlags.js +87 -40
- package/src/converterRule.js +59 -53
- package/src/extLink.js +45 -37
- package/src/gallery.js +71 -16
- package/src/hasNowiki/index.js +42 -0
- package/src/hasNowiki/pre.js +40 -0
- package/src/heading.js +41 -18
- package/src/html.js +76 -48
- package/src/imageParameter.js +73 -51
- package/src/imagemap.js +205 -0
- package/src/imagemapLink.js +43 -0
- package/src/index.js +243 -138
- package/src/link/category.js +10 -14
- package/src/link/file.js +112 -56
- package/src/link/galleryImage.js +74 -10
- package/src/link/index.js +86 -61
- package/src/magicLink.js +48 -21
- 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 +18 -4
- package/src/nowiki/dd.js +2 -2
- package/src/nowiki/doubleUnderscore.js +16 -11
- package/src/nowiki/index.js +12 -0
- package/src/nowiki/quote.js +28 -1
- package/src/onlyinclude.js +15 -8
- package/src/paramTag/index.js +83 -0
- package/src/paramTag/inputbox.js +42 -0
- package/src/parameter.js +73 -46
- package/src/syntax.js +9 -1
- package/src/table/index.js +58 -44
- package/src/table/td.js +63 -63
- package/src/table/tr.js +52 -35
- package/src/tagPair/ext.js +60 -43
- package/src/tagPair/include.js +11 -1
- package/src/tagPair/index.js +29 -20
- package/src/transclude.js +214 -166
- package/tool/index.js +720 -439
- package/util/base.js +17 -0
- package/util/debug.js +1 -1
- package/{test/util.js → util/diff.js} +15 -19
- package/util/lint.js +40 -0
- package/util/string.js +37 -20
- package/.eslintrc.json +0 -714
- package/errors/README +0 -1
- package/jsconfig.json +0 -7
- package/printed/README +0 -1
- package/printed/example.json +0 -120
- package/test/api.js +0 -83
- package/test/real.js +0 -133
- package/test/test.js +0 -28
- package/typings/api.d.ts +0 -13
- package/typings/array.d.ts +0 -28
- package/typings/event.d.ts +0 -24
- package/typings/index.d.ts +0 -94
- package/typings/node.d.ts +0 -29
- package/typings/parser.d.ts +0 -16
- package/typings/table.d.ts +0 -14
- package/typings/token.d.ts +0 -22
- package/typings/tool.d.ts +0 -11
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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
|
|
2
3
|
const {spawn} = require('child_process'),
|
|
3
4
|
fs = require('fs/promises');
|
|
4
5
|
|
|
@@ -17,7 +18,7 @@ const cmd = (command, args) => new Promise(resolve => {
|
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* 清除进程并返回
|
|
20
|
-
* @param {
|
|
21
|
+
* @param {*} val 返回值
|
|
21
22
|
*/
|
|
22
23
|
const r = val => {
|
|
23
24
|
clearTimeout(timer);
|
|
@@ -49,32 +50,27 @@ const cmd = (command, args) => new Promise(resolve => {
|
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
* 比较两个文件
|
|
52
|
-
* @param {string}
|
|
53
|
-
* @param {string}
|
|
53
|
+
* @param {string} oldStr 旧文本
|
|
54
|
+
* @param {string} newStr 新文本
|
|
55
|
+
* @param {string} uid 唯一标识
|
|
54
56
|
*/
|
|
55
|
-
const diff = async (
|
|
56
|
-
if (
|
|
57
|
+
const diff = async (oldStr, newStr, uid = '') => {
|
|
58
|
+
if (oldStr === newStr) {
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
|
-
|
|
61
|
+
const oldFile = `diffOld${uid}`,
|
|
62
|
+
newFile = `diffNew${uid}`;
|
|
63
|
+
await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
|
|
60
64
|
const stdout = await cmd('git', [
|
|
61
65
|
'diff',
|
|
62
|
-
'--color-words=[\
|
|
66
|
+
'--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
|
|
63
67
|
'-U0',
|
|
64
68
|
'--no-index',
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
oldFile,
|
|
70
|
+
newFile,
|
|
67
71
|
]);
|
|
68
|
-
await Promise.all([fs.unlink(
|
|
72
|
+
await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
|
|
69
73
|
console.log(stdout?.split('\n')?.slice(4)?.join('\n'));
|
|
70
74
|
};
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
* 延时
|
|
74
|
-
* @param {number} t 秒数
|
|
75
|
-
*/
|
|
76
|
-
const sleep = t => new Promise(resolve => {
|
|
77
|
-
setTimeout(resolve, t * 1000);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
module.exports = {diff, sleep};
|
|
76
|
+
module.exports = diff;
|
package/util/lint.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Token = require('../src');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 生成对于子节点的LintError对象
|
|
7
|
+
* @param {Token} child 子节点
|
|
8
|
+
* @param {{top: number, left: number}} boundingRect 父节点的绝对定位
|
|
9
|
+
* @param {string} message 错误信息
|
|
10
|
+
* @param {'error'|'warning'} severity 严重程度
|
|
11
|
+
* @returns {LintError}
|
|
12
|
+
*/
|
|
13
|
+
const generateForChild = (child, boundingRect, message, severity = 'error') => {
|
|
14
|
+
const {style: {top: offsetTop, left: offsetLeft, height, width}} = child,
|
|
15
|
+
{top, left} = boundingRect,
|
|
16
|
+
startLine = top + offsetTop,
|
|
17
|
+
endLine = startLine + height - 1,
|
|
18
|
+
startCol = offsetTop ? offsetLeft : left + offsetLeft,
|
|
19
|
+
endCol = height > 1 ? width : startCol + width;
|
|
20
|
+
return {message, severity, startLine, endLine, startCol, endCol};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 生成对于自己的LintError对象
|
|
25
|
+
* @param {Token} token 节点
|
|
26
|
+
* @param {{top: number, left: number}} boundingRect 绝对定位
|
|
27
|
+
* @param {string} message 错误信息
|
|
28
|
+
* @param {'error'|'warning'} severity 严重程度
|
|
29
|
+
* @returns {LintError}
|
|
30
|
+
*/
|
|
31
|
+
const generateForSelf = (token, boundingRect, message, severity = 'error') => ({
|
|
32
|
+
message,
|
|
33
|
+
severity,
|
|
34
|
+
startLine: boundingRect.top,
|
|
35
|
+
endLine: boundingRect.top + token.offsetHeight - 1,
|
|
36
|
+
startCol: boundingRect.left,
|
|
37
|
+
endCol: token.offsetHeight > 1 ? token.offsetWidth : boundingRect.left + token.offsetWidth,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
module.exports = {generateForChild, generateForSelf};
|
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
|
|
@@ -14,20 +10,27 @@ const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
|
14
10
|
const removeComment = str => str.replaceAll(/\0\d+c\x7F/gu, '');
|
|
15
11
|
|
|
16
12
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {
|
|
13
|
+
* 以HTML格式打印
|
|
14
|
+
* @param {(AstText|AstElement)[]} childNodes 子节点
|
|
15
|
+
* @param {printOpt} opt 选项
|
|
19
16
|
*/
|
|
20
|
-
const
|
|
17
|
+
const print = (childNodes, opt = {}) => {
|
|
18
|
+
const AstText = require('../lib/text'),
|
|
19
|
+
AstElement = require('../lib/element');
|
|
20
|
+
const {pre = '', post = '', sep = ''} = opt,
|
|
21
|
+
entities = {'&': 'amp', '<': 'lt', '>': 'gt'};
|
|
22
|
+
return `${pre}${childNodes.map(
|
|
23
|
+
child => child instanceof AstElement
|
|
24
|
+
? child.print()
|
|
25
|
+
: String(child).replaceAll(/[&<>]/gu, p => `&${entities[p]};`),
|
|
26
|
+
).join(sep)}${post}`;
|
|
27
|
+
};
|
|
21
28
|
|
|
22
29
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {string} separator delimiter between nodes
|
|
30
|
+
* escape special chars for RegExp constructor
|
|
31
|
+
* @param {string} str RegExp source
|
|
26
32
|
*/
|
|
27
|
-
const
|
|
28
|
-
const AstNode = require('../lib/node');
|
|
29
|
-
return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
30
|
-
};
|
|
33
|
+
const escapeRegExp = str => str.replaceAll(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* a more sophisticated string-explode function
|
|
@@ -59,6 +62,23 @@ const explode = (start, end, separator, str) => {
|
|
|
59
62
|
return exploded;
|
|
60
63
|
};
|
|
61
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
|
+
|
|
62
82
|
/**
|
|
63
83
|
* escape newlines
|
|
64
84
|
* @param {string} str 原字符串
|
|
@@ -82,7 +102,4 @@ const normalizeSpace = token => {
|
|
|
82
102
|
}
|
|
83
103
|
};
|
|
84
104
|
|
|
85
|
-
|
|
86
|
-
+ '(?:[^[\\]<>"\\0-\\x1f\\x7f\\p{Zs}\\ufffd]|\\0\\d+c\\x7f)*';
|
|
87
|
-
|
|
88
|
-
module.exports = {toCase, removeComment, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};
|
|
105
|
+
module.exports = {extUrlChar, removeComment, print, escapeRegExp, explode, toCase, text, noWrap, normalizeSpace};
|