wikiparser-node 0.4.0 → 0.5.0
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/index.js +25 -2
- package/lib/element.js +69 -185
- package/lib/node.js +159 -1
- package/lib/ranges.js +1 -2
- package/lib/text.js +35 -6
- package/lib/title.js +1 -1
- package/mixin/fixedToken.js +4 -4
- package/mixin/sol.js +17 -7
- package/package.json +11 -1
- package/parser/commentAndExt.js +1 -1
- package/parser/converter.js +1 -1
- package/parser/externalLinks.js +1 -1
- package/parser/hrAndDoubleUnderscore.js +6 -5
- package/parser/links.js +1 -2
- package/parser/magicLinks.js +1 -1
- package/parser/selector.js +5 -5
- package/parser/table.js +12 -12
- package/src/arg.js +44 -20
- package/src/attribute.js +34 -7
- package/src/converter.js +13 -5
- package/src/converterFlags.js +42 -5
- package/src/converterRule.js +25 -19
- package/src/extLink.js +20 -14
- package/src/gallery.js +35 -4
- package/src/heading.js +28 -9
- package/src/html.js +46 -18
- package/src/imageParameter.js +13 -7
- package/src/index.js +22 -15
- package/src/link/category.js +6 -6
- package/src/link/file.js +25 -5
- package/src/link/index.js +36 -33
- package/src/magicLink.js +32 -4
- package/src/nowiki/comment.js +14 -0
- package/src/nowiki/doubleUnderscore.js +5 -0
- package/src/nowiki/quote.js +28 -1
- package/src/onlyinclude.js +5 -0
- package/src/parameter.js +48 -35
- package/src/table/index.js +37 -24
- package/src/table/td.js +23 -17
- package/src/table/tr.js +47 -30
- package/src/tagPair/ext.js +4 -5
- package/src/tagPair/include.js +10 -0
- package/src/tagPair/index.js +8 -0
- package/src/transclude.js +79 -46
- package/tool/index.js +1 -1
- package/{test/util.js → util/diff.js} +14 -18
- package/util/lint.js +40 -0
- package/util/string.js +20 -3
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
|
|
2
3
|
const {spawn} = require('child_process'),
|
|
3
4
|
fs = require('fs/promises');
|
|
4
5
|
|
|
@@ -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
|
@@ -13,6 +13,23 @@ const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
|
13
13
|
*/
|
|
14
14
|
const removeComment = str => str.replaceAll(/\0\d+c\x7F/gu, '');
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* 以HTML格式打印
|
|
18
|
+
* @param {(AstText|AstElement)[]} childNodes 子节点
|
|
19
|
+
* @param {printOpt} opt 选项
|
|
20
|
+
*/
|
|
21
|
+
const print = (childNodes, opt = {}) => {
|
|
22
|
+
const AstText = require('../lib/text'),
|
|
23
|
+
AstElement = require('../lib/element');
|
|
24
|
+
const {pre = '', post = '', sep = ''} = opt,
|
|
25
|
+
entities = {'&': 'amp', '<': 'lt', '>': 'gt'};
|
|
26
|
+
return `${pre}${childNodes.map(
|
|
27
|
+
child => child instanceof AstElement
|
|
28
|
+
? child.print()
|
|
29
|
+
: String(child).replaceAll(/[&<>]/gu, p => `&${entities[p]};`),
|
|
30
|
+
).join(sep)}${post}`;
|
|
31
|
+
};
|
|
32
|
+
|
|
16
33
|
/**
|
|
17
34
|
* escape special chars for RegExp constructor
|
|
18
35
|
* @param {string} str RegExp source
|
|
@@ -82,7 +99,7 @@ const normalizeSpace = token => {
|
|
|
82
99
|
}
|
|
83
100
|
};
|
|
84
101
|
|
|
85
|
-
const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\
|
|
86
|
-
+ '(?:[^[\\]<>"\\0-\\
|
|
102
|
+
const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])'
|
|
103
|
+
+ '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
|
|
87
104
|
|
|
88
|
-
module.exports = {toCase, removeComment, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};
|
|
105
|
+
module.exports = {toCase, removeComment, print, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};
|