wikiparser-node 0.7.0-m → 0.7.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/README.md +39 -0
- package/config/llwiki.json +35 -0
- package/config/moegirl.json +44 -0
- package/config/zhwiki.json +466 -0
- package/index.js +259 -11
- package/lib/element.js +481 -7
- package/lib/node.js +552 -6
- package/lib/ranges.js +130 -0
- package/lib/text.js +112 -21
- package/lib/title.js +27 -0
- package/mixin/attributeParent.js +117 -0
- package/mixin/fixedToken.js +40 -0
- package/mixin/hidden.js +3 -0
- package/mixin/singleLine.js +31 -0
- package/mixin/sol.js +65 -0
- package/package.json +5 -4
- package/parser/brackets.js +1 -0
- package/parser/commentAndExt.js +4 -3
- package/parser/converter.js +1 -0
- package/parser/externalLinks.js +1 -0
- package/parser/hrAndDoubleUnderscore.js +1 -0
- package/parser/html.js +1 -0
- package/parser/links.js +5 -4
- package/parser/list.js +1 -0
- package/parser/magicLinks.js +5 -4
- package/parser/quotes.js +2 -1
- package/parser/selector.js +177 -0
- package/parser/table.js +1 -0
- package/src/arg.js +116 -2
- package/src/atom/hidden.js +2 -0
- package/src/atom/index.js +17 -0
- package/src/attribute.js +171 -4
- package/src/attributes.js +306 -4
- package/src/charinsert.js +57 -1
- package/src/converter.js +108 -2
- package/src/converterFlags.js +187 -0
- package/src/converterRule.js +184 -1
- package/src/extLink.js +120 -1
- package/src/gallery.js +55 -5
- package/src/hasNowiki/index.js +12 -0
- package/src/hasNowiki/pre.js +12 -0
- package/src/heading.js +55 -4
- package/src/html.js +118 -3
- package/src/imageParameter.js +176 -5
- package/src/imagemap.js +60 -1
- package/src/imagemapLink.js +13 -1
- package/src/index.js +527 -3
- package/src/link/category.js +37 -1
- package/src/link/file.js +159 -2
- package/src/link/galleryImage.js +59 -1
- package/src/link/index.js +269 -1
- package/src/magicLink.js +90 -9
- package/src/nested/choose.js +1 -0
- package/src/nested/combobox.js +1 -0
- package/src/nested/index.js +30 -3
- package/src/nested/references.js +1 -0
- package/src/nowiki/comment.js +25 -1
- package/src/nowiki/dd.js +47 -1
- package/src/nowiki/doubleUnderscore.js +31 -1
- package/src/nowiki/hr.js +20 -1
- package/src/nowiki/index.js +23 -1
- package/src/nowiki/list.js +5 -2
- package/src/nowiki/noinclude.js +14 -0
- package/src/nowiki/quote.js +16 -2
- package/src/onlyinclude.js +26 -1
- package/src/paramTag/index.js +24 -1
- package/src/paramTag/inputbox.js +44 -0
- package/src/parameter.js +148 -6
- package/src/syntax.js +68 -0
- package/src/table/index.js +940 -2
- package/src/table/td.js +225 -5
- package/src/table/tr.js +247 -2
- package/src/tagPair/ext.js +24 -4
- package/src/tagPair/include.js +24 -0
- package/src/tagPair/index.js +52 -2
- package/src/transclude.js +512 -11
- package/tool/index.js +1202 -0
- package/util/debug.js +73 -0
- package/util/string.js +48 -1
- package/config/minimum.json +0 -142
package/util/debug.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 定制TypeError消息
|
|
5
|
+
* @param {Function} constructor 类
|
|
6
|
+
* @param {string} method
|
|
7
|
+
* @param {...string} args 可接受的参数类型
|
|
8
|
+
* @throws `TypeError`
|
|
9
|
+
*/
|
|
10
|
+
const typeError = ({name}, method, ...args) => {
|
|
11
|
+
throw new TypeError(`${name}.${method} 方法仅接受 ${args.join('、')} 作为输入参数!`);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 不是被构造器或原型方法调用
|
|
16
|
+
* @param {string} name 方法名称
|
|
17
|
+
*/
|
|
18
|
+
const externalUse = name => {
|
|
19
|
+
const Parser = require('..');
|
|
20
|
+
if (Parser.running) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const regex = new RegExp(`^new \\w*Token$|^(?:Ast\\w*|\\w*Token)\\.(?!${name}$)`, 'u');
|
|
24
|
+
try {
|
|
25
|
+
throw new Error(); // eslint-disable-line unicorn/error-message
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (e instanceof Error) {
|
|
28
|
+
const mt = e.stack.match(/(?<=^\s+at )(?:new )?[\w.]+(?= \(\/)/gmu);
|
|
29
|
+
return !mt.slice(2).some(func => regex.test(func));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 撤销最近一次Mutation
|
|
37
|
+
* @param {AstEvent} e 事件
|
|
38
|
+
* @param {AstEventData} data 事件数据
|
|
39
|
+
* @throws `RangeError` 无法撤销的事件类型
|
|
40
|
+
*/
|
|
41
|
+
const undo = (e, data) => {
|
|
42
|
+
const {target, type} = e;
|
|
43
|
+
switch (type) {
|
|
44
|
+
case 'remove': {
|
|
45
|
+
const childNodes = [...target.childNodes];
|
|
46
|
+
childNodes.splice(data.position, 0, data.removed);
|
|
47
|
+
data.removed.setAttribute('parentNode', target);
|
|
48
|
+
target.setAttribute('childNodes', childNodes);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 'insert': {
|
|
52
|
+
const childNodes = [...target.childNodes];
|
|
53
|
+
childNodes.splice(data.position, 1);
|
|
54
|
+
target.setAttribute('childNodes', childNodes);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case 'replace': {
|
|
58
|
+
const {parentNode} = target,
|
|
59
|
+
childNodes = [...parentNode.childNodes];
|
|
60
|
+
childNodes.splice(data.position, 1, data.oldToken);
|
|
61
|
+
data.oldToken.setAttribute('parentNode', parentNode);
|
|
62
|
+
parentNode.setAttribute('childNodes', childNodes);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case 'text':
|
|
66
|
+
target.replaceData(data.oldText);
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
throw new RangeError(`无法撤销未知类型的事件:${type}`);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
module.exports = {typeError, externalUse, undo};
|
package/util/string.js
CHANGED
|
@@ -9,6 +9,23 @@ const extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uF
|
|
|
9
9
|
*/
|
|
10
10
|
const removeComment = str => str.replace(/\0\d+c\x7F/gu, '');
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* 以HTML格式打印
|
|
14
|
+
* @param {(AstText|AstElement)[]} childNodes 子节点
|
|
15
|
+
* @param {printOpt} opt 选项
|
|
16
|
+
*/
|
|
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).replace(/[&<>]/gu, p => `&${entities[p]};`),
|
|
26
|
+
).join(sep)}${post}`;
|
|
27
|
+
};
|
|
28
|
+
|
|
12
29
|
/**
|
|
13
30
|
* escape special chars for RegExp constructor
|
|
14
31
|
* @param {string} str RegExp source
|
|
@@ -55,6 +72,36 @@ const text = (childNodes, separator = '') => {
|
|
|
55
72
|
return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
56
73
|
};
|
|
57
74
|
|
|
75
|
+
/**
|
|
76
|
+
* optionally convert to lower cases
|
|
77
|
+
* @param {string} val 属性值
|
|
78
|
+
* @param {string|undefined} i 是否对大小写不敏感
|
|
79
|
+
*/
|
|
80
|
+
const toCase = (val, i) => i ? val.toLowerCase() : val;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* escape newlines
|
|
84
|
+
* @param {string} str 原字符串
|
|
85
|
+
*/
|
|
86
|
+
const noWrap = str => str.replaceAll('\n', '\\n');
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* convert newline in text nodes to single whitespace
|
|
90
|
+
* @param {Token & {childNodes: AstText[]}} token 父节点
|
|
91
|
+
*/
|
|
92
|
+
const normalizeSpace = token => {
|
|
93
|
+
if (token === undefined) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const Token = require('../src'),
|
|
97
|
+
AstText = require('../lib/text');
|
|
98
|
+
for (const child of token.childNodes) {
|
|
99
|
+
if (child.type === 'text') {
|
|
100
|
+
child.replaceData(child.data.replaceAll('\n', ' '));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
58
105
|
module.exports = {
|
|
59
|
-
extUrlCharFirst, extUrlChar, removeComment, escapeRegExp, explode, text,
|
|
106
|
+
extUrlCharFirst, extUrlChar, removeComment, print, escapeRegExp, explode, text, toCase, noWrap, normalizeSpace,
|
|
60
107
|
};
|
package/config/minimum.json
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ext": [],
|
|
3
|
-
"html": [
|
|
4
|
-
[
|
|
5
|
-
"b",
|
|
6
|
-
"bdi",
|
|
7
|
-
"del",
|
|
8
|
-
"i",
|
|
9
|
-
"ins",
|
|
10
|
-
"u",
|
|
11
|
-
"font",
|
|
12
|
-
"big",
|
|
13
|
-
"small",
|
|
14
|
-
"sub",
|
|
15
|
-
"sup",
|
|
16
|
-
"h1",
|
|
17
|
-
"h2",
|
|
18
|
-
"h3",
|
|
19
|
-
"h4",
|
|
20
|
-
"h5",
|
|
21
|
-
"h6",
|
|
22
|
-
"cite",
|
|
23
|
-
"code",
|
|
24
|
-
"em",
|
|
25
|
-
"s",
|
|
26
|
-
"strike",
|
|
27
|
-
"strong",
|
|
28
|
-
"tt",
|
|
29
|
-
"var",
|
|
30
|
-
"div",
|
|
31
|
-
"center",
|
|
32
|
-
"blockquote",
|
|
33
|
-
"ol",
|
|
34
|
-
"ul",
|
|
35
|
-
"dl",
|
|
36
|
-
"table",
|
|
37
|
-
"caption",
|
|
38
|
-
"pre",
|
|
39
|
-
"ruby",
|
|
40
|
-
"rb",
|
|
41
|
-
"rp",
|
|
42
|
-
"rt",
|
|
43
|
-
"rtc",
|
|
44
|
-
"p",
|
|
45
|
-
"span",
|
|
46
|
-
"abbr",
|
|
47
|
-
"dfn",
|
|
48
|
-
"kbd",
|
|
49
|
-
"samp",
|
|
50
|
-
"data",
|
|
51
|
-
"time",
|
|
52
|
-
"mark",
|
|
53
|
-
"tr",
|
|
54
|
-
"td",
|
|
55
|
-
"th",
|
|
56
|
-
"q",
|
|
57
|
-
"bdo"
|
|
58
|
-
],
|
|
59
|
-
[
|
|
60
|
-
"li",
|
|
61
|
-
"dt",
|
|
62
|
-
"dd"
|
|
63
|
-
],
|
|
64
|
-
[
|
|
65
|
-
"br",
|
|
66
|
-
"wbr",
|
|
67
|
-
"hr",
|
|
68
|
-
"meta",
|
|
69
|
-
"link",
|
|
70
|
-
"img"
|
|
71
|
-
]
|
|
72
|
-
],
|
|
73
|
-
"namespaces": {},
|
|
74
|
-
"nsid": {},
|
|
75
|
-
"parserFunction": [
|
|
76
|
-
{
|
|
77
|
-
"#language": "language",
|
|
78
|
-
"#special": "special",
|
|
79
|
-
"#speciale": "speciale",
|
|
80
|
-
"#tag": "tag",
|
|
81
|
-
"#formatdate": "formatdate",
|
|
82
|
-
"#invoke": "invoke",
|
|
83
|
-
"#while": "while",
|
|
84
|
-
"#dowhile": "dowhile",
|
|
85
|
-
"#loop": "loop",
|
|
86
|
-
"#forargs": "forargs",
|
|
87
|
-
"#fornumargs": "fornumargs",
|
|
88
|
-
"#if": "if",
|
|
89
|
-
"#ifeq": "ifeq",
|
|
90
|
-
"#switch": "switch",
|
|
91
|
-
"#ifexist": "ifexist",
|
|
92
|
-
"#ifexpr": "ifexpr",
|
|
93
|
-
"#iferror": "iferror",
|
|
94
|
-
"#time": "time",
|
|
95
|
-
"#timel": "timel",
|
|
96
|
-
"#expr": "expr",
|
|
97
|
-
"#rel2abs": "rel2abs",
|
|
98
|
-
"#titleparts": "titleparts",
|
|
99
|
-
"#categorytree": "categorytree",
|
|
100
|
-
"#urldecode": "urldecode",
|
|
101
|
-
"#choose": "choose",
|
|
102
|
-
"#var": "var",
|
|
103
|
-
"#varexists": "varexists",
|
|
104
|
-
"#var_final": "var_final",
|
|
105
|
-
"#vardefine": "vardefine",
|
|
106
|
-
"#vardefineecho": "vardefineecho",
|
|
107
|
-
"#widget": "widget",
|
|
108
|
-
"#related": "related",
|
|
109
|
-
"#cscore": "cscore"
|
|
110
|
-
},
|
|
111
|
-
[],
|
|
112
|
-
[
|
|
113
|
-
"msg",
|
|
114
|
-
"原始",
|
|
115
|
-
"raw"
|
|
116
|
-
],
|
|
117
|
-
[
|
|
118
|
-
"替代",
|
|
119
|
-
"subst",
|
|
120
|
-
"安全替代",
|
|
121
|
-
"safesubst"
|
|
122
|
-
]
|
|
123
|
-
],
|
|
124
|
-
"doubleUnderscore": [
|
|
125
|
-
[],
|
|
126
|
-
[]
|
|
127
|
-
],
|
|
128
|
-
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
|
|
129
|
-
"interwiki": [],
|
|
130
|
-
"img": {},
|
|
131
|
-
"variants": [
|
|
132
|
-
"zh",
|
|
133
|
-
"zh-hans",
|
|
134
|
-
"zh-hant",
|
|
135
|
-
"zh-cn",
|
|
136
|
-
"zh-tw",
|
|
137
|
-
"zh-hk",
|
|
138
|
-
"zh-sg",
|
|
139
|
-
"zh-my",
|
|
140
|
-
"zh-mo"
|
|
141
|
-
]
|
|
142
|
-
}
|