wikiparser-node 1.0.0-beta.3 → 1.0.0-beta.5
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 +10 -9
- package/config/minimum.json +136 -0
- package/dist/bin/toc.js +18 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.js +21 -13
- package/dist/internal.d.ts +6 -6
- package/dist/lib/element.d.ts +12 -31
- package/dist/lib/element.js +83 -83
- package/dist/lib/node.d.ts +9 -40
- package/dist/lib/node.js +23 -53
- package/dist/lib/range.d.ts +9 -2
- package/dist/lib/range.js +46 -21
- package/dist/lib/ranges.js +4 -6
- package/dist/lib/text.d.ts +4 -19
- package/dist/lib/text.js +11 -22
- package/dist/lib/title.d.ts +3 -16
- package/dist/lib/title.js +18 -20
- package/dist/mixin/attributesParent.js +2 -3
- package/dist/mixin/fixed.js +3 -4
- package/dist/mixin/hidden.js +2 -3
- package/dist/mixin/singleLine.js +5 -6
- package/dist/mixin/sol.js +8 -9
- package/dist/mixin/syntax.js +55 -0
- package/dist/parser/braces.js +4 -9
- package/dist/parser/commentAndExt.js +24 -18
- package/dist/parser/converter.js +8 -7
- package/dist/parser/externalLinks.js +3 -4
- package/dist/parser/hrAndDoubleUnderscore.js +7 -10
- package/dist/parser/html.js +4 -7
- package/dist/parser/links.js +7 -8
- package/dist/parser/list.js +3 -6
- package/dist/parser/magicLinks.js +3 -3
- package/dist/parser/quotes.js +4 -5
- package/dist/parser/selector.js +5 -9
- package/dist/parser/table.js +12 -20
- package/dist/src/arg.d.ts +11 -30
- package/dist/src/arg.js +35 -48
- package/dist/src/atom.d.ts +4 -3
- package/dist/src/atom.js +9 -8
- package/dist/src/attribute.d.ts +24 -44
- package/dist/src/attribute.js +52 -71
- package/dist/src/attributes.d.ts +10 -21
- package/dist/src/attributes.js +26 -38
- package/dist/src/converter.d.ts +6 -18
- package/dist/src/converter.js +19 -34
- package/dist/src/converterFlags.d.ts +11 -34
- package/dist/src/converterFlags.js +21 -49
- package/dist/src/converterRule.d.ts +6 -18
- package/dist/src/converterRule.js +28 -39
- package/dist/src/extLink.d.ts +7 -19
- package/dist/src/extLink.js +23 -32
- package/dist/src/gallery.d.ts +10 -26
- package/dist/src/gallery.js +25 -43
- package/dist/src/heading.d.ts +24 -33
- package/dist/src/heading.js +30 -50
- package/dist/src/hidden.d.ts +8 -6
- package/dist/src/hidden.js +6 -10
- package/dist/src/html.d.ts +26 -39
- package/dist/src/html.js +34 -50
- package/dist/src/imageParameter.d.ts +13 -32
- package/dist/src/imageParameter.js +47 -57
- package/dist/src/imagemap.d.ts +15 -35
- package/dist/src/imagemap.js +23 -48
- package/dist/src/imagemapLink.d.ts +20 -11
- package/dist/src/imagemapLink.js +11 -15
- package/dist/src/index.d.ts +7 -15
- package/dist/src/index.js +88 -124
- package/dist/src/link/base.d.ts +7 -21
- package/dist/src/link/base.js +34 -44
- package/dist/src/link/category.d.ts +2 -3
- package/dist/src/link/category.js +6 -5
- package/dist/src/link/file.d.ts +10 -27
- package/dist/src/link/file.js +28 -46
- package/dist/src/link/galleryImage.d.ts +21 -11
- package/dist/src/link/galleryImage.js +28 -14
- package/dist/src/link/index.d.ts +1 -2
- package/dist/src/link/index.js +9 -7
- package/dist/src/magicLink.d.ts +26 -10
- package/dist/src/magicLink.js +22 -23
- package/dist/src/nested.d.ts +6 -9
- package/dist/src/nested.js +11 -18
- package/dist/src/nowiki/base.d.ts +13 -7
- package/dist/src/nowiki/base.js +15 -10
- package/dist/src/nowiki/comment.d.ts +15 -23
- package/dist/src/nowiki/comment.js +18 -30
- package/dist/src/nowiki/dd.d.ts +3 -20
- package/dist/src/nowiki/dd.js +10 -38
- package/dist/src/nowiki/doubleUnderscore.d.ts +31 -19
- package/dist/src/nowiki/doubleUnderscore.js +30 -29
- package/dist/src/nowiki/hr.d.ts +19 -17
- package/dist/src/nowiki/hr.js +5 -27
- package/dist/src/nowiki/index.d.ts +3 -6
- package/dist/src/nowiki/index.js +7 -10
- package/dist/src/nowiki/list.d.ts +13 -5
- package/dist/src/nowiki/list.js +23 -5
- package/dist/src/nowiki/listBase.d.ts +29 -0
- package/dist/src/nowiki/listBase.js +34 -0
- package/dist/src/nowiki/noinclude.d.ts +8 -3
- package/dist/src/nowiki/noinclude.js +4 -3
- package/dist/src/nowiki/quote.d.ts +16 -21
- package/dist/src/nowiki/quote.js +27 -37
- package/dist/src/onlyinclude.d.ts +2 -26
- package/dist/src/onlyinclude.js +17 -34
- package/dist/src/paramTag/index.d.ts +10 -23
- package/dist/src/paramTag/index.js +19 -31
- package/dist/src/paramTag/inputbox.d.ts +6 -5
- package/dist/src/paramTag/inputbox.js +9 -8
- package/dist/src/parameter.d.ts +18 -31
- package/dist/src/parameter.js +37 -51
- package/dist/src/pre.d.ts +6 -5
- package/dist/src/pre.js +23 -18
- package/dist/src/syntax.d.ts +17 -15
- package/dist/src/syntax.js +13 -52
- package/dist/src/table/base.d.ts +13 -14
- package/dist/src/table/base.js +13 -13
- package/dist/src/table/index.d.ts +13 -21
- package/dist/src/table/index.js +33 -40
- package/dist/src/table/td.d.ts +29 -42
- package/dist/src/table/td.js +53 -65
- package/dist/src/table/tr.d.ts +3 -4
- package/dist/src/table/tr.js +5 -5
- package/dist/src/table/trBase.d.ts +4 -12
- package/dist/src/table/trBase.js +16 -22
- package/dist/src/tagPair/ext.d.ts +15 -13
- package/dist/src/tagPair/ext.js +17 -29
- package/dist/src/tagPair/include.d.ts +10 -7
- package/dist/src/tagPair/include.js +7 -9
- package/dist/src/tagPair/index.d.ts +15 -25
- package/dist/src/tagPair/index.js +23 -42
- package/dist/src/transclude.d.ts +14 -43
- package/dist/src/transclude.js +53 -88
- package/dist/util/diff.js +4 -3
- package/dist/util/lint.js +14 -4
- package/dist/util/string.js +20 -24
- package/package.json +19 -16
package/README.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/wikiparser-node)
|
|
2
|
-
[](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/codeql.yml)
|
|
3
|
+
[](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml)
|
|
3
4
|
|
|
4
5
|
# 简介
|
|
5
6
|
|
|
6
|
-
wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/
|
|
7
|
+
wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/) 环境的离线[维基文本](https://www.mediawiki.org/wiki/Wikitext)语法解析器,可以解析几乎全部的维基语法并生成[语法树](https://en.wikipedia.org/wiki/Abstract_syntax_tree),还可以很方便地对语法树进行查询和修改,最后返回修改后的维基文本。
|
|
7
8
|
|
|
8
9
|
# 其他版本
|
|
9
10
|
|
|
10
|
-
## Mini
|
|
11
|
+
## Mini (又名 [wikilint](https://www.npmjs.com/package/wikilint))
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
提供了 [CLI](https://en.wikipedia.org/wiki/Command-line_interface),但仅保留了解析功能和语法错误分析功能,解析生成的语法树不能修改。这个版本被应用于 [eslint-plugin-wikitext](https://www.npmjs.com/package/eslint-plugin-wikitext) 插件。
|
|
13
14
|
|
|
14
15
|
## Browser
|
|
15
16
|
|
|
@@ -19,16 +20,16 @@ wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/e
|
|
|
19
20
|
|
|
20
21
|
## Node.js
|
|
21
22
|
|
|
22
|
-
请根据需要需要安装对应的版本(`
|
|
23
|
+
请根据需要需要安装对应的版本(`wikiparser-node` 或 `wikilint`),如:
|
|
23
24
|
|
|
24
25
|
```sh
|
|
25
|
-
npm i wikiparser-node
|
|
26
|
+
npm i wikiparser-node
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
或
|
|
29
30
|
|
|
30
31
|
```sh
|
|
31
|
-
npm i
|
|
32
|
+
npm i wikilint
|
|
32
33
|
```
|
|
33
34
|
|
|
34
35
|
## 浏览器
|
|
@@ -45,8 +46,8 @@ npm i wikiparser-node@mini
|
|
|
45
46
|
<script src="//unpkg.com/wikiparser-node@browser/bundle/bundle.min.js"></script>
|
|
46
47
|
```
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
更多浏览器端可用的插件请查阅对应文档。
|
|
49
50
|
|
|
50
51
|
# 使用方法
|
|
51
52
|
|
|
52
|
-
请查阅 [Wiki](https://github.com/bhsd-harry/wikiparser-node/wiki
|
|
53
|
+
请查阅 [Wiki](https://github.com/bhsd-harry/wikiparser-node/wiki)。
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
"6": "File",
|
|
75
|
+
"10": "Template"
|
|
76
|
+
},
|
|
77
|
+
"nsid": {},
|
|
78
|
+
"parserFunction": [
|
|
79
|
+
{
|
|
80
|
+
"#language": "language",
|
|
81
|
+
"#special": "special",
|
|
82
|
+
"#speciale": "speciale",
|
|
83
|
+
"#tag": "tag",
|
|
84
|
+
"#formatdate": "formatdate",
|
|
85
|
+
"#invoke": "invoke",
|
|
86
|
+
"#while": "while",
|
|
87
|
+
"#dowhile": "dowhile",
|
|
88
|
+
"#loop": "loop",
|
|
89
|
+
"#forargs": "forargs",
|
|
90
|
+
"#fornumargs": "fornumargs",
|
|
91
|
+
"#if": "if",
|
|
92
|
+
"#ifeq": "ifeq",
|
|
93
|
+
"#switch": "switch",
|
|
94
|
+
"#ifexist": "ifexist",
|
|
95
|
+
"#ifexpr": "ifexpr",
|
|
96
|
+
"#iferror": "iferror",
|
|
97
|
+
"#time": "time",
|
|
98
|
+
"#timel": "timel",
|
|
99
|
+
"#expr": "expr",
|
|
100
|
+
"#rel2abs": "rel2abs",
|
|
101
|
+
"#titleparts": "titleparts",
|
|
102
|
+
"#categorytree": "categorytree",
|
|
103
|
+
"#urldecode": "urldecode",
|
|
104
|
+
"#choose": "choose",
|
|
105
|
+
"#var": "var",
|
|
106
|
+
"#varexists": "varexists",
|
|
107
|
+
"#var_final": "var_final",
|
|
108
|
+
"#vardefine": "vardefine",
|
|
109
|
+
"#vardefineecho": "vardefineecho",
|
|
110
|
+
"#widget": "widget",
|
|
111
|
+
"#regex": "regex",
|
|
112
|
+
"#related": "related",
|
|
113
|
+
"#cscore": "cscore"
|
|
114
|
+
},
|
|
115
|
+
[],
|
|
116
|
+
[
|
|
117
|
+
"msg",
|
|
118
|
+
"原始",
|
|
119
|
+
"raw"
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
"替代",
|
|
123
|
+
"subst",
|
|
124
|
+
"安全替代",
|
|
125
|
+
"safesubst"
|
|
126
|
+
]
|
|
127
|
+
],
|
|
128
|
+
"doubleUnderscore": [
|
|
129
|
+
[],
|
|
130
|
+
[]
|
|
131
|
+
],
|
|
132
|
+
"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:",
|
|
133
|
+
"interwiki": [],
|
|
134
|
+
"img": {},
|
|
135
|
+
"variants": []
|
|
136
|
+
}
|
package/dist/bin/toc.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { argv: [, , filename] } = process;
|
|
6
|
+
if (!filename) {
|
|
7
|
+
throw new RangeError('请指定文档文件!');
|
|
8
|
+
}
|
|
9
|
+
const fullpath = path.join(__dirname, '..', '..', 'wiki', `${filename}.md`);
|
|
10
|
+
if (!fs.existsSync(fullpath)) {
|
|
11
|
+
throw new RangeError(`文档 ${filename}.md 不存在!`);
|
|
12
|
+
}
|
|
13
|
+
const content = fs.readFileSync(fullpath, 'utf8');
|
|
14
|
+
if (/^- \[[^\]]+\]\(#[^)]+\)$/mu.test(content)) {
|
|
15
|
+
throw new Error(`文档 ${filename}.md 中已包含目录!`);
|
|
16
|
+
}
|
|
17
|
+
const toc = content.split('\n').filter(line => line.startsWith('#')).map(line => line.replace(/^(#+)\s+(\S.*)$/u, (_, { length }, title) => `${'\t'.repeat(length - 1)}- [${title}](#${title.toLowerCase().replaceAll(' ', '-').replaceAll('.', '')})`)).join('\n');
|
|
18
|
+
fs.writeFileSync(fullpath, `<details>\n\t<summary>目录</summary>\n\n${toc}\n</details>\n\n${content}`);
|
package/dist/index.d.ts
CHANGED
|
@@ -27,15 +27,12 @@ export interface LintError {
|
|
|
27
27
|
excerpt: string;
|
|
28
28
|
}
|
|
29
29
|
declare interface Parser {
|
|
30
|
-
/** @browser */
|
|
31
30
|
config: string | Config;
|
|
32
|
-
/** @browser */
|
|
33
31
|
i18n?: string | Record<string, string>;
|
|
34
32
|
conversionTable: Map<string, string>;
|
|
35
33
|
redirects: Map<string, string>;
|
|
36
34
|
/**
|
|
37
35
|
* 规范化页面标题
|
|
38
|
-
* @browser
|
|
39
36
|
* @param title 标题(含或不含命名空间前缀)
|
|
40
37
|
* @param defaultNs 命名空间
|
|
41
38
|
* @param include 是否嵌入
|
|
@@ -46,7 +43,6 @@ declare interface Parser {
|
|
|
46
43
|
normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
|
|
47
44
|
/**
|
|
48
45
|
* 解析wikitext
|
|
49
|
-
* @browser
|
|
50
46
|
* @param include 是否嵌入
|
|
51
47
|
* @param maxStage 最大解析层级
|
|
52
48
|
*/
|
|
@@ -58,5 +54,5 @@ declare interface Parser {
|
|
|
58
54
|
isInterwiki(title: string, config?: Config): [string, string] | null;
|
|
59
55
|
}
|
|
60
56
|
declare const Parser: Parser;
|
|
61
|
-
export
|
|
57
|
+
export = Parser;
|
|
62
58
|
export type * from './internal';
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
/* eslint n/exports-style: 0 */
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
+
const diff_1 = require("./util/diff");
|
|
5
6
|
/**
|
|
6
7
|
* 从根路径require
|
|
7
8
|
* @param file 文件名
|
|
8
9
|
* @param dir 子路径
|
|
9
10
|
*/
|
|
10
|
-
const rootRequire = (file, dir
|
|
11
|
+
const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
|
|
11
12
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
12
13
|
const Parser = {
|
|
13
14
|
config: 'default',
|
|
15
|
+
MAX_STAGE: 11,
|
|
16
|
+
/* NOT FOR BROWSER */
|
|
14
17
|
conversionTable: new Map(),
|
|
15
18
|
redirects: new Map(),
|
|
16
|
-
MAX_STAGE: 11,
|
|
17
19
|
warning: true,
|
|
18
20
|
debugging: false,
|
|
19
21
|
running: false,
|
|
@@ -120,6 +122,7 @@ const Parser = {
|
|
|
120
122
|
'imagemap-link': ['image-map-link'],
|
|
121
123
|
},
|
|
122
124
|
promises: [Promise.resolve()],
|
|
125
|
+
/* NOT FOR BROWSER END */
|
|
123
126
|
/** @implements */
|
|
124
127
|
getConfig() {
|
|
125
128
|
if (typeof this.config === 'string') {
|
|
@@ -149,8 +152,8 @@ const Parser = {
|
|
|
149
152
|
if (halfParsed) {
|
|
150
153
|
return new Title(title, defaultNs, config, decode, selfLink);
|
|
151
154
|
}
|
|
152
|
-
const { Token } = require('./src');
|
|
153
|
-
const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token
|
|
155
|
+
const { Token } = require('./src/index');
|
|
156
|
+
const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
|
|
154
157
|
this.run(() => {
|
|
155
158
|
for (const key of ['main', 'fragment']) {
|
|
156
159
|
if (titleObj[key]?.includes('\0')) {
|
|
@@ -164,10 +167,10 @@ const Parser = {
|
|
|
164
167
|
},
|
|
165
168
|
/** @implements */
|
|
166
169
|
parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
|
|
167
|
-
const { Token } = require('./src');
|
|
170
|
+
const { Token } = require('./src/index');
|
|
168
171
|
let token;
|
|
169
172
|
this.run(() => {
|
|
170
|
-
token = new Token(wikitext, config);
|
|
173
|
+
token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config);
|
|
171
174
|
try {
|
|
172
175
|
token.parse(maxStage, include);
|
|
173
176
|
}
|
|
@@ -216,6 +219,7 @@ const Parser = {
|
|
|
216
219
|
throw e;
|
|
217
220
|
}
|
|
218
221
|
},
|
|
222
|
+
/* NOT FOR BROWSER */
|
|
219
223
|
/** @implements */
|
|
220
224
|
warn(msg, ...args) {
|
|
221
225
|
if (this.warning) {
|
|
@@ -243,8 +247,8 @@ const Parser = {
|
|
|
243
247
|
}
|
|
244
248
|
},
|
|
245
249
|
/** @implements */
|
|
246
|
-
clearCache() {
|
|
247
|
-
const entries = [
|
|
250
|
+
async clearCache() {
|
|
251
|
+
const promise = (0, diff_1.cmd)('npm', ['run', 'build']), entries = [
|
|
248
252
|
...Object.entries(this.classes),
|
|
249
253
|
...Object.entries(this.mixins),
|
|
250
254
|
...Object.entries(this.parsers),
|
|
@@ -255,12 +259,15 @@ const Parser = {
|
|
|
255
259
|
}
|
|
256
260
|
catch { }
|
|
257
261
|
}
|
|
262
|
+
await promise;
|
|
258
263
|
for (const [name, filePath] of entries) {
|
|
259
264
|
if (name in global) {
|
|
260
265
|
// @ts-expect-error noImplicitAny
|
|
261
|
-
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
267
|
+
global[name] = require(filePath)[name];
|
|
262
268
|
}
|
|
263
269
|
}
|
|
270
|
+
this.info('已重新加载Parser');
|
|
264
271
|
},
|
|
265
272
|
/** @implements */
|
|
266
273
|
isInterwiki(title, { interwiki } = Parser.getConfig()) {
|
|
@@ -278,9 +285,10 @@ const Parser = {
|
|
|
278
285
|
const { stage, include, config } = require(`${file}.json`), { Token } = require('./src');
|
|
279
286
|
this.config = config;
|
|
280
287
|
return this.run(() => {
|
|
281
|
-
const halfParsed = stage < this.MAX_STAGE, token = new Token(wikitext, this.getConfig()
|
|
288
|
+
const halfParsed = stage < this.MAX_STAGE, token = new Token(halfParsed ? wikitext : wikitext.replace(/[\0\x7F]/gu, ''), this.getConfig());
|
|
282
289
|
if (halfParsed) {
|
|
283
|
-
token.setAttribute('stage', stage)
|
|
290
|
+
token.setAttribute('stage', stage);
|
|
291
|
+
token.parseOnce(stage, include);
|
|
284
292
|
}
|
|
285
293
|
else {
|
|
286
294
|
token.parse(undefined, include);
|
|
@@ -302,4 +310,4 @@ for (const key in Parser) {
|
|
|
302
310
|
}
|
|
303
311
|
}
|
|
304
312
|
Object.defineProperties(Parser, def);
|
|
305
|
-
exports
|
|
313
|
+
module.exports = Parser;
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export type { AstNodes, } from './lib/node';
|
|
2
2
|
export type * from './lib/text';
|
|
3
|
-
export type * from './src';
|
|
3
|
+
export type * from './src/index';
|
|
4
4
|
export type * from './src/onlyinclude';
|
|
5
5
|
export type * from './src/nowiki/noinclude';
|
|
6
6
|
export type * from './src/tagPair/include';
|
|
7
7
|
export type * from './src/nowiki/comment';
|
|
8
8
|
export type * from './src/atom';
|
|
9
|
-
export type
|
|
9
|
+
export type { AttributeToken } from './src/attribute';
|
|
10
10
|
export type * from './src/attributes';
|
|
11
11
|
export type * from './src/tagPair/ext';
|
|
12
12
|
export type * from './src/hidden';
|
|
@@ -18,10 +18,10 @@ export type * from './src/heading';
|
|
|
18
18
|
export type * from './src/html';
|
|
19
19
|
export type { TdToken } from './src/table/td';
|
|
20
20
|
export type * from './src/table/tr';
|
|
21
|
-
export type * from './src/table';
|
|
21
|
+
export type * from './src/table/index';
|
|
22
22
|
export type * from './src/nowiki/hr';
|
|
23
23
|
export type * from './src/nowiki/doubleUnderscore';
|
|
24
|
-
export type * from './src/link';
|
|
24
|
+
export type * from './src/link/index';
|
|
25
25
|
export type * from './src/link/category';
|
|
26
26
|
export type * from './src/imageParameter';
|
|
27
27
|
export type * from './src/link/file';
|
|
@@ -34,9 +34,9 @@ export type * from './src/nowiki/list';
|
|
|
34
34
|
export type * from './src/converterFlags';
|
|
35
35
|
export type * from './src/converterRule';
|
|
36
36
|
export type * from './src/converter';
|
|
37
|
-
export type * from './src/nowiki';
|
|
37
|
+
export type * from './src/nowiki/index';
|
|
38
38
|
export type * from './src/pre';
|
|
39
|
-
export type * from './src/paramTag';
|
|
39
|
+
export type * from './src/paramTag/index';
|
|
40
40
|
export type * from './src/paramTag/inputbox';
|
|
41
41
|
export type * from './src/nested';
|
|
42
42
|
export type * from './src/gallery';
|
package/dist/lib/element.d.ts
CHANGED
|
@@ -4,12 +4,8 @@ import type { AstNodes, AstText, Token } from '../internal';
|
|
|
4
4
|
/** 类似HTMLElement */
|
|
5
5
|
export declare abstract class AstElement extends AstNode {
|
|
6
6
|
#private;
|
|
7
|
-
/** @browser */
|
|
8
7
|
name?: string;
|
|
9
|
-
/**
|
|
10
|
-
* 子节点总数
|
|
11
|
-
* @browser
|
|
12
|
-
*/
|
|
8
|
+
/** 子节点总数 */
|
|
13
9
|
get length(): number;
|
|
14
10
|
/** 全部非文本子节点 */
|
|
15
11
|
get children(): Token[];
|
|
@@ -36,24 +32,18 @@ export declare abstract class AstElement extends AstNode {
|
|
|
36
32
|
constructor();
|
|
37
33
|
/**
|
|
38
34
|
* 可见部分
|
|
39
|
-
* @browser
|
|
40
35
|
* @param separator 子节点间的连接符
|
|
41
36
|
*/
|
|
42
37
|
text(separator?: string): string;
|
|
43
|
-
/**
|
|
44
|
-
* 合并相邻的文本子节点
|
|
45
|
-
* @browser
|
|
46
|
-
*/
|
|
38
|
+
/** 合并相邻的文本子节点 */
|
|
47
39
|
normalize(): void;
|
|
48
40
|
/**
|
|
49
41
|
* 移除子节点
|
|
50
|
-
* @browser
|
|
51
42
|
* @param i 移除位置
|
|
52
43
|
*/
|
|
53
44
|
removeAt(i: number): AstNodes;
|
|
54
45
|
/**
|
|
55
46
|
* 插入子节点
|
|
56
|
-
* @browser
|
|
57
47
|
* @param node 待插入的子节点
|
|
58
48
|
* @param i 插入位置
|
|
59
49
|
* @throws `RangeError` 不能插入祖先节点
|
|
@@ -61,52 +51,38 @@ export declare abstract class AstElement extends AstNode {
|
|
|
61
51
|
insertAt<T extends AstNodes>(node: T, i?: number): T;
|
|
62
52
|
/**
|
|
63
53
|
* 最近的祖先节点
|
|
64
|
-
* @browser
|
|
65
54
|
* @param selector 选择器
|
|
66
55
|
*/
|
|
67
56
|
closest(selector: string): Token | undefined;
|
|
68
57
|
/**
|
|
69
58
|
* 在末尾批量插入子节点
|
|
70
|
-
* @browser
|
|
71
59
|
* @param elements 插入节点
|
|
72
60
|
*/
|
|
73
61
|
append(...elements: (AstNodes | string)[]): void;
|
|
74
62
|
/**
|
|
75
63
|
* 批量替换子节点
|
|
76
|
-
* @browser
|
|
77
64
|
* @param elements 新的子节点
|
|
78
65
|
*/
|
|
79
66
|
replaceChildren(...elements: (AstNodes | string)[]): void;
|
|
80
67
|
/**
|
|
81
68
|
* 修改文本子节点
|
|
82
|
-
* @browser
|
|
83
69
|
* @param str 新文本
|
|
84
70
|
* @param i 子节点位置
|
|
85
71
|
* @throws `RangeError` 对应位置的子节点不是文本节点
|
|
86
72
|
*/
|
|
87
73
|
setText(str: string, i?: number): string;
|
|
88
|
-
/**
|
|
89
|
-
* 还原为wikitext
|
|
90
|
-
* @browser
|
|
91
|
-
* @param selector
|
|
92
|
-
* @param separator 子节点间的连接符
|
|
93
|
-
*/
|
|
94
|
-
toString(selector?: string, separator?: string): string;
|
|
95
74
|
/**
|
|
96
75
|
* Linter
|
|
97
|
-
* @browser
|
|
98
76
|
* @param start
|
|
99
77
|
*/
|
|
100
78
|
lint(start?: number): LintError[];
|
|
101
79
|
/**
|
|
102
80
|
* 以HTML格式打印
|
|
103
|
-
* @browser
|
|
104
81
|
* @param opt 选项
|
|
105
82
|
*/
|
|
106
83
|
print(opt?: PrintOpt): string;
|
|
107
84
|
/**
|
|
108
85
|
* 保存为JSON
|
|
109
|
-
* @browser
|
|
110
86
|
* @param file 文件名
|
|
111
87
|
*/
|
|
112
88
|
json(file?: string): unknown;
|
|
@@ -123,15 +99,20 @@ export declare abstract class AstElement extends AstNode {
|
|
|
123
99
|
*/
|
|
124
100
|
querySelector(selector: string): Token | undefined;
|
|
125
101
|
/**
|
|
126
|
-
*
|
|
127
|
-
* @param
|
|
102
|
+
* 类型选择器
|
|
103
|
+
* @param types
|
|
128
104
|
*/
|
|
129
|
-
|
|
105
|
+
getElementByTypes(types: string): Token | undefined;
|
|
130
106
|
/**
|
|
131
107
|
* id选择器
|
|
132
108
|
* @param id id名
|
|
133
109
|
*/
|
|
134
110
|
getElementById(id: string): Token | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* 符合选择器的所有后代节点
|
|
113
|
+
* @param selector 选择器
|
|
114
|
+
*/
|
|
115
|
+
querySelectorAll(selector: string): Token[];
|
|
135
116
|
/**
|
|
136
117
|
* 类选择器
|
|
137
118
|
* @param className 类名之一
|
|
@@ -139,9 +120,9 @@ export declare abstract class AstElement extends AstNode {
|
|
|
139
120
|
getElementsByClassName(className: string): Token[];
|
|
140
121
|
/**
|
|
141
122
|
* 标签名选择器
|
|
142
|
-
* @param
|
|
123
|
+
* @param tag 标签名
|
|
143
124
|
*/
|
|
144
|
-
getElementsByTagName(
|
|
125
|
+
getElementsByTagName(tag: string): Token[];
|
|
145
126
|
/**
|
|
146
127
|
* 获取某一行的wikitext
|
|
147
128
|
* @param n 行号
|