wikiparser-node 0.11.0 → 1.0.0-beta.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/.schema.json +26 -0
- package/dist/index.d.ts +61 -113
- package/dist/index.js +314 -0
- package/dist/lib/element.d.ts +122 -108
- package/dist/lib/element.js +656 -0
- package/dist/lib/node.d.ts +115 -221
- package/dist/lib/node.js +473 -0
- package/dist/lib/ranges.d.ts +27 -26
- package/dist/lib/ranges.js +130 -0
- package/dist/lib/text.d.ts +36 -28
- package/dist/lib/text.js +215 -0
- package/dist/lib/title.d.ts +26 -12
- package/dist/lib/title.js +108 -0
- package/dist/mixin/attributesParent.js +90 -0
- package/dist/mixin/fixed.js +29 -0
- package/dist/mixin/hidden.js +19 -0
- package/dist/mixin/singleLine.js +23 -0
- package/dist/mixin/sol.js +41 -0
- package/dist/parser/brackets.js +118 -0
- package/dist/parser/commentAndExt.js +48 -0
- package/dist/parser/converter.js +31 -0
- package/dist/parser/externalLinks.js +22 -0
- package/dist/parser/hrAndDoubleUnderscore.js +35 -0
- package/dist/parser/html.js +29 -0
- package/dist/parser/links.js +86 -0
- package/dist/parser/list.js +51 -0
- package/dist/parser/magicLinks.js +32 -0
- package/dist/parser/quotes.js +57 -0
- package/dist/parser/selector.js +158 -0
- package/dist/parser/table.js +108 -0
- package/dist/src/arg.d.ts +47 -23
- package/dist/src/arg.js +196 -0
- package/dist/src/atom.d.ts +12 -0
- package/dist/src/atom.js +22 -0
- package/dist/src/attribute.d.ts +74 -33
- package/dist/src/attribute.js +433 -0
- package/dist/src/attributes.d.ts +61 -55
- package/dist/src/attributes.js +371 -0
- package/dist/src/converter.d.ts +45 -71
- package/dist/src/converter.js +135 -0
- package/dist/src/converterFlags.d.ts +64 -39
- package/dist/src/converterFlags.js +235 -0
- package/dist/src/converterRule.d.ts +49 -27
- package/dist/src/converterRule.js +255 -0
- package/dist/src/extLink.d.ts +41 -38
- package/dist/src/extLink.js +154 -0
- package/dist/src/gallery.d.ts +59 -18
- package/dist/src/gallery.js +132 -0
- package/dist/src/heading.d.ts +60 -22
- package/dist/src/heading.js +135 -0
- package/dist/src/hidden.d.ts +20 -0
- package/dist/src/hidden.js +24 -0
- package/dist/src/html.d.ts +83 -29
- package/dist/src/html.js +242 -0
- package/dist/src/imageParameter.d.ts +59 -40
- package/dist/src/imageParameter.js +251 -0
- package/dist/src/imagemap.d.ts +65 -21
- package/dist/src/imagemap.js +169 -0
- package/dist/src/imagemapLink.d.ts +46 -14
- package/dist/src/imagemapLink.js +38 -0
- package/dist/src/index.d.ts +71 -105
- package/dist/src/index.js +826 -0
- package/dist/src/link/base.d.ts +71 -0
- package/dist/src/link/base.js +225 -0
- package/dist/src/link/category.d.ts +10 -11
- package/dist/src/link/category.js +26 -0
- package/dist/src/link/file.d.ts +61 -39
- package/dist/src/link/file.js +242 -0
- package/dist/src/link/galleryImage.d.ts +34 -12
- package/dist/src/link/galleryImage.js +98 -0
- package/dist/src/link/index.d.ts +25 -63
- package/dist/src/link/index.js +136 -0
- package/dist/src/magicLink.d.ts +22 -15
- package/dist/src/magicLink.js +126 -0
- package/dist/src/nested.d.ts +47 -0
- package/dist/src/nested.js +84 -0
- package/dist/src/nowiki/base.d.ts +39 -0
- package/dist/src/nowiki/base.js +29 -0
- package/dist/src/nowiki/comment.d.ts +31 -20
- package/dist/src/nowiki/comment.js +61 -0
- package/dist/src/nowiki/dd.d.ts +17 -11
- package/dist/src/nowiki/dd.js +50 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +28 -13
- package/dist/src/nowiki/doubleUnderscore.js +45 -0
- package/dist/src/nowiki/hr.d.ts +28 -10
- package/dist/src/nowiki/hr.js +33 -0
- package/dist/src/nowiki/index.d.ts +17 -23
- package/dist/src/nowiki/index.js +21 -0
- package/dist/src/nowiki/list.d.ts +15 -7
- package/dist/src/nowiki/list.js +11 -0
- package/dist/src/nowiki/noinclude.d.ts +20 -7
- package/dist/src/nowiki/noinclude.js +22 -0
- package/dist/src/nowiki/quote.d.ts +25 -10
- package/dist/src/nowiki/quote.js +55 -0
- package/dist/src/onlyinclude.d.ts +28 -12
- package/dist/src/onlyinclude.js +64 -0
- package/dist/src/paramTag/index.d.ts +40 -17
- package/dist/src/paramTag/index.js +76 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -7
- package/dist/src/paramTag/inputbox.js +19 -0
- package/dist/src/parameter.d.ts +62 -41
- package/dist/src/parameter.js +201 -0
- package/dist/src/pre.d.ts +32 -0
- package/dist/src/pre.js +39 -0
- package/dist/src/syntax.d.ts +17 -14
- package/dist/src/syntax.js +65 -0
- package/dist/src/table/base.d.ts +55 -0
- package/dist/src/table/base.js +77 -0
- package/dist/src/table/index.d.ts +123 -156
- package/dist/src/table/index.js +811 -0
- package/dist/src/table/td.d.ts +90 -67
- package/dist/src/table/td.js +276 -0
- package/dist/src/table/tr.d.ts +30 -85
- package/dist/src/table/tr.js +48 -0
- package/dist/src/table/trBase.d.ts +72 -0
- package/dist/src/table/trBase.js +153 -0
- package/dist/src/tagPair/ext.d.ts +47 -11
- package/dist/src/tagPair/ext.js +127 -0
- package/dist/src/tagPair/include.d.ts +32 -13
- package/dist/src/tagPair/include.js +40 -0
- package/dist/src/tagPair/index.d.ts +44 -29
- package/dist/src/tagPair/index.js +111 -0
- package/dist/src/transclude.d.ts +88 -85
- package/dist/src/transclude.js +739 -0
- package/dist/util/base.js +26 -0
- package/dist/util/debug.js +52 -0
- package/dist/util/diff.js +69 -0
- package/dist/util/lint.js +38 -0
- package/dist/util/string.js +103 -0
- package/errors/README +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +21 -24
- package/printed/README +1 -0
- package/dist/mixin/attributeParent.d.ts +0 -9
- package/dist/mixin/fixedToken.d.ts +0 -8
- package/dist/mixin/hidden.d.ts +0 -8
- package/dist/mixin/singleLine.d.ts +0 -8
- package/dist/mixin/sol.d.ts +0 -8
- package/dist/parser/brackets.d.ts +0 -12
- package/dist/parser/commentAndExt.d.ts +0 -8
- package/dist/parser/converter.d.ts +0 -7
- package/dist/parser/externalLinks.d.ts +0 -7
- package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
- package/dist/parser/html.d.ts +0 -7
- package/dist/parser/links.d.ts +0 -7
- package/dist/parser/list.d.ts +0 -7
- package/dist/parser/magicLinks.d.ts +0 -7
- package/dist/parser/quotes.d.ts +0 -7
- package/dist/parser/selector.d.ts +0 -12
- package/dist/parser/table.d.ts +0 -11
- package/dist/src/atom/hidden.d.ts +0 -5
- package/dist/src/atom/index.d.ts +0 -15
- package/dist/src/charinsert.d.ts +0 -32
- package/dist/src/hasNowiki/index.d.ts +0 -14
- package/dist/src/hasNowiki/pre.d.ts +0 -13
- package/dist/src/nested/choose.d.ts +0 -13
- package/dist/src/nested/combobox.d.ts +0 -13
- package/dist/src/nested/index.d.ts +0 -18
- package/dist/src/nested/references.d.ts +0 -13
- package/dist/tool/index.d.ts +0 -420
- package/dist/util/base.d.ts +0 -10
- package/dist/util/debug.d.ts +0 -20
- package/dist/util/diff.d.ts +0 -8
- package/dist/util/lint.d.ts +0 -28
- package/dist/util/string.d.ts +0 -55
- package/index.js +0 -333
- package/lib/element.js +0 -618
- package/lib/node.js +0 -730
- package/lib/ranges.js +0 -130
- package/lib/text.js +0 -265
- package/lib/title.js +0 -83
- package/mixin/attributeParent.js +0 -117
- package/mixin/fixedToken.js +0 -40
- package/mixin/hidden.js +0 -21
- package/mixin/singleLine.js +0 -31
- package/mixin/sol.js +0 -54
- package/parser/brackets.js +0 -128
- package/parser/commentAndExt.js +0 -62
- package/parser/converter.js +0 -46
- package/parser/externalLinks.js +0 -33
- package/parser/hrAndDoubleUnderscore.js +0 -49
- package/parser/html.js +0 -42
- package/parser/links.js +0 -94
- package/parser/list.js +0 -59
- package/parser/magicLinks.js +0 -41
- package/parser/quotes.js +0 -64
- package/parser/selector.js +0 -180
- package/parser/table.js +0 -114
- package/src/arg.js +0 -207
- package/src/atom/hidden.js +0 -13
- package/src/atom/index.js +0 -43
- package/src/attribute.js +0 -472
- package/src/attributes.js +0 -453
- package/src/charinsert.js +0 -97
- package/src/converter.js +0 -176
- package/src/converterFlags.js +0 -284
- package/src/converterRule.js +0 -256
- package/src/extLink.js +0 -180
- package/src/gallery.js +0 -149
- package/src/hasNowiki/index.js +0 -44
- package/src/hasNowiki/pre.js +0 -40
- package/src/heading.js +0 -134
- package/src/html.js +0 -254
- package/src/imageParameter.js +0 -303
- package/src/imagemap.js +0 -199
- package/src/imagemapLink.js +0 -41
- package/src/index.js +0 -938
- package/src/link/category.js +0 -44
- package/src/link/file.js +0 -287
- package/src/link/galleryImage.js +0 -120
- package/src/link/index.js +0 -388
- package/src/magicLink.js +0 -151
- package/src/nested/choose.js +0 -24
- package/src/nested/combobox.js +0 -23
- package/src/nested/index.js +0 -96
- package/src/nested/references.js +0 -23
- package/src/nowiki/comment.js +0 -71
- package/src/nowiki/dd.js +0 -59
- package/src/nowiki/doubleUnderscore.js +0 -56
- package/src/nowiki/hr.js +0 -41
- package/src/nowiki/index.js +0 -56
- package/src/nowiki/list.js +0 -16
- package/src/nowiki/noinclude.js +0 -28
- package/src/nowiki/quote.js +0 -69
- package/src/onlyinclude.js +0 -64
- package/src/paramTag/index.js +0 -89
- package/src/paramTag/inputbox.js +0 -35
- package/src/parameter.js +0 -239
- package/src/syntax.js +0 -91
- package/src/table/index.js +0 -985
- package/src/table/td.js +0 -343
- package/src/table/tr.js +0 -319
- package/src/tagPair/ext.js +0 -146
- package/src/tagPair/include.js +0 -50
- package/src/tagPair/index.js +0 -131
- package/src/transclude.js +0 -843
- package/tool/index.js +0 -1209
- package/typings/api.d.ts +0 -9
- package/typings/array.d.ts +0 -29
- package/typings/event.d.ts +0 -22
- package/typings/index.d.ts +0 -118
- package/typings/node.d.ts +0 -35
- package/typings/parser.d.ts +0 -12
- package/typings/table.d.ts +0 -10
- package/typings/token.d.ts +0 -31
- package/typings/tool.d.ts +0 -6
- package/util/base.js +0 -17
- package/util/debug.js +0 -73
- package/util/diff.js +0 -76
- package/util/lint.js +0 -57
- package/util/string.js +0 -126
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.del = exports.isPlainObject = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 是否是普通对象
|
|
6
|
+
* @param obj 对象
|
|
7
|
+
*/
|
|
8
|
+
const isPlainObject = (obj) => {
|
|
9
|
+
if (!obj) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
13
|
+
return prototype === null || prototype.constructor === Object;
|
|
14
|
+
};
|
|
15
|
+
exports.isPlainObject = isPlainObject;
|
|
16
|
+
/**
|
|
17
|
+
* 从数组中删除指定元素
|
|
18
|
+
* @param arr 数组
|
|
19
|
+
* @param ele 元素
|
|
20
|
+
*/
|
|
21
|
+
const del = (arr, ele) => {
|
|
22
|
+
const set = new Set(arr);
|
|
23
|
+
set.delete(ele);
|
|
24
|
+
return [...set];
|
|
25
|
+
};
|
|
26
|
+
exports.del = del;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.undo = exports.typeError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 定制TypeError消息
|
|
6
|
+
* @param {Function} Constructor 类
|
|
7
|
+
* @param args 可接受的参数类型
|
|
8
|
+
* @throws `TypeError`
|
|
9
|
+
*/
|
|
10
|
+
const typeError = ({ name }, method, ...args) => {
|
|
11
|
+
throw new TypeError(`${name}.${method} 方法仅接受 ${args.join('、')} 作为输入参数!`);
|
|
12
|
+
};
|
|
13
|
+
exports.typeError = typeError;
|
|
14
|
+
/**
|
|
15
|
+
* 撤销最近一次Mutation
|
|
16
|
+
* @param e 事件
|
|
17
|
+
* @param data 事件数据
|
|
18
|
+
* @throws `RangeError` 无法撤销的事件类型
|
|
19
|
+
*/
|
|
20
|
+
const undo = (e, data) => {
|
|
21
|
+
const { target, type } = e;
|
|
22
|
+
switch (type) {
|
|
23
|
+
case 'remove': {
|
|
24
|
+
const childNodes = [...target.childNodes];
|
|
25
|
+
childNodes.splice(data.position, 0, data.removed);
|
|
26
|
+
data.removed.setAttribute('parentNode', target);
|
|
27
|
+
target.setAttribute('childNodes', childNodes);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 'insert': {
|
|
31
|
+
const childNodes = [...target.childNodes];
|
|
32
|
+
childNodes.splice(data.position, 1);
|
|
33
|
+
target.setAttribute('childNodes', childNodes);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case 'replace': {
|
|
37
|
+
const { parentNode } = target, childNodes = [...parentNode.childNodes];
|
|
38
|
+
childNodes.splice(data.position, 1, data.oldToken);
|
|
39
|
+
data.oldToken.setAttribute('parentNode', parentNode);
|
|
40
|
+
parentNode.setAttribute('childNodes', childNodes);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 'text':
|
|
44
|
+
if (target.type === 'text') {
|
|
45
|
+
target.replaceData(data.oldText);
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
throw new RangeError(`无法撤销未知类型的事件:${type}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.undo = undo;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const child_process_1 = require("child_process");
|
|
3
|
+
const fs = require("fs/promises");
|
|
4
|
+
process.on('unhandledRejection', e => {
|
|
5
|
+
console.error(e);
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* 将shell命令转化为Promise对象
|
|
9
|
+
* @param command shell指令
|
|
10
|
+
* @param args shell输入参数
|
|
11
|
+
*/
|
|
12
|
+
const cmd = (command, args) => new Promise(resolve => {
|
|
13
|
+
let timer, shell;
|
|
14
|
+
/**
|
|
15
|
+
* 清除进程并返回
|
|
16
|
+
* @param val 返回值
|
|
17
|
+
*/
|
|
18
|
+
const r = (val) => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
shell?.kill('SIGINT');
|
|
21
|
+
resolve(val);
|
|
22
|
+
};
|
|
23
|
+
try {
|
|
24
|
+
shell = (0, child_process_1.spawn)(command, args);
|
|
25
|
+
timer = setTimeout(() => {
|
|
26
|
+
shell.kill('SIGINT');
|
|
27
|
+
}, 60 * 1000);
|
|
28
|
+
let buf = '';
|
|
29
|
+
shell.stdout.on('data', data => {
|
|
30
|
+
buf += String(data);
|
|
31
|
+
});
|
|
32
|
+
shell.stdout.on('end', () => {
|
|
33
|
+
r(buf);
|
|
34
|
+
});
|
|
35
|
+
shell.on('exit', () => {
|
|
36
|
+
r(shell.killed ? undefined : '');
|
|
37
|
+
});
|
|
38
|
+
shell.on('error', () => {
|
|
39
|
+
r(undefined);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
r(undefined);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* 比较两个文件
|
|
48
|
+
* @param oldStr 旧文本
|
|
49
|
+
* @param newStr 新文本
|
|
50
|
+
* @param uid 唯一标识
|
|
51
|
+
*/
|
|
52
|
+
const diff = async (oldStr, newStr, uid = -1) => {
|
|
53
|
+
if (oldStr === newStr) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const oldFile = `diffOld${uid}`, newFile = `diffNew${uid}`;
|
|
57
|
+
await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
|
|
58
|
+
const stdout = await cmd('git', [
|
|
59
|
+
'diff',
|
|
60
|
+
'--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
|
|
61
|
+
'-U0',
|
|
62
|
+
'--no-index',
|
|
63
|
+
oldFile,
|
|
64
|
+
newFile,
|
|
65
|
+
]);
|
|
66
|
+
await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
|
|
67
|
+
console.log(stdout?.split('\n')?.slice(4)?.join('\n'));
|
|
68
|
+
};
|
|
69
|
+
module.exports = diff;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateForSelf = exports.generateForChild = void 0;
|
|
4
|
+
const Parser = require("../index");
|
|
5
|
+
/**
|
|
6
|
+
* 生成对于子节点的LintError对象
|
|
7
|
+
* @param child 子节点
|
|
8
|
+
* @param boundingRect 父节点的绝对定位
|
|
9
|
+
* @param msg 错误信息
|
|
10
|
+
* @param severity 严重程度
|
|
11
|
+
*/
|
|
12
|
+
const generateForChild = (child, boundingRect, msg, severity = 'error') => {
|
|
13
|
+
const index = child.getRelativeIndex(), { offsetHeight, offsetWidth, parentNode } = child, { top: offsetTop, left: offsetLeft } = parentNode.posFromIndex(index), { start } = boundingRect, { top, left } = 'top' in boundingRect ? boundingRect : child.getRootNode().posFromIndex(start), str = String(child), excerpt = str.slice(0, 50), startIndex = start + index, endIndex = startIndex + str.length, startLine = top + offsetTop, endLine = startLine + offsetHeight - 1, startCol = offsetTop ? offsetLeft : left + offsetLeft, endCol = offsetHeight > 1 ? offsetWidth : startCol + offsetWidth;
|
|
14
|
+
return { message: Parser.msg(msg), severity, startIndex, endIndex, startLine, endLine, startCol, endCol, excerpt };
|
|
15
|
+
};
|
|
16
|
+
exports.generateForChild = generateForChild;
|
|
17
|
+
/**
|
|
18
|
+
* 生成对于自己的LintError对象
|
|
19
|
+
* @param token 节点
|
|
20
|
+
* @param boundingRect 绝对定位
|
|
21
|
+
* @param msg 错误信息
|
|
22
|
+
* @param severity 严重程度
|
|
23
|
+
*/
|
|
24
|
+
const generateForSelf = (token, boundingRect, msg, severity = 'error') => {
|
|
25
|
+
const { start } = boundingRect, { offsetHeight, offsetWidth } = token, str = String(token), { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start);
|
|
26
|
+
return {
|
|
27
|
+
message: Parser.msg(msg),
|
|
28
|
+
severity,
|
|
29
|
+
startIndex: start,
|
|
30
|
+
endIndex: start + str.length,
|
|
31
|
+
startLine: top,
|
|
32
|
+
endLine: top + offsetHeight - 1,
|
|
33
|
+
startCol: left,
|
|
34
|
+
endCol: offsetHeight > 1 ? offsetWidth : left + offsetWidth,
|
|
35
|
+
excerpt: str.slice(0, 50),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
exports.generateForSelf = generateForSelf;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeSpace = exports.noWrap = exports.toCase = exports.decodeHtml = exports.text = exports.explode = exports.escapeRegExp = exports.print = exports.removeComment = exports.extUrlChar = exports.extUrlCharFirst = void 0;
|
|
4
|
+
exports.extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])';
|
|
5
|
+
exports.extUrlChar = '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
|
|
6
|
+
/**
|
|
7
|
+
* remove half-parsed comment-like tokens
|
|
8
|
+
* @browser
|
|
9
|
+
* @param str 原字符串
|
|
10
|
+
*/
|
|
11
|
+
const removeComment = (str) => str.replace(/\0\d+c\x7F/gu, '');
|
|
12
|
+
exports.removeComment = removeComment;
|
|
13
|
+
/**
|
|
14
|
+
* 以HTML格式打印
|
|
15
|
+
* @browser
|
|
16
|
+
* @param childNodes 子节点
|
|
17
|
+
* @param opt 选项
|
|
18
|
+
*/
|
|
19
|
+
const print = (childNodes, opt = {}) => {
|
|
20
|
+
const { pre = '', post = '', sep = '' } = opt, entities = { '&': 'amp', '<': 'lt', '>': 'gt' };
|
|
21
|
+
return `${pre}${childNodes.map(child => child.type === 'text'
|
|
22
|
+
? String(child).replace(/[&<>]/gu, p => `&${entities[p]};`)
|
|
23
|
+
: child.print()).join(sep)}${post}`;
|
|
24
|
+
};
|
|
25
|
+
exports.print = print;
|
|
26
|
+
/**
|
|
27
|
+
* escape special chars for RegExp constructor
|
|
28
|
+
* @browser
|
|
29
|
+
* @param str RegExp source
|
|
30
|
+
*/
|
|
31
|
+
const escapeRegExp = (str) => str.replace(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
|
|
32
|
+
exports.escapeRegExp = escapeRegExp;
|
|
33
|
+
/**
|
|
34
|
+
* a more sophisticated string-explode function
|
|
35
|
+
* @browser
|
|
36
|
+
* @param start start syntax of a nested AST node
|
|
37
|
+
* @param end end syntax of a nested AST node
|
|
38
|
+
* @param separator syntax for explosion
|
|
39
|
+
* @param str string to be exploded
|
|
40
|
+
*/
|
|
41
|
+
const explode = (start, end, separator, str) => {
|
|
42
|
+
if (str === undefined) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const regex = new RegExp(`${[start, end, separator].map(exports.escapeRegExp).join('|')}`, 'gu'), exploded = [];
|
|
46
|
+
let mt = regex.exec(str), depth = 0, lastIndex = 0;
|
|
47
|
+
while (mt) {
|
|
48
|
+
const { 0: match, index } = mt;
|
|
49
|
+
if (match !== separator) {
|
|
50
|
+
depth += match === start ? 1 : -1;
|
|
51
|
+
}
|
|
52
|
+
else if (depth === 0) {
|
|
53
|
+
exploded.push(str.slice(lastIndex, index));
|
|
54
|
+
({ lastIndex } = regex);
|
|
55
|
+
}
|
|
56
|
+
mt = regex.exec(str);
|
|
57
|
+
}
|
|
58
|
+
exploded.push(str.slice(lastIndex));
|
|
59
|
+
return exploded;
|
|
60
|
+
};
|
|
61
|
+
exports.explode = explode;
|
|
62
|
+
/**
|
|
63
|
+
* extract effective wikitext
|
|
64
|
+
* @browser
|
|
65
|
+
* @param childNodes a Token's contents
|
|
66
|
+
* @param separator delimiter between nodes
|
|
67
|
+
*/
|
|
68
|
+
const text = (childNodes, separator = '') => childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
69
|
+
exports.text = text;
|
|
70
|
+
/**
|
|
71
|
+
* decode HTML entities
|
|
72
|
+
* @browser
|
|
73
|
+
* @param str 原字符串
|
|
74
|
+
*/
|
|
75
|
+
const decodeHtml = (str) => str.replace(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number(`${code[0].toLowerCase() === 'x' ? '0' : ''}${code}`)));
|
|
76
|
+
exports.decodeHtml = decodeHtml;
|
|
77
|
+
/**
|
|
78
|
+
* optionally convert to lower cases
|
|
79
|
+
* @param val 属性值
|
|
80
|
+
* @param i 是否对大小写不敏感
|
|
81
|
+
*/
|
|
82
|
+
const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
83
|
+
exports.toCase = toCase;
|
|
84
|
+
/**
|
|
85
|
+
* escape newlines
|
|
86
|
+
* @param str 原字符串
|
|
87
|
+
*/
|
|
88
|
+
const noWrap = (str) => str.replaceAll('\n', '\\n');
|
|
89
|
+
exports.noWrap = noWrap;
|
|
90
|
+
/**
|
|
91
|
+
* convert newline in text nodes to single whitespace
|
|
92
|
+
* @param token 父节点
|
|
93
|
+
*/
|
|
94
|
+
const normalizeSpace = (token) => {
|
|
95
|
+
if (token) {
|
|
96
|
+
for (const child of token.childNodes) {
|
|
97
|
+
if (child.type === 'text') {
|
|
98
|
+
child.replaceData(child.data.replaceAll('\n', ' '));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports.normalizeSpace = normalizeSpace;
|
package/errors/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
这里记录解析失败时处于半解析状态的维基文本以及错误信息。
|
package/i18n/zh-hans.json
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"invalid self-closing tag": "无效自封闭标签",
|
|
28
28
|
"invisible content inside triple brackets": "三重括号内的不可见部分",
|
|
29
29
|
"lonely \"$1\"": "孤立的\"$1\"",
|
|
30
|
+
"nonzero tabindex": "不为0的tabindex",
|
|
30
31
|
"nothing should be in <$1>": "<$1>标签内不应有任何内容",
|
|
31
32
|
"section header in a HTML tag": "HTML标签属性中的段落标题",
|
|
32
33
|
"tag that is both closing and self-closing": "同时闭合和自封闭的标签",
|
package/i18n/zh-hant.json
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"invalid self-closing tag": "無效自封閉標籤",
|
|
28
28
|
"invisible content inside triple brackets": "三重括號內的不可見部分",
|
|
29
29
|
"lonely \"$1\"": "孤立的\"$1\"",
|
|
30
|
+
"nonzero tabindex": "不為0的tabindex",
|
|
30
31
|
"nothing should be in <$1>": "<$1>標籤內不應有任何內容",
|
|
31
32
|
"section header in a HTML tag": "HTML標籤屬性中的段落標題",
|
|
32
33
|
"tag that is both closing and self-closing": "同時閉合和自封閉的標籤",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiparser-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "A Node.js parser for MediaWiki markup with AST",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -14,47 +14,44 @@
|
|
|
14
14
|
"license": "GPL-3.0",
|
|
15
15
|
"author": "Bhsd",
|
|
16
16
|
"files": [
|
|
17
|
-
"/
|
|
17
|
+
"/errors/README",
|
|
18
|
+
"/printed/README",
|
|
18
19
|
"/config/",
|
|
19
20
|
"/i18n/",
|
|
20
|
-
"/lib/",
|
|
21
|
-
"/mixin/",
|
|
22
|
-
"/parser/",
|
|
23
|
-
"/src/",
|
|
24
|
-
"/tool/",
|
|
25
|
-
"/util/",
|
|
26
|
-
"/typings/",
|
|
27
21
|
"/dist/"
|
|
28
22
|
],
|
|
29
|
-
"
|
|
23
|
+
"main": "./dist/index.js",
|
|
30
24
|
"repository": {
|
|
31
25
|
"type": "git",
|
|
32
26
|
"url": "git+https://github.com/bhsd-harry/wikiparser-node.git"
|
|
33
27
|
},
|
|
34
28
|
"scripts": {
|
|
35
|
-
"
|
|
29
|
+
"prepublishOnly": "rm -rf dist/; tsc; grep -rl --include='*.js' -e '@ts' -e '@typescript' dist/ | xargs gsed -i -E '/@ts|@typescript/d'; rm dist/[mpu]*/*.d.ts; grep -rl --include='*.d.ts' '@private' dist/ | xargs gsed -i '/@private/,+1d'",
|
|
30
|
+
"build": "rm -rf dist/; tsc; grep -rl --include='*.js' -e '@ts' -e '@typescript' dist/ | xargs gsed -i -E '/@ts|@typescript/d'; eslint --fix dist/",
|
|
36
31
|
"doc": "node ./bin/doc.js",
|
|
37
32
|
"toc": "node ./bin/toc.js",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
33
|
+
"lint:ts": "eslint --cache --ignore-pattern '/dist/' .",
|
|
34
|
+
"lint:json": "ajv -s config/.schema.json -d 'config/*.json' --strict=true --strict-required=false",
|
|
35
|
+
"lint": "npm run lint:ts && npm run lint:json",
|
|
36
|
+
"test:real": "node test/real.js",
|
|
37
|
+
"test:single": "node --prof test/single.js && node --prof-process isolate-0x*-v8.log > test/processed.txt && rm isolate-0x*-v8.log"
|
|
41
38
|
},
|
|
42
39
|
"devDependencies": {
|
|
43
|
-
"@types/node": "^17.0.
|
|
44
|
-
"eslint": "^8.
|
|
45
|
-
"eslint-plugin-n": "^
|
|
46
|
-
"eslint-plugin-regexp": "^1.
|
|
47
|
-
"eslint-plugin-unicorn": "^
|
|
48
|
-
"eslint-plugin-jsdoc": "^
|
|
40
|
+
"@types/node": "^17.0.45",
|
|
41
|
+
"eslint": "^8.53.0",
|
|
42
|
+
"eslint-plugin-n": "^16.3.0",
|
|
43
|
+
"eslint-plugin-regexp": "^2.1.1",
|
|
44
|
+
"eslint-plugin-unicorn": "^49.0.0",
|
|
45
|
+
"eslint-plugin-jsdoc": "^46.8.2",
|
|
49
46
|
"eslint-plugin-json-es": "^1.5.7",
|
|
50
47
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
51
|
-
"typescript": "^
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
53
|
-
"@typescript-eslint/parser": "^5.
|
|
48
|
+
"typescript": "^5.0.3",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
50
|
+
"@typescript-eslint/parser": "^5.57.0",
|
|
54
51
|
"ajv-cli": "^5.0.0",
|
|
55
52
|
"request": "^2.88.2"
|
|
56
53
|
},
|
|
57
54
|
"engines": {
|
|
58
|
-
"node": "^
|
|
55
|
+
"node": "^20.9.0"
|
|
59
56
|
}
|
|
60
57
|
}
|
package/printed/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
这里存放以 JSON 格式打印的 AST。
|
package/dist/mixin/hidden.d.ts
DELETED
package/dist/mixin/sol.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export = parseBrackets;
|
|
2
|
-
/**
|
|
3
|
-
* 解析花括号
|
|
4
|
-
* @param {string} text wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
* @throws TranscludeToken.constructor()
|
|
7
|
-
*/
|
|
8
|
-
declare function parseBrackets(text: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
|
9
|
-
declare namespace parseBrackets {
|
|
10
|
-
export { BracketExecArray };
|
|
11
|
-
}
|
|
12
|
-
type BracketExecArray = import('../../typings/parser').BracketExecArray;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export = parseCommentAndExt;
|
|
2
|
-
/**
|
|
3
|
-
* 解析HTML注释和扩展标签
|
|
4
|
-
* @param {string} text wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
* @param {boolean} includeOnly 是否嵌入
|
|
7
|
-
*/
|
|
8
|
-
declare function parseCommentAndExt(text: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum, includeOnly?: boolean): string;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export = parseConverter;
|
|
2
|
-
/**
|
|
3
|
-
* 解析语言变体转换
|
|
4
|
-
* @param {string} wikitext wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseConverter(wikitext: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export = parseExternalLinks;
|
|
2
|
-
/**
|
|
3
|
-
* 解析外部链接
|
|
4
|
-
* @param {string} wikitext wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseExternalLinks(wikitext: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export = parseHrAndDoubleUnderscore;
|
|
2
|
-
/**
|
|
3
|
-
* 解析\<hr\>和状态开关
|
|
4
|
-
* @param {Token & {firstChild: AstText}} root 根节点
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseHrAndDoubleUnderscore({ firstChild: { data }, type, name }: Token & {
|
|
8
|
-
firstChild: AstText;
|
|
9
|
-
}, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
|
10
|
-
import Token = require("../src");
|
|
11
|
-
import AstText = require("../lib/text");
|
package/dist/parser/html.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export = parseHtml;
|
|
2
|
-
/**
|
|
3
|
-
* 解析HTML标签
|
|
4
|
-
* @param {string} wikitext wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseHtml(wikitext: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
package/dist/parser/links.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export = parseLinks;
|
|
2
|
-
/**
|
|
3
|
-
* 解析内部链接
|
|
4
|
-
* @param {string} wikitext wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseLinks(wikitext: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
package/dist/parser/list.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export = parseList;
|
|
2
|
-
/**
|
|
3
|
-
* 解析列表
|
|
4
|
-
* @param {string} text wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseList(text: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export = parseMagicLinks;
|
|
2
|
-
/**
|
|
3
|
-
* 解析自由外链
|
|
4
|
-
* @param {string} wikitext wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseMagicLinks(wikitext: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
package/dist/parser/quotes.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export = parseQuotes;
|
|
2
|
-
/**
|
|
3
|
-
* 解析单引号
|
|
4
|
-
* @param {string} text wikitext
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseQuotes(text: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export = parseSelector;
|
|
2
|
-
/**
|
|
3
|
-
* 解析选择器
|
|
4
|
-
* @param {string} selector
|
|
5
|
-
* @throws `SyntaxError` 非法的选择器
|
|
6
|
-
*/
|
|
7
|
-
declare function parseSelector(selector: string): import("../../typings/parser").SelectorArray[][];
|
|
8
|
-
declare namespace parseSelector {
|
|
9
|
-
export { SelectorArray, pseudo };
|
|
10
|
-
}
|
|
11
|
-
type SelectorArray = import('../../typings/parser').SelectorArray;
|
|
12
|
-
type pseudo = import('../../typings/parser').pseudo;
|
package/dist/parser/table.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export = parseTable;
|
|
2
|
-
/**
|
|
3
|
-
* 解析表格,注意`tr`和`td`包含开头的换行
|
|
4
|
-
* @param {Token & {firstChild: AstText}} root 根节点
|
|
5
|
-
* @param {import('../../typings/token').accum} accum
|
|
6
|
-
*/
|
|
7
|
-
declare function parseTable({ firstChild: { data }, type, name }: Token & {
|
|
8
|
-
firstChild: AstText;
|
|
9
|
-
}, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum): string;
|
|
10
|
-
import Token = require("../src");
|
|
11
|
-
import AstText = require("../lib/text");
|
package/dist/src/atom/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export = AtomToken;
|
|
2
|
-
/**
|
|
3
|
-
* 不会被继续解析的plain Token
|
|
4
|
-
* @classdesc `{childNodes: ...AstText|Token}`
|
|
5
|
-
*/
|
|
6
|
-
declare class AtomToken extends Token {
|
|
7
|
-
/**
|
|
8
|
-
* @param {string} wikitext wikitext
|
|
9
|
-
* @param {string|undefined} type Token.type
|
|
10
|
-
* @param {import('../../../typings/token').accum} accum
|
|
11
|
-
* @param {import('../../../typings/token').acceptable} acceptable 可接受的子节点设置
|
|
12
|
-
*/
|
|
13
|
-
constructor(wikitext: string, type: string | undefined, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum, acceptable?: import('../../../typings/token').acceptable);
|
|
14
|
-
}
|
|
15
|
-
import Token = require("..");
|
package/dist/src/charinsert.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export = CharinsertToken;
|
|
2
|
-
/**
|
|
3
|
-
* `<charinsert>`
|
|
4
|
-
* @classdesc `{childNodes: [...HasNowikiToken]}`
|
|
5
|
-
*/
|
|
6
|
-
declare class CharinsertToken extends Token {
|
|
7
|
-
/**
|
|
8
|
-
* @param {string} wikitext wikitext
|
|
9
|
-
* @param {import('../../typings/token').accum} accum
|
|
10
|
-
*/
|
|
11
|
-
constructor(wikitext: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum);
|
|
12
|
-
/**
|
|
13
|
-
* @override
|
|
14
|
-
* @param {string} selector
|
|
15
|
-
*/
|
|
16
|
-
override toString(selector: string): string;
|
|
17
|
-
/** @override */
|
|
18
|
-
override print(): string;
|
|
19
|
-
/** @override */
|
|
20
|
-
override cloneNode(): CharinsertToken;
|
|
21
|
-
/**
|
|
22
|
-
* 获取某一行的插入选项
|
|
23
|
-
* @param {number|HasNowikiToken} child 行号或子节点
|
|
24
|
-
*/
|
|
25
|
-
getLineItems(child: number | HasNowikiToken): (string | string[])[];
|
|
26
|
-
/** 获取所有插入选项 */
|
|
27
|
-
getAllItems(): (string | string[])[];
|
|
28
|
-
/** @override */
|
|
29
|
-
override text(): string;
|
|
30
|
-
}
|
|
31
|
-
import Token = require(".");
|
|
32
|
-
import HasNowikiToken = require("./hasNowiki");
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export = HasNowikiToken;
|
|
2
|
-
/**
|
|
3
|
-
* `<pre>`
|
|
4
|
-
* @classdesc `{childNodes: [...AstText|NoincludeToken]}`
|
|
5
|
-
*/
|
|
6
|
-
declare class HasNowikiToken extends Token {
|
|
7
|
-
/**
|
|
8
|
-
* @param {string} wikitext wikitext
|
|
9
|
-
* @param {string} type type
|
|
10
|
-
* @param {import('../../../typings/token').accum} accum
|
|
11
|
-
*/
|
|
12
|
-
constructor(wikitext: string, type: string, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
|
|
13
|
-
}
|
|
14
|
-
import Token = require("..");
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export = PreToken;
|
|
2
|
-
/**
|
|
3
|
-
* `<pre>`
|
|
4
|
-
* @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
|
|
5
|
-
*/
|
|
6
|
-
declare class PreToken extends HasNowikiToken {
|
|
7
|
-
/**
|
|
8
|
-
* @param {string} wikitext wikitext
|
|
9
|
-
* @param {import('../../../typings/token').accum} accum
|
|
10
|
-
*/
|
|
11
|
-
constructor(wikitext: string, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
|
|
12
|
-
}
|
|
13
|
-
import HasNowikiToken = require(".");
|