wikiparser-node 1.4.3-b → 1.4.4
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/README.en.md +1 -1
- package/README.md +1 -1
- package/config/.schema.json +172 -0
- package/config/enwiki.json +814 -1
- package/config/llwiki.json +35 -1
- package/config/moegirl.json +44 -1
- package/config/zhwiki.json +466 -1
- package/dist/addon/table.d.ts +6 -0
- package/dist/addon/table.js +564 -0
- package/dist/base.d.ts +58 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +211 -0
- package/dist/internal.d.ts +44 -0
- package/dist/lib/element.d.ts +155 -0
- package/dist/lib/element.js +655 -0
- package/dist/lib/node.d.ts +146 -0
- package/dist/lib/node.js +428 -0
- package/dist/lib/range.d.ts +104 -0
- package/dist/lib/range.js +385 -0
- package/dist/lib/ranges.d.ts +26 -0
- package/dist/lib/ranges.js +118 -0
- package/dist/lib/text.d.ts +62 -0
- package/dist/lib/text.js +306 -0
- package/dist/lib/title.d.ts +38 -0
- package/dist/lib/title.js +164 -0
- package/dist/mixin/attributesParent.d.ts +50 -0
- package/dist/mixin/attributesParent.js +78 -0
- package/dist/mixin/fixed.d.ts +6 -0
- package/dist/mixin/fixed.js +30 -0
- package/dist/mixin/flagsParent.d.ts +72 -0
- package/dist/mixin/flagsParent.js +59 -0
- package/dist/mixin/hidden.d.ts +5 -0
- package/dist/mixin/hidden.js +24 -0
- package/dist/mixin/magicLinkParent.d.ts +40 -0
- package/dist/mixin/magicLinkParent.js +42 -0
- package/dist/mixin/singleLine.d.ts +6 -0
- package/dist/mixin/singleLine.js +26 -0
- package/dist/mixin/sol.d.ts +6 -0
- package/dist/mixin/sol.js +43 -0
- package/dist/mixin/syntax.d.ts +9 -0
- package/dist/mixin/syntax.js +50 -0
- package/dist/parser/braces.js +131 -0
- package/dist/parser/commentAndExt.js +90 -0
- package/dist/parser/converter.js +41 -0
- package/dist/parser/externalLinks.js +32 -0
- package/dist/parser/hrAndDoubleUnderscore.js +41 -0
- package/dist/parser/html.js +39 -0
- package/dist/parser/links.js +95 -0
- package/dist/parser/list.js +68 -0
- package/dist/parser/magicLinks.js +43 -0
- package/dist/parser/quotes.js +68 -0
- package/dist/parser/selector.js +162 -0
- package/dist/parser/table.js +124 -0
- package/dist/src/arg.d.ts +58 -0
- package/dist/src/arg.js +196 -0
- package/dist/src/atom.d.ts +12 -0
- package/dist/src/atom.js +27 -0
- package/dist/src/attribute.d.ts +69 -0
- package/dist/src/attribute.js +475 -0
- package/dist/src/attributes.d.ts +109 -0
- package/dist/src/attributes.js +346 -0
- package/dist/src/converter.d.ts +33 -0
- package/dist/src/converter.js +134 -0
- package/dist/src/converterFlags.d.ts +87 -0
- package/dist/src/converterFlags.js +226 -0
- package/dist/src/converterRule.d.ts +77 -0
- package/dist/src/converterRule.js +209 -0
- package/dist/src/extLink.d.ts +43 -0
- package/dist/src/extLink.js +186 -0
- package/dist/src/gallery.d.ts +54 -0
- package/dist/src/gallery.js +126 -0
- package/dist/src/heading.d.ts +47 -0
- package/dist/src/heading.js +190 -0
- package/dist/src/hidden.d.ts +7 -0
- package/dist/src/hidden.js +23 -0
- package/dist/src/html.d.ts +65 -0
- package/dist/src/html.js +337 -0
- package/dist/src/imageParameter.d.ts +65 -0
- package/dist/src/imageParameter.js +246 -0
- package/dist/src/imagemap.d.ts +56 -0
- package/dist/src/imagemap.js +150 -0
- package/dist/src/imagemapLink.d.ts +31 -0
- package/dist/src/imagemapLink.js +93 -0
- package/dist/src/index.d.ts +143 -0
- package/dist/src/index.js +803 -0
- package/dist/src/link/base.d.ts +52 -0
- package/dist/src/link/base.js +209 -0
- package/dist/src/link/category.d.ts +13 -0
- package/dist/src/link/category.js +28 -0
- package/dist/src/link/file.d.ts +96 -0
- package/dist/src/link/file.js +265 -0
- package/dist/src/link/galleryImage.d.ts +32 -0
- package/dist/src/link/galleryImage.js +157 -0
- package/dist/src/link/index.d.ts +56 -0
- package/dist/src/link/index.js +133 -0
- package/dist/src/magicLink.d.ts +59 -0
- package/dist/src/magicLink.js +199 -0
- package/dist/src/nested.d.ts +43 -0
- package/dist/src/nested.js +92 -0
- package/dist/src/nowiki/base.d.ts +31 -0
- package/dist/src/nowiki/base.js +93 -0
- package/dist/src/nowiki/comment.d.ts +25 -0
- package/dist/src/nowiki/comment.js +68 -0
- package/dist/src/nowiki/dd.d.ts +8 -0
- package/dist/src/nowiki/dd.js +24 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
- package/dist/src/nowiki/doubleUnderscore.js +101 -0
- package/dist/src/nowiki/hr.d.ts +5 -0
- package/dist/src/nowiki/hr.js +63 -0
- package/dist/src/nowiki/index.d.ts +16 -0
- package/dist/src/nowiki/index.js +21 -0
- package/dist/src/nowiki/list.d.ts +16 -0
- package/dist/src/nowiki/list.js +97 -0
- package/dist/src/nowiki/listBase.d.ts +5 -0
- package/dist/src/nowiki/listBase.js +61 -0
- package/dist/src/nowiki/noinclude.d.ts +10 -0
- package/dist/src/nowiki/noinclude.js +23 -0
- package/dist/src/nowiki/quote.d.ts +14 -0
- package/dist/src/nowiki/quote.js +116 -0
- package/dist/src/onlyinclude.d.ts +16 -0
- package/dist/src/onlyinclude.js +57 -0
- package/dist/src/paramTag/index.d.ts +37 -0
- package/dist/src/paramTag/index.js +69 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -0
- package/dist/src/paramTag/inputbox.js +22 -0
- package/dist/src/parameter.d.ts +70 -0
- package/dist/src/parameter.js +262 -0
- package/dist/src/pre.d.ts +28 -0
- package/dist/src/pre.js +55 -0
- package/dist/src/syntax.d.ts +20 -0
- package/dist/src/syntax.js +86 -0
- package/dist/src/table/base.d.ts +30 -0
- package/dist/src/table/base.js +132 -0
- package/dist/src/table/index.d.ts +233 -0
- package/dist/src/table/index.js +396 -0
- package/dist/src/table/td.d.ts +92 -0
- package/dist/src/table/td.js +337 -0
- package/dist/src/table/tr.d.ts +32 -0
- package/dist/src/table/tr.js +58 -0
- package/dist/src/table/trBase.d.ts +53 -0
- package/dist/src/table/trBase.js +154 -0
- package/dist/src/tagPair/ext.d.ts +32 -0
- package/dist/src/tagPair/ext.js +203 -0
- package/dist/src/tagPair/include.d.ts +35 -0
- package/dist/src/tagPair/include.js +63 -0
- package/dist/src/tagPair/index.d.ts +27 -0
- package/dist/src/tagPair/index.js +128 -0
- package/dist/src/transclude.d.ts +167 -0
- package/dist/src/transclude.js +710 -0
- package/dist/util/constants.js +113 -0
- package/dist/util/debug.js +88 -0
- package/dist/util/diff.js +82 -0
- package/dist/util/lint.js +30 -0
- package/dist/util/string.js +53 -0
- package/errors/README +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +15 -30
- package/printed/README +1 -0
- package/bundle/bundle.min.js +0 -36
- package/extensions/dist/base.js +0 -64
- package/extensions/dist/editor.js +0 -159
- package/extensions/dist/highlight.js +0 -59
- package/extensions/dist/lint.js +0 -48
- package/extensions/editor.css +0 -63
- package/extensions/ui.css +0 -141
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promises = exports.typeAliases = exports.aliases = exports.parsers = exports.mixins = exports.classes = exports.BuildMethod = exports.MAX_STAGE = void 0;
|
|
4
|
+
exports.MAX_STAGE = 11;
|
|
5
|
+
var BuildMethod;
|
|
6
|
+
(function (BuildMethod) {
|
|
7
|
+
BuildMethod[BuildMethod["String"] = 0] = "String";
|
|
8
|
+
BuildMethod[BuildMethod["Text"] = 1] = "Text";
|
|
9
|
+
})(BuildMethod || (exports.BuildMethod = BuildMethod = {}));
|
|
10
|
+
/* NOT FOR BROWSER */
|
|
11
|
+
exports.classes = {};
|
|
12
|
+
exports.mixins = {};
|
|
13
|
+
exports.parsers = {};
|
|
14
|
+
exports.aliases = [
|
|
15
|
+
['AstText'],
|
|
16
|
+
['CommentToken', 'ExtToken', 'IncludeToken', 'NoincludeToken'],
|
|
17
|
+
['ArgToken', 'TranscludeToken', 'HeadingToken'],
|
|
18
|
+
['HtmlToken'],
|
|
19
|
+
['TableToken'],
|
|
20
|
+
['HrToken', 'DoubleUnderscoreToken'],
|
|
21
|
+
['LinkToken', 'FileToken', 'CategoryToken'],
|
|
22
|
+
['QuoteToken'],
|
|
23
|
+
['ExtLinkToken'],
|
|
24
|
+
['MagicLinkToken'],
|
|
25
|
+
['ListToken', 'DdToken'],
|
|
26
|
+
['ConverterToken'],
|
|
27
|
+
];
|
|
28
|
+
exports.typeAliases = {
|
|
29
|
+
text: ['string', 'str'],
|
|
30
|
+
plain: ['regular', 'normal'],
|
|
31
|
+
root: undefined,
|
|
32
|
+
// comment and extension
|
|
33
|
+
onlyinclude: ['only-include'],
|
|
34
|
+
noinclude: ['no-include'],
|
|
35
|
+
include: ['includeonly', 'include-only'],
|
|
36
|
+
comment: undefined,
|
|
37
|
+
ext: ['extension'],
|
|
38
|
+
'ext-attrs': ['extension-attrs', 'ext-attributes', 'extension-attributes'],
|
|
39
|
+
'ext-attr-dirty': ['extension-attr-dirty', 'ext-attribute-dirty', 'extension-attribute-dirty'],
|
|
40
|
+
'ext-attr': ['extension-attr', 'ext-attribute', 'extension-attribute'],
|
|
41
|
+
'attr-key': ['attribute-key'],
|
|
42
|
+
'attr-value': ['attribute-value', 'attr-val', 'attribute-val'],
|
|
43
|
+
'ext-inner': ['extension-inner'],
|
|
44
|
+
// triple braces
|
|
45
|
+
arg: ['argument'],
|
|
46
|
+
'arg-name': ['argument-name'],
|
|
47
|
+
'arg-default': ['argument-default'],
|
|
48
|
+
hidden: ['arg-redundant'],
|
|
49
|
+
// double braces
|
|
50
|
+
'magic-word': ['parser-function', 'parser-func'],
|
|
51
|
+
'magic-word-name': ['parser-function-name', 'parser-func-name'],
|
|
52
|
+
'invoke-function': ['invoke-func', 'lua-function', 'lua-func', 'module-function', 'module-func'],
|
|
53
|
+
'invoke-module': ['lua-module'],
|
|
54
|
+
template: undefined,
|
|
55
|
+
'template-name': undefined,
|
|
56
|
+
parameter: ['param'],
|
|
57
|
+
'parameter-key': ['param-key'],
|
|
58
|
+
'parameter-value': ['parameter-val', 'param-value', 'param-val'],
|
|
59
|
+
// heading
|
|
60
|
+
heading: ['header'],
|
|
61
|
+
'heading-title': ['header-title'],
|
|
62
|
+
'heading-trail': ['header-trail'],
|
|
63
|
+
// html
|
|
64
|
+
html: undefined,
|
|
65
|
+
'html-attrs': ['html-attributes'],
|
|
66
|
+
'html-attr-dirty': ['html-attribute-dirty'],
|
|
67
|
+
'html-attr': ['html-attribute'],
|
|
68
|
+
// table
|
|
69
|
+
table: undefined,
|
|
70
|
+
tr: ['table-row'],
|
|
71
|
+
td: ['table-cell', 'table-data'],
|
|
72
|
+
'table-syntax': undefined,
|
|
73
|
+
'table-attrs': ['tr-attrs', 'td-attrs', 'table-attributes', 'tr-attributes', 'td-attributes'],
|
|
74
|
+
'table-attr-dirty': ['tr-attr-dirty', 'td-attr-dirty', 'table-attribute-dirty', 'tr-attribute-dirty', 'td-attribute-dirty'],
|
|
75
|
+
'table-attr': ['tr-attr', 'td-attr', 'table-attribute', 'tr-attribute', 'td-attribute'],
|
|
76
|
+
'table-inter': undefined,
|
|
77
|
+
'td-inner': ['table-cell-inner', 'table-data-inner'],
|
|
78
|
+
// hr and double-underscore
|
|
79
|
+
hr: ['horizontal'],
|
|
80
|
+
'double-underscore': ['underscore', 'behavior-switch', 'behaviour-switch'],
|
|
81
|
+
// link
|
|
82
|
+
link: ['wikilink'],
|
|
83
|
+
'link-target': ['wikilink-target'],
|
|
84
|
+
'link-text': ['wikilink-text'],
|
|
85
|
+
category: ['category-link', 'cat', 'cat-link'],
|
|
86
|
+
file: ['file-link', 'image', 'image-link', 'img', 'img-link'],
|
|
87
|
+
'gallery-image': ['gallery-file', 'gallery-img'],
|
|
88
|
+
'imagemap-image': ['imagemap-file', 'imagemap-img', 'image-map-image', 'image-map-file', 'image-map-img'],
|
|
89
|
+
'image-parameter': ['img-parameter', 'image-param', 'img-param'],
|
|
90
|
+
// quotes
|
|
91
|
+
quote: ['quotes', 'quot', 'apostrophe', 'apostrophes', 'apos'],
|
|
92
|
+
// external link
|
|
93
|
+
'ext-link': ['external-link'],
|
|
94
|
+
'ext-link-text': ['external-link-text'],
|
|
95
|
+
'ext-link-url': ['external-link-url'],
|
|
96
|
+
// magic link
|
|
97
|
+
'free-ext-link': ['free-external-link', 'magic-link'],
|
|
98
|
+
// list
|
|
99
|
+
list: ['ol', 'ordered-list', 'ul', 'unordered-list', 'dl', 'description-list'],
|
|
100
|
+
dd: ['indent', 'indentation'],
|
|
101
|
+
// converter
|
|
102
|
+
converter: ['convert', 'conversion'],
|
|
103
|
+
'converter-flags': ['convert-flags', 'conversion-flags'],
|
|
104
|
+
'converter-flag': ['convert-flag', 'conversion-flag'],
|
|
105
|
+
'converter-rule': ['convert-rule', 'conversion-rule'],
|
|
106
|
+
'converter-rule-variant': ['convert-rule-variant', 'conversion-rule-variant'],
|
|
107
|
+
'converter-rule-to': ['convert-rule-to', 'conversion-rule-to', 'converter-rule-noconvert'],
|
|
108
|
+
'converter-rule-from': ['convert-rule-from', 'conversion-rule-from'],
|
|
109
|
+
// specific extensions
|
|
110
|
+
'param-line': ['parameter-line'],
|
|
111
|
+
'imagemap-link': ['image-map-link'],
|
|
112
|
+
};
|
|
113
|
+
exports.promises = [Promise.resolve()];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.undo = exports.emptyArray = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
|
|
4
|
+
exports.Shadow = {
|
|
5
|
+
running: false,
|
|
6
|
+
/** @private */
|
|
7
|
+
run(callback) {
|
|
8
|
+
/* NOT FOR BROWSER */
|
|
9
|
+
const { running } = this;
|
|
10
|
+
this.running = true;
|
|
11
|
+
try {
|
|
12
|
+
/* NOT FOR BROWSER END */
|
|
13
|
+
const result = callback();
|
|
14
|
+
/* NOT FOR BROWSER */
|
|
15
|
+
this.running = running;
|
|
16
|
+
/* NOT FOR BROWSER END */
|
|
17
|
+
return result;
|
|
18
|
+
/* NOT FOR BROWSER */
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
this.running = running;
|
|
22
|
+
throw e;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 是否是某一特定类型的节点
|
|
28
|
+
* @param type 节点类型
|
|
29
|
+
*/
|
|
30
|
+
const isToken = (type) => (node) => node.type === type;
|
|
31
|
+
exports.isToken = isToken;
|
|
32
|
+
/**
|
|
33
|
+
* 更新chldNodes
|
|
34
|
+
* @param parent 父节点
|
|
35
|
+
* @param position 子节点位置
|
|
36
|
+
* @param deleteCount 移除的子节点数量
|
|
37
|
+
* @param inserted 插入的子节点
|
|
38
|
+
*/
|
|
39
|
+
const setChildNodes = (parent, position, deleteCount, inserted = []) => {
|
|
40
|
+
const childNodes = [...parent.childNodes], removed = childNodes.splice(position, deleteCount, ...inserted);
|
|
41
|
+
parent.setAttribute('childNodes', childNodes);
|
|
42
|
+
for (const node of inserted) {
|
|
43
|
+
node.setAttribute('parentNode', parent);
|
|
44
|
+
}
|
|
45
|
+
/* NOT FOR BROWSER */
|
|
46
|
+
for (const node of removed) {
|
|
47
|
+
node.setAttribute('parentNode', undefined);
|
|
48
|
+
}
|
|
49
|
+
/* NOT FOR BROWSER END */
|
|
50
|
+
return removed;
|
|
51
|
+
};
|
|
52
|
+
exports.setChildNodes = setChildNodes;
|
|
53
|
+
/* NOT FOR BROWSER */
|
|
54
|
+
/**
|
|
55
|
+
* 生成一个指定长度的空数组
|
|
56
|
+
* @param n 数组长度
|
|
57
|
+
* @param callback 回调函数
|
|
58
|
+
*/
|
|
59
|
+
const emptyArray = (n, callback) => new Array(n).fill(undefined).map((_, i) => callback(i));
|
|
60
|
+
exports.emptyArray = emptyArray;
|
|
61
|
+
/**
|
|
62
|
+
* 撤销最近一次Mutation
|
|
63
|
+
* @param e 事件
|
|
64
|
+
* @param data 事件数据
|
|
65
|
+
* @throws `RangeError` 无法撤销的事件类型
|
|
66
|
+
*/
|
|
67
|
+
const undo = (e, data) => {
|
|
68
|
+
const { target, type } = e;
|
|
69
|
+
switch (data.type) {
|
|
70
|
+
case 'remove':
|
|
71
|
+
(0, exports.setChildNodes)(target, data.position, 0, [data.removed]);
|
|
72
|
+
break;
|
|
73
|
+
case 'insert':
|
|
74
|
+
(0, exports.setChildNodes)(target, data.position, 1);
|
|
75
|
+
break;
|
|
76
|
+
case 'replace':
|
|
77
|
+
(0, exports.setChildNodes)(target.parentNode, data.position, 1, [data.oldToken]);
|
|
78
|
+
break;
|
|
79
|
+
case 'text':
|
|
80
|
+
if (target.type === 'text') {
|
|
81
|
+
target.replaceData(data.oldText);
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
throw new RangeError(`无法撤销未知类型的事件:${String(type)}`);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
exports.undo = undo;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.info = exports.error = exports.diff = exports.cmd = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
process.on('unhandledRejection', e => {
|
|
7
|
+
console.error(e);
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* 将shell命令转化为Promise对象
|
|
11
|
+
* @param command shell指令
|
|
12
|
+
* @param args shell输入参数
|
|
13
|
+
*/
|
|
14
|
+
const cmd = (command, args) => new Promise(resolve => {
|
|
15
|
+
let timer, shell;
|
|
16
|
+
/**
|
|
17
|
+
* 清除进程并返回
|
|
18
|
+
* @param val 返回值
|
|
19
|
+
*/
|
|
20
|
+
const r = (val) => {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
shell?.kill('SIGINT');
|
|
23
|
+
resolve(val);
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
shell = (0, child_process_1.spawn)(command, args);
|
|
27
|
+
timer = setTimeout(() => {
|
|
28
|
+
shell.kill('SIGINT');
|
|
29
|
+
}, 60 * 1000);
|
|
30
|
+
let buf = '';
|
|
31
|
+
shell.stdout.on('data', data => {
|
|
32
|
+
buf += String(data);
|
|
33
|
+
});
|
|
34
|
+
shell.stdout.on('end', () => {
|
|
35
|
+
r(buf);
|
|
36
|
+
});
|
|
37
|
+
shell.on('exit', () => {
|
|
38
|
+
r(shell.killed ? undefined : '');
|
|
39
|
+
});
|
|
40
|
+
shell.on('error', () => {
|
|
41
|
+
r(undefined);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
r(undefined);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
exports.cmd = cmd;
|
|
49
|
+
/**
|
|
50
|
+
* 比较两个文件
|
|
51
|
+
* @param oldStr 旧文本
|
|
52
|
+
* @param newStr 新文本
|
|
53
|
+
* @param uid 唯一标识
|
|
54
|
+
*/
|
|
55
|
+
const diff = async (oldStr, newStr, uid = -1) => {
|
|
56
|
+
if (oldStr === newStr) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const oldFile = `diffOld${uid}`, newFile = `diffNew${uid}`;
|
|
60
|
+
await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
|
|
61
|
+
const stdout = await (0, exports.cmd)('git', [
|
|
62
|
+
'diff',
|
|
63
|
+
'--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
|
|
64
|
+
'-U0',
|
|
65
|
+
'--no-index',
|
|
66
|
+
oldFile,
|
|
67
|
+
newFile,
|
|
68
|
+
]);
|
|
69
|
+
await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
|
|
70
|
+
console.log(stdout?.split('\n').slice(4).join('\n'));
|
|
71
|
+
};
|
|
72
|
+
exports.diff = diff;
|
|
73
|
+
/** @implements */
|
|
74
|
+
const error = (msg, ...args) => {
|
|
75
|
+
console.error('\x1B[31m%s\x1B[0m', msg, ...args);
|
|
76
|
+
};
|
|
77
|
+
exports.error = error;
|
|
78
|
+
/** @implements */
|
|
79
|
+
const info = (msg, ...args) => {
|
|
80
|
+
console.info('\x1B[32m%s\x1B[0m', msg, ...args);
|
|
81
|
+
};
|
|
82
|
+
exports.info = info;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateForSelf = exports.generateForChild = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
/**
|
|
6
|
+
* 生成lint函数
|
|
7
|
+
* @param func lint函数
|
|
8
|
+
*/
|
|
9
|
+
const factory = (func) => (token, boundingRect, msg, severity = 'error') => {
|
|
10
|
+
const { start } = boundingRect, { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start), { offsetHeight, offsetWidth } = token, { startIndex, startLine, startCol } = func(token, start, top, left);
|
|
11
|
+
return {
|
|
12
|
+
message: index_1.default.msg(msg),
|
|
13
|
+
severity,
|
|
14
|
+
startIndex,
|
|
15
|
+
endIndex: startIndex + String(token).length,
|
|
16
|
+
startLine,
|
|
17
|
+
endLine: startLine + offsetHeight - 1,
|
|
18
|
+
startCol,
|
|
19
|
+
endCol: offsetHeight === 1 ? startCol + offsetWidth : offsetWidth,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.generateForChild = factory((child, start, line, col) => {
|
|
23
|
+
const index = child.getRelativeIndex(), { top, left } = child.parentNode.posFromIndex(index);
|
|
24
|
+
return {
|
|
25
|
+
startIndex: start + index,
|
|
26
|
+
startLine: line + top,
|
|
27
|
+
startCol: top ? left : col + left,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
exports.generateForSelf = factory((_, startIndex, startLine, startCol) => ({ startIndex, startLine, startCol }));
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeSpace = exports.print = exports.noWrap = exports.decodeHtml = exports.text = exports.escapeRegExp = exports.removeComment = exports.tidy = 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
|
+
* 生成正则替换函数
|
|
8
|
+
* @param regex 正则表达式
|
|
9
|
+
* @param replace 替换字符串或函数
|
|
10
|
+
*/
|
|
11
|
+
const factory = (regex, replace) => (str) => str.replace(regex, replace);
|
|
12
|
+
/** 清理解析专用的不可见字符 */
|
|
13
|
+
exports.tidy = factory(/[\0\x7F]/gu, '');
|
|
14
|
+
/** remove half-parsed comment-like tokens */
|
|
15
|
+
exports.removeComment = factory(/\0\d+c\x7F/gu, '');
|
|
16
|
+
/** escape special chars for RegExp constructor */
|
|
17
|
+
exports.escapeRegExp = factory(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
|
|
18
|
+
/**
|
|
19
|
+
* extract effective wikitext
|
|
20
|
+
* @param childNodes a Token's contents
|
|
21
|
+
* @param separator delimiter between nodes
|
|
22
|
+
*/
|
|
23
|
+
const text = (childNodes, separator = '') => childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
24
|
+
exports.text = text;
|
|
25
|
+
/** decode HTML entities */
|
|
26
|
+
exports.decodeHtml = factory(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number(`${code.toLowerCase().startsWith('x') ? '0' : ''}${code}`)));
|
|
27
|
+
/** escape newlines */
|
|
28
|
+
exports.noWrap = factory(/\n/gu, '\\n');
|
|
29
|
+
/**
|
|
30
|
+
* 以HTML格式打印
|
|
31
|
+
* @param childNodes 子节点
|
|
32
|
+
* @param opt 选项
|
|
33
|
+
*/
|
|
34
|
+
const print = (childNodes, opt = {}) => {
|
|
35
|
+
const { pre = '', post = '', sep = '' } = opt;
|
|
36
|
+
return `${pre}${childNodes.map(child => child.print()).join(sep)}${post}`;
|
|
37
|
+
};
|
|
38
|
+
exports.print = print;
|
|
39
|
+
/* NOT FOR BROWSER */
|
|
40
|
+
/**
|
|
41
|
+
* convert newline in text nodes to single whitespace
|
|
42
|
+
* @param token 父节点
|
|
43
|
+
*/
|
|
44
|
+
const normalizeSpace = (token) => {
|
|
45
|
+
if (token) {
|
|
46
|
+
for (const child of token.childNodes) {
|
|
47
|
+
if (child.type === 'text') {
|
|
48
|
+
child.replaceData(child.data.replace(/\n+/gu, ' '));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.normalizeSpace = normalizeSpace;
|
package/errors/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
这里记录解析失败时处于半解析状态的维基文本以及错误信息。
|
package/i18n/zh-hans.json
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"HTML tag in table attributes": "表格属性中的HTML标签",
|
|
22
22
|
"illegal attribute name": "非法的属性名",
|
|
23
23
|
"illegal module name": "非法的模块名称",
|
|
24
|
+
"inconsistent table layout": "不一致的表格布局",
|
|
24
25
|
"insecure style": "不安全的样式",
|
|
25
26
|
"internal link in an external link": "外链中的内链",
|
|
26
27
|
"invalid content in <$1>": "<$1>内的无效内容",
|
package/i18n/zh-hant.json
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"HTML tag in table attributes": "表格屬性中的HTML標籤",
|
|
22
22
|
"illegal attribute name": "非法的屬性名",
|
|
23
23
|
"illegal module name": "非法的模組名稱",
|
|
24
|
+
"inconsistent table layout": "不一致的表格佈局",
|
|
24
25
|
"insecure style": "不安全的樣式",
|
|
25
26
|
"internal link in an external link": "外部連結中的內部連結",
|
|
26
27
|
"invalid content in <$1>": "<$1>內的無效內容",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiparser-node",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "A Node.js parser for MediaWiki markup with AST",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -14,52 +14,40 @@
|
|
|
14
14
|
"license": "GPL-3.0",
|
|
15
15
|
"author": "Bhsd",
|
|
16
16
|
"files": [
|
|
17
|
-
"/
|
|
18
|
-
"/
|
|
19
|
-
"/extensions/*.css",
|
|
20
|
-
"!/extensions/dist/gh-page.js",
|
|
21
|
-
"!/extensions/gh-page.css",
|
|
17
|
+
"/errors/README",
|
|
18
|
+
"/printed/README",
|
|
22
19
|
"/config/",
|
|
23
20
|
"/i18n/",
|
|
24
|
-
"
|
|
21
|
+
"/dist/",
|
|
22
|
+
"!/dist/[bt]*/"
|
|
25
23
|
],
|
|
26
|
-
"
|
|
27
|
-
"main": "./bundle/bundle.js",
|
|
28
|
-
"types": "./extensions/typings.d.ts",
|
|
24
|
+
"main": "./dist/index.js",
|
|
29
25
|
"repository": {
|
|
30
26
|
"type": "git",
|
|
31
27
|
"url": "git+https://github.com/bhsd-harry/wikiparser-node.git"
|
|
32
28
|
},
|
|
33
29
|
"scripts": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"build
|
|
38
|
-
"
|
|
39
|
-
"build": "npm run build:core && npm run build:ext",
|
|
40
|
-
"diff": "git diff --ignore-all-space --color-moved",
|
|
30
|
+
"toc": "node ./dist/bin/toc.js",
|
|
31
|
+
"declaration": "grep -rl --include='*.d.ts' '@private' dist/ | xargs bash sed.sh -i -E '/^\\s+\\/\\*\\* @private/,+1d'; node ./dist/bin/declaration.js",
|
|
32
|
+
"prepublishOnly": "npm run build && rm dist/internal.js dist/base.js dist/[pu]*/*.d.ts",
|
|
33
|
+
"build": "bash build.sh",
|
|
34
|
+
"diff": "bash diff.sh",
|
|
41
35
|
"diff:stat": "f() { git diff --stat --ignore-all-space --color=always $1 $2 -- . ':!extensions/' ':!bin/' | grep '\\.ts'; }; f",
|
|
42
|
-
"lint:ts": "tsc --noEmit &&
|
|
36
|
+
"lint:ts": "tsc --noEmit && eslint --cache .",
|
|
43
37
|
"lint:json": "ajv -s config/.schema.json -d 'config/*.json' --strict=true --strict-required=false",
|
|
44
|
-
"lint
|
|
45
|
-
"
|
|
46
|
-
"server": "npm run test:end; http-server .. -c-1 --cors &",
|
|
47
|
-
"test": "npm run build:prod && npm run build:ext && npm run server",
|
|
38
|
+
"lint": "npm run lint:ts && npm run lint:json",
|
|
39
|
+
"test": "node dist/test/test.js",
|
|
48
40
|
"test:end": "pkill -x http-server",
|
|
49
|
-
"test:real": "
|
|
41
|
+
"test:real": "node dist/test/real.js"
|
|
50
42
|
},
|
|
51
43
|
"devDependencies": {
|
|
52
|
-
"@bhsd/codemirror-mediawiki": "^2.1.11",
|
|
53
|
-
"@codemirror/lint": "^6.4.2",
|
|
54
44
|
"@cypress/request": "^3.0.1",
|
|
55
45
|
"@stylistic/eslint-plugin": "^1.5.4",
|
|
56
|
-
"@stylistic/stylelint-plugin": "^2.0.0",
|
|
57
46
|
"@types/node": "^20.11.6",
|
|
58
47
|
"@types/request": "^2.48.12",
|
|
59
48
|
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
60
49
|
"@typescript-eslint/parser": "^6.19.1",
|
|
61
50
|
"ajv-cli": "^5.0.0",
|
|
62
|
-
"esbuild": "^0.19.12",
|
|
63
51
|
"eslint": "^8.56.0",
|
|
64
52
|
"eslint-plugin-es-x": "^7.5.0",
|
|
65
53
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
@@ -69,9 +57,6 @@
|
|
|
69
57
|
"eslint-plugin-promise": "^6.1.1",
|
|
70
58
|
"eslint-plugin-regexp": "^2.2.0",
|
|
71
59
|
"eslint-plugin-unicorn": "^50.0.1",
|
|
72
|
-
"http-server": "^14.1.0",
|
|
73
|
-
"stylelint": "^16.1.0",
|
|
74
|
-
"stylelint-config-recommended": "^14.0.0",
|
|
75
60
|
"typescript": "^5.3.3"
|
|
76
61
|
},
|
|
77
62
|
"engines": {
|
package/printed/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
这里存放以 JSON 格式打印的 AST。
|