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/printed/example.json
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"type": "root",
|
|
3
|
-
"childNodes": [
|
|
4
|
-
{
|
|
5
|
-
"type": "ext",
|
|
6
|
-
"name": "ref",
|
|
7
|
-
"childNodes": [
|
|
8
|
-
{
|
|
9
|
-
"type": "ext-attr",
|
|
10
|
-
"name": "ref",
|
|
11
|
-
"childNodes": [
|
|
12
|
-
""
|
|
13
|
-
]
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"type": "ext-inner",
|
|
17
|
-
"name": "ref",
|
|
18
|
-
"childNodes": [
|
|
19
|
-
{
|
|
20
|
-
"type": "template",
|
|
21
|
-
"name": "Template:T",
|
|
22
|
-
"childNodes": [
|
|
23
|
-
{
|
|
24
|
-
"type": "template-name",
|
|
25
|
-
"childNodes": [
|
|
26
|
-
"T"
|
|
27
|
-
]
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"type": "parameter",
|
|
31
|
-
"name": "1",
|
|
32
|
-
"childNodes": [
|
|
33
|
-
{
|
|
34
|
-
"type": "parameter-key",
|
|
35
|
-
"childNodes": []
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"type": "parameter-value",
|
|
39
|
-
"childNodes": [
|
|
40
|
-
{
|
|
41
|
-
"type": "html",
|
|
42
|
-
"name": "br",
|
|
43
|
-
"childNodes": [
|
|
44
|
-
{
|
|
45
|
-
"type": "html-attr",
|
|
46
|
-
"name": "br",
|
|
47
|
-
"childNodes": [
|
|
48
|
-
""
|
|
49
|
-
]
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
},
|
|
53
|
-
"\n",
|
|
54
|
-
{
|
|
55
|
-
"type": "hr",
|
|
56
|
-
"childNodes": [
|
|
57
|
-
"----"
|
|
58
|
-
]
|
|
59
|
-
},
|
|
60
|
-
"\n",
|
|
61
|
-
{
|
|
62
|
-
"type": "file",
|
|
63
|
-
"name": "File:F",
|
|
64
|
-
"childNodes": [
|
|
65
|
-
{
|
|
66
|
-
"type": "link-target",
|
|
67
|
-
"childNodes": [
|
|
68
|
-
"File:F"
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"type": "image-parameter",
|
|
73
|
-
"name": "thumbnail",
|
|
74
|
-
"childNodes": []
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
"type": "image-parameter",
|
|
78
|
-
"name": "caption",
|
|
79
|
-
"childNodes": [
|
|
80
|
-
{
|
|
81
|
-
"type": "quote",
|
|
82
|
-
"name": "2",
|
|
83
|
-
"childNodes": [
|
|
84
|
-
"''"
|
|
85
|
-
]
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
"type": "ext-link",
|
|
89
|
-
"childNodes": [
|
|
90
|
-
{
|
|
91
|
-
"type": "ext-link-url",
|
|
92
|
-
"childNodes": [
|
|
93
|
-
"//example.net"
|
|
94
|
-
]
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"type": "quote",
|
|
100
|
-
"name": "2",
|
|
101
|
-
"childNodes": [
|
|
102
|
-
"''"
|
|
103
|
-
]
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
]
|
|
112
|
-
}
|
|
113
|
-
]
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
]
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
}
|
package/test/api.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/** @file 为MediaWiki API请求提供Promise界面 */
|
|
2
|
-
'use strict';
|
|
3
|
-
const request = require('request'),
|
|
4
|
-
{sleep} = require('./util'),
|
|
5
|
-
{info} = require('..');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 规范化API请求参数
|
|
9
|
-
* @param {Record<string, string|number|boolean|(string|number)[]>} obj 请求参数
|
|
10
|
-
* @returns {Record<string, string}
|
|
11
|
-
* @throws `TypeError` 部分参数不是字符串或数字
|
|
12
|
-
*/
|
|
13
|
-
const normalizeValues = obj => {
|
|
14
|
-
for (const [key, val] of Object.entries(obj)) {
|
|
15
|
-
if (val === undefined || val === false) {
|
|
16
|
-
delete obj[key];
|
|
17
|
-
} else if (val === true) {
|
|
18
|
-
obj[key] = 1;
|
|
19
|
-
} else if (Array.isArray(val)) {
|
|
20
|
-
obj[key] = val.join('|');
|
|
21
|
-
} else if (typeof val !== 'string' && typeof val !== 'number') {
|
|
22
|
-
throw new TypeError('API请求的各项参数均为字符串或数字!');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return obj;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/** 通用MediaWiki站点的请求 */
|
|
29
|
-
class Api {
|
|
30
|
-
url;
|
|
31
|
-
request = request.defaults({jar: true});
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {string} url 网址
|
|
35
|
-
* @throws `RangeError` 无效网址
|
|
36
|
-
*/
|
|
37
|
-
constructor(url) {
|
|
38
|
-
try {
|
|
39
|
-
new URL(url);
|
|
40
|
-
} catch {
|
|
41
|
-
throw new RangeError('不是有效的网址!');
|
|
42
|
-
}
|
|
43
|
-
this.url = url;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* GET请求
|
|
48
|
-
* @param {Record<string, string|number|boolean|(string|number)[]>} params 请求参数
|
|
49
|
-
* @returns {Promise<any>}
|
|
50
|
-
*/
|
|
51
|
-
async get(params) {
|
|
52
|
-
params = normalizeValues(params);
|
|
53
|
-
const /** @type {Record<string, string|number>} */ qs = {
|
|
54
|
-
action: 'query', format: 'json', formatversion: 2, errorformat: 'plaintext', ...params,
|
|
55
|
-
};
|
|
56
|
-
try {
|
|
57
|
-
return await new Promise((resolve, reject) => {
|
|
58
|
-
this.request.get({url: this.url, qs}, (e, response, body) => {
|
|
59
|
-
const statusCode = response?.statusCode;
|
|
60
|
-
if (e) {
|
|
61
|
-
reject({statusCode, ...e});
|
|
62
|
-
} else {
|
|
63
|
-
try {
|
|
64
|
-
const data = JSON.parse(body);
|
|
65
|
-
resolve(data);
|
|
66
|
-
} catch {
|
|
67
|
-
reject({statusCode, body});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
} catch (e) {
|
|
73
|
-
if ([500, 502, 504].includes(e.statusCode)) {
|
|
74
|
-
info(`对网址 ${this.url} 发出的GET请求触发错误代码 ${e.statusCode},30秒后将再次尝试。`);
|
|
75
|
-
await sleep(30);
|
|
76
|
-
return this.get(params);
|
|
77
|
-
}
|
|
78
|
-
throw e;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
module.exports = Api;
|
package/test/real.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {diff} = require('./util'),
|
|
4
|
-
Api = require('./api'),
|
|
5
|
-
Parser = require('../'),
|
|
6
|
-
AstText = require('../lib/text');
|
|
7
|
-
|
|
8
|
-
const {argv: [,, site = '']} = process,
|
|
9
|
-
apis = [
|
|
10
|
-
['LLWiki', 'https://llwiki.org/mediawiki', 'llwiki'],
|
|
11
|
-
['萌娘百科', 'https://zh.moegirl.org.cn', 'moegirl'],
|
|
12
|
-
['维基百科', 'https://zh.wikipedia.org/w', 'zhwiki'],
|
|
13
|
-
].filter(([name]) => name.toLowerCase().includes(site.toLowerCase())),
|
|
14
|
-
complexOrHiddenTypes = [
|
|
15
|
-
// 以下为子节点必为Token的类
|
|
16
|
-
'ext',
|
|
17
|
-
'arg',
|
|
18
|
-
'template',
|
|
19
|
-
'magic-word',
|
|
20
|
-
'parameter',
|
|
21
|
-
'heading',
|
|
22
|
-
'html',
|
|
23
|
-
'table',
|
|
24
|
-
'tr',
|
|
25
|
-
'td',
|
|
26
|
-
'link',
|
|
27
|
-
'category',
|
|
28
|
-
'file',
|
|
29
|
-
'gallery-image',
|
|
30
|
-
'ext-link',
|
|
31
|
-
'converter',
|
|
32
|
-
'converter-flags',
|
|
33
|
-
'converter-rule',
|
|
34
|
-
// 以下为不可见的类
|
|
35
|
-
'noinclude',
|
|
36
|
-
'include',
|
|
37
|
-
'comment',
|
|
38
|
-
'double-underscore',
|
|
39
|
-
'hidden',
|
|
40
|
-
// 以下为SyntaxToken
|
|
41
|
-
'magic-word-name',
|
|
42
|
-
'heading-trail',
|
|
43
|
-
'table-syntax',
|
|
44
|
-
// 以下为代码不受限的NowikiToken
|
|
45
|
-
'ext-inner#nowiki',
|
|
46
|
-
'ext-inner#pre',
|
|
47
|
-
'ext-inner#syntaxhighlight',
|
|
48
|
-
'ext-inner#source',
|
|
49
|
-
'ext-inner#math',
|
|
50
|
-
'ext-inner#timeline',
|
|
51
|
-
],
|
|
52
|
-
simpleTypes = new Set([
|
|
53
|
-
'ext-inner',
|
|
54
|
-
'ext-attr',
|
|
55
|
-
'html-attr',
|
|
56
|
-
'table-attr',
|
|
57
|
-
'arg-default',
|
|
58
|
-
'parameter-key',
|
|
59
|
-
'parameter-value',
|
|
60
|
-
'heading-title',
|
|
61
|
-
'td-inner',
|
|
62
|
-
'link-target',
|
|
63
|
-
'link-text',
|
|
64
|
-
'image-parameter',
|
|
65
|
-
'ext-link-text',
|
|
66
|
-
'converter-rule-noconvert',
|
|
67
|
-
'converter-rule-to',
|
|
68
|
-
]),
|
|
69
|
-
possibleSyntax = /[{}]|\[{2,}|\[(?!(?:(?!https?\b)[^[])*\])|(?<=^|\])([^[]*?)\]+|<(?=\s*\/?\w+[\s/>])/giu;
|
|
70
|
-
|
|
71
|
-
Parser.debugging = true;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 获取最近更改的页面源代码
|
|
75
|
-
* @param {string} url api.php网址
|
|
76
|
-
*/
|
|
77
|
-
const getPages = async url => {
|
|
78
|
-
const api = new Api(url),
|
|
79
|
-
generatorParams = {generator: 'recentchanges', grcnamespace: '0|10', grclimit: 'max', grctype: 'edit'},
|
|
80
|
-
revisionParams = {prop: 'revisions', rvprop: 'contentmodel|content'};
|
|
81
|
-
/** @type {{query: {pages: MediaWikiPage[]}}} */
|
|
82
|
-
const {query: {pages}} = await api.get({...generatorParams, ...revisionParams});
|
|
83
|
-
return pages.map(({title, ns, revisions}) => ({
|
|
84
|
-
title, ns, content: revisions?.[0]?.contentmodel === 'wikitext' && revisions?.[0]?.content,
|
|
85
|
-
})).filter(({content}) => content);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
(async () => {
|
|
89
|
-
const moreTypes = new Set();
|
|
90
|
-
for (const [name, url, config] of apis) {
|
|
91
|
-
Parser.debug(`开始检查${name}:`);
|
|
92
|
-
Parser.config = `./config/${config}`;
|
|
93
|
-
try {
|
|
94
|
-
const revs = await getPages(`${url}/api.php`);
|
|
95
|
-
for (const {title, ns, content} of revs) {
|
|
96
|
-
try {
|
|
97
|
-
console.time(title);
|
|
98
|
-
const root = Parser.parse(content, ns === 10);
|
|
99
|
-
console.timeEnd(title);
|
|
100
|
-
await diff(content, String(root));
|
|
101
|
-
for (const token of root.querySelectorAll(`:not(${complexOrHiddenTypes.join()})`)) {
|
|
102
|
-
const {childNodes, type, hidden} = token;
|
|
103
|
-
if (hidden && !simpleTypes.has(type)) {
|
|
104
|
-
moreTypes.add(type);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
let first;
|
|
108
|
-
for (let i = 0; i < childNodes.length; i++) {
|
|
109
|
-
const /** @type {AstText} */ {type: childType, data} = childNodes[i];
|
|
110
|
-
if (childType === 'text') {
|
|
111
|
-
first = i;
|
|
112
|
-
if (data.search(possibleSyntax) >= 0) {
|
|
113
|
-
token.setText(data.replaceAll(possibleSyntax, '$1'), i);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (first === undefined && !simpleTypes.has(type)) {
|
|
118
|
-
moreTypes.add(type);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
await diff(content, String(root));
|
|
122
|
-
} catch (e) {
|
|
123
|
-
Parser.error(`解析${name}的 ${title} 页面时出错!`, e);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
} catch (e) {
|
|
127
|
-
Parser.error(`访问${name}的API端口时出错!`, e);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (moreTypes.size > 0) {
|
|
131
|
-
Parser.debug('其他可能不含纯文本子节点的类:', moreTypes);
|
|
132
|
-
}
|
|
133
|
-
})();
|
package/test/test.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/* eslint-disable no-var */
|
|
3
|
-
const fs = require('fs/promises'),
|
|
4
|
-
assert = require('assert'), // eslint-disable-line no-unused-vars
|
|
5
|
-
path = require('path');
|
|
6
|
-
|
|
7
|
-
var Parser = require('..');
|
|
8
|
-
var wikitext = ''; // eslint-disable-line no-unused-vars
|
|
9
|
-
const {argv: [,, title = '']} = process;
|
|
10
|
-
Parser.debugging = true;
|
|
11
|
-
|
|
12
|
-
(async () => {
|
|
13
|
-
const list = await fs.readdir(path.join(__dirname, '../wiki'));
|
|
14
|
-
for (const file of list) {
|
|
15
|
-
if (file.endsWith('.md') && file.toLowerCase().includes(title.toLowerCase())) {
|
|
16
|
-
Parser.debug(file);
|
|
17
|
-
const md = await fs.readFile(path.join(__dirname, '../wiki', file), 'utf8');
|
|
18
|
-
for (const [, code] of md.matchAll(/```js\n(.+?)\n```/gsu)) {
|
|
19
|
-
try {
|
|
20
|
-
eval(code); // eslint-disable-line no-eval
|
|
21
|
-
} catch (e) {
|
|
22
|
-
Parser.error(code);
|
|
23
|
-
throw e;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
})();
|
package/typings/api.d.ts
DELETED
package/typings/array.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface Array<T> {
|
|
3
|
-
/**
|
|
4
|
-
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
5
|
-
* otherwise.
|
|
6
|
-
* @param predicate find calls predicate once for each element of the array, in descending
|
|
7
|
-
* order, until it finds one where predicate returns true. If such an element is found, findLast
|
|
8
|
-
* immediately returns that element value. Otherwise, findLast returns undefined.
|
|
9
|
-
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
10
|
-
* predicate. If it is not provided, undefined is used instead.
|
|
11
|
-
*/
|
|
12
|
-
findLast<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
|
|
13
|
-
findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Returns the index of the last element in the array where predicate is true, and -1
|
|
17
|
-
* otherwise.
|
|
18
|
-
* @param predicate find calls predicate once for each element of the array, in descending
|
|
19
|
-
* order, until it finds one where predicate returns true. If such an element is found,
|
|
20
|
-
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
|
|
21
|
-
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
22
|
-
* predicate. If it is not provided, undefined is used instead.
|
|
23
|
-
*/
|
|
24
|
-
findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export {};
|
package/typings/event.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import Token from '../src';
|
|
2
|
-
import AstText from '../lib/text';
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
interface AstEvent extends Event {
|
|
6
|
-
readonly target: Token & AstText;
|
|
7
|
-
currentTarget: Token;
|
|
8
|
-
prevTarget: ?Token;
|
|
9
|
-
};
|
|
10
|
-
interface AstEventData {
|
|
11
|
-
position: number;
|
|
12
|
-
removed: AstText|Token;
|
|
13
|
-
inserted: AstText|Token;
|
|
14
|
-
oldToken: Token;
|
|
15
|
-
newToken: Token;
|
|
16
|
-
oldText: string;
|
|
17
|
-
newText: string;
|
|
18
|
-
oldKey: string;
|
|
19
|
-
newKey: string;
|
|
20
|
-
}
|
|
21
|
-
type AstListener = (e: AstEvent, data: AstEventData) => any;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export {};
|
package/typings/index.d.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import Token from '../src';
|
|
2
|
-
import $ from '../tool';
|
|
3
|
-
import Title from '../lib/title';
|
|
4
|
-
|
|
5
|
-
declare global {
|
|
6
|
-
interface Parser {
|
|
7
|
-
warning: boolean;
|
|
8
|
-
debugging: boolean;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 默认输出到console.warn
|
|
12
|
-
* @param {string} msg 消息
|
|
13
|
-
* @param {...any} args 更多信息
|
|
14
|
-
*/
|
|
15
|
-
warn(msg: string, ...args: any[]): void;
|
|
16
|
-
/**
|
|
17
|
-
* 默认不输出到console.debug
|
|
18
|
-
* @param {string} msg 消息
|
|
19
|
-
* @param {...any} args 更多信息
|
|
20
|
-
*/
|
|
21
|
-
debug(msg: string, ...args: any[]): void;
|
|
22
|
-
/**
|
|
23
|
-
* 总是输出到console.error
|
|
24
|
-
* @param {string} msg 消息
|
|
25
|
-
* @param {...any} args 更多信息
|
|
26
|
-
*/
|
|
27
|
-
error(msg: string, ...args: any[]): void;
|
|
28
|
-
/**
|
|
29
|
-
* 总是输出到console.info
|
|
30
|
-
* @param {string} msg 消息
|
|
31
|
-
* @param {...any} args 更多信息
|
|
32
|
-
*/
|
|
33
|
-
info(msg: string, ...args: any[]): void;
|
|
34
|
-
|
|
35
|
-
running: boolean;
|
|
36
|
-
|
|
37
|
-
run<T>(callback: () => T): T;
|
|
38
|
-
|
|
39
|
-
/** 只储存导出各个Class的文件路径 */
|
|
40
|
-
classes: Record<string, string>;
|
|
41
|
-
mixins: Record<string, string>;
|
|
42
|
-
parsers: Record<string, string>;
|
|
43
|
-
/** 清除各模块的缓存 */
|
|
44
|
-
clearCache(): void;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 打印函数定义
|
|
48
|
-
* @param {Function} f 待打印的函数
|
|
49
|
-
*/
|
|
50
|
-
log(f: Function): void;
|
|
51
|
-
|
|
52
|
-
readonly aliases: string[][];
|
|
53
|
-
|
|
54
|
-
config: string;
|
|
55
|
-
/** 获取设置 */
|
|
56
|
-
getConfig(): ParserConfig;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 是否是跨维基链接
|
|
60
|
-
* @param {string} title 链接标题
|
|
61
|
-
*/
|
|
62
|
-
isInterwiki(title: string, config?: ParserConfig): RegExpMatchArray;
|
|
63
|
-
/**
|
|
64
|
-
* 规范化页面标题
|
|
65
|
-
* @param {string} title 标题(含或不含命名空间前缀)
|
|
66
|
-
* @param {number} defaultNs 命名空间
|
|
67
|
-
* @param {boolean} include 是否嵌入
|
|
68
|
-
* @param {boolean} halfParsed 是否是半解析状态
|
|
69
|
-
*/
|
|
70
|
-
normalizeTitle(
|
|
71
|
-
title: string, defaultNs?: number, include?: boolean, config?: ParserConfig, halfParsed?: boolean
|
|
72
|
-
): Title;
|
|
73
|
-
|
|
74
|
-
readonly MAX_STAGE: number;
|
|
75
|
-
/**
|
|
76
|
-
* 解析wikitext
|
|
77
|
-
* @param {string|Token} wikitext wikitext
|
|
78
|
-
* @param {boolean} include 是否嵌入
|
|
79
|
-
* @param {number} maxStage 最大解析层级
|
|
80
|
-
*/
|
|
81
|
-
parse(wikitext: string|Token, include?: boolean, maxStage?: number, config?: ParserConfig): Token;
|
|
82
|
-
/**
|
|
83
|
-
* 再次解析上次出错的wikitext
|
|
84
|
-
* @param {string} date 错误日期
|
|
85
|
-
*/
|
|
86
|
-
reparse(date: string): Token;
|
|
87
|
-
|
|
88
|
-
getTool(): typeof $;
|
|
89
|
-
|
|
90
|
-
typeAliases: Record<string, string[]>;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export {};
|
package/typings/node.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Ranges from '../lib/ranges';
|
|
2
|
-
import Token from '../src';
|
|
3
|
-
import AstText from '../lib/text';
|
|
4
|
-
import ParameterToken from '../src/parameter';
|
|
5
|
-
|
|
6
|
-
declare global {
|
|
7
|
-
type TokenAttribute<T> =
|
|
8
|
-
T extends 'stage' ? number :
|
|
9
|
-
T extends 'include' ? boolean :
|
|
10
|
-
T extends 'pattern' ? RegExp :
|
|
11
|
-
T extends 'optional'|'tags'|'flags' ? string[] :
|
|
12
|
-
T extends 'keys' ? Set<string> :
|
|
13
|
-
T extends 'attr' ? Map<string, string|true> :
|
|
14
|
-
T extends 'acceptable' ? Record<string, Ranges> :
|
|
15
|
-
T extends 'args' ? Record<string, Set<ParameterToken>> :
|
|
16
|
-
T extends 'config' ? ParserConfig :
|
|
17
|
-
T extends 'accum' ? accum :
|
|
18
|
-
T extends 'protectedChildren' ? Ranges :
|
|
19
|
-
T extends 'parentNode' ? Token|undefined :
|
|
20
|
-
T extends 'childNodes' ? (AstText|Token)[] :
|
|
21
|
-
T extends 'verifyChild' ? (i: number, addition: number) => void :
|
|
22
|
-
T extends 'matchesAttr' ? (key: string, equal: string, val: string, i: string) => boolean :
|
|
23
|
-
T extends 'parseOnce' ? (n: number, include: boolean) => Token :
|
|
24
|
-
T extends 'buildFromStr' ? (str: string) => (AstText|Token)[] :
|
|
25
|
-
T extends 'protectChildren' ? (...args: string|number|Range) => void :
|
|
26
|
-
string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export {};
|
package/typings/parser.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface BracketExecArray extends RegExpExecArray {
|
|
3
|
-
parts: string[][];
|
|
4
|
-
findEqual: boolean;
|
|
5
|
-
pos: number;
|
|
6
|
-
}
|
|
7
|
-
interface SelectorArray extends Array<string|RegExpExecArray> {
|
|
8
|
-
relation: string|undefined;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type pseudo = 'root'|'is'|'not'|'nth-child'|'nth-of-type'|'nth-last-child'|'nth-last-of-type'
|
|
12
|
-
|'first-child'|'first-of-type'|'last-child'|'last-of-type'|'only-child'|'only-of-type'|'empty'
|
|
13
|
-
|'contains'|'has'|'header'|'parent'|'hidden'|'visible';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export {};
|
package/typings/table.d.ts
DELETED
package/typings/token.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Token from '../src';
|
|
2
|
-
import Ranges from '../lib/ranges';
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
interface ParserConfig {
|
|
6
|
-
ext: string[];
|
|
7
|
-
html: [string[], string[], string[]];
|
|
8
|
-
namespaces: Record<string, string>;
|
|
9
|
-
nsid: Record<string, number>;
|
|
10
|
-
parserFunction: [string[], string[], string[], string[]];
|
|
11
|
-
doubleUnderscore: [string[], string[]];
|
|
12
|
-
protocol: string;
|
|
13
|
-
interwiki: string[];
|
|
14
|
-
img: Record<string, string>;
|
|
15
|
-
variants: string[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type accum = Token[];
|
|
19
|
-
type acceptable = Record<string, number|string|Ranges|(number|string)[]>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export {};
|
package/typings/tool.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Token from '../src';
|
|
2
|
-
import AstText from '../lib/text';
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
interface CollectionCallback<T, S> extends Function {
|
|
6
|
-
call: (thisArg: AstText|Token, i: number, ele: S) => T;
|
|
7
|
-
}
|
|
8
|
-
type CollectionMap = (arr: Token[]) => (AstText|Token)[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export {};
|