wikiparser-node 1.0.0-beta.3 → 1.0.1-b
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/bundle/bundle.min.js +37 -0
- package/config/llwiki.json +1 -35
- package/config/minimum.json +136 -0
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +105 -0
- package/extensions/dist/editor.js +172 -0
- package/extensions/dist/highlight.js +46 -0
- package/extensions/dist/lint.js +43 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +119 -0
- package/package.json +35 -20
- package/config/.schema.json +0 -160
- package/dist/index.d.ts +0 -62
- package/dist/index.js +0 -305
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -186
- package/dist/lib/element.js +0 -659
- package/dist/lib/node.d.ts +0 -178
- package/dist/lib/node.js +0 -458
- package/dist/lib/range.d.ts +0 -132
- package/dist/lib/range.js +0 -387
- package/dist/lib/ranges.d.ts +0 -28
- package/dist/lib/ranges.js +0 -125
- package/dist/lib/text.d.ts +0 -78
- package/dist/lib/text.js +0 -227
- package/dist/lib/title.d.ts +0 -33
- package/dist/lib/title.js +0 -110
- package/dist/mixin/attributesParent.js +0 -93
- package/dist/mixin/fixed.js +0 -32
- package/dist/mixin/hidden.js +0 -23
- package/dist/mixin/singleLine.js +0 -26
- package/dist/mixin/sol.js +0 -44
- package/dist/parser/braces.js +0 -125
- package/dist/parser/commentAndExt.js +0 -58
- package/dist/parser/converter.js +0 -38
- package/dist/parser/externalLinks.js +0 -28
- package/dist/parser/hrAndDoubleUnderscore.js +0 -40
- package/dist/parser/html.js +0 -38
- package/dist/parser/links.js +0 -94
- package/dist/parser/list.js +0 -61
- package/dist/parser/magicLinks.js +0 -39
- package/dist/parser/quotes.js +0 -67
- package/dist/parser/selector.js +0 -165
- package/dist/parser/table.js +0 -117
- package/dist/src/arg.d.ts +0 -77
- package/dist/src/arg.js +0 -199
- package/dist/src/atom.d.ts +0 -11
- package/dist/src/atom.js +0 -24
- package/dist/src/attribute.d.ts +0 -106
- package/dist/src/attribute.js +0 -436
- package/dist/src/attributes.d.ts +0 -119
- package/dist/src/attributes.js +0 -366
- package/dist/src/converter.d.ts +0 -75
- package/dist/src/converter.js +0 -141
- package/dist/src/converterFlags.d.ts +0 -107
- package/dist/src/converterFlags.js +0 -238
- package/dist/src/converterRule.d.ts +0 -96
- package/dist/src/converterRule.js +0 -255
- package/dist/src/extLink.d.ts +0 -63
- package/dist/src/extLink.js +0 -157
- package/dist/src/gallery.d.ts +0 -70
- package/dist/src/gallery.js +0 -137
- package/dist/src/heading.d.ts +0 -82
- package/dist/src/heading.js +0 -135
- package/dist/src/hidden.d.ts +0 -19
- package/dist/src/hidden.js +0 -26
- package/dist/src/html.d.ts +0 -113
- package/dist/src/html.js +0 -245
- package/dist/src/imageParameter.d.ts +0 -82
- package/dist/src/imageParameter.js +0 -256
- package/dist/src/imagemap.d.ts +0 -77
- package/dist/src/imagemap.js +0 -169
- package/dist/src/imagemapLink.d.ts +0 -48
- package/dist/src/imagemapLink.js +0 -43
- package/dist/src/index.d.ts +0 -156
- package/dist/src/index.js +0 -819
- package/dist/src/link/base.d.ts +0 -69
- package/dist/src/link/base.js +0 -231
- package/dist/src/link/category.d.ts +0 -14
- package/dist/src/link/category.js +0 -28
- package/dist/src/link/file.d.ts +0 -105
- package/dist/src/link/file.js +0 -269
- package/dist/src/link/galleryImage.d.ts +0 -37
- package/dist/src/link/galleryImage.js +0 -100
- package/dist/src/link/index.d.ts +0 -50
- package/dist/src/link/index.js +0 -134
- package/dist/src/magicLink.d.ts +0 -46
- package/dist/src/magicLink.js +0 -131
- package/dist/src/nested.d.ts +0 -47
- package/dist/src/nested.js +0 -92
- package/dist/src/nowiki/base.d.ts +0 -38
- package/dist/src/nowiki/base.js +0 -31
- package/dist/src/nowiki/comment.d.ts +0 -42
- package/dist/src/nowiki/comment.js +0 -64
- package/dist/src/nowiki/dd.d.ts +0 -22
- package/dist/src/nowiki/dd.js +0 -46
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -35
- package/dist/src/nowiki/doubleUnderscore.js +0 -48
- package/dist/src/nowiki/hr.d.ts +0 -30
- package/dist/src/nowiki/hr.js +0 -36
- package/dist/src/nowiki/index.d.ts +0 -19
- package/dist/src/nowiki/index.js +0 -23
- package/dist/src/nowiki/list.d.ts +0 -16
- package/dist/src/nowiki/list.js +0 -13
- package/dist/src/nowiki/noinclude.d.ts +0 -21
- package/dist/src/nowiki/noinclude.js +0 -24
- package/dist/src/nowiki/quote.d.ts +0 -27
- package/dist/src/nowiki/quote.js +0 -58
- package/dist/src/onlyinclude.d.ts +0 -38
- package/dist/src/onlyinclude.js +0 -66
- package/dist/src/paramTag/index.d.ts +0 -50
- package/dist/src/paramTag/index.js +0 -78
- package/dist/src/paramTag/inputbox.d.ts +0 -7
- package/dist/src/paramTag/inputbox.js +0 -21
- package/dist/src/parameter.d.ts +0 -95
- package/dist/src/parameter.js +0 -204
- package/dist/src/pre.d.ts +0 -27
- package/dist/src/pre.js +0 -44
- package/dist/src/syntax.d.ts +0 -22
- package/dist/src/syntax.js +0 -67
- package/dist/src/table/base.d.ts +0 -60
- package/dist/src/table/base.js +0 -80
- package/dist/src/table/index.d.ts +0 -247
- package/dist/src/table/index.js +0 -783
- package/dist/src/table/td.d.ts +0 -119
- package/dist/src/table/td.js +0 -268
- package/dist/src/table/tr.d.ts +0 -31
- package/dist/src/table/tr.js +0 -50
- package/dist/src/table/trBase.d.ts +0 -62
- package/dist/src/table/trBase.js +0 -157
- package/dist/src/tagPair/ext.d.ts +0 -54
- package/dist/src/tagPair/ext.js +0 -150
- package/dist/src/tagPair/include.d.ts +0 -43
- package/dist/src/tagPair/include.js +0 -43
- package/dist/src/tagPair/index.d.ts +0 -57
- package/dist/src/tagPair/index.js +0 -113
- package/dist/src/transclude.d.ts +0 -200
- package/dist/src/transclude.js +0 -732
- package/dist/util/debug.js +0 -42
- package/dist/util/diff.js +0 -71
- package/dist/util/lint.js +0 -38
- package/dist/util/string.js +0 -74
- package/errors/README +0 -1
- package/printed/README +0 -1
package/dist/index.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { Title } from './lib/title';
|
|
2
|
-
import type { Token } from './internal';
|
|
3
|
-
export interface Config {
|
|
4
|
-
ext: string[];
|
|
5
|
-
html: [string[], string[], string[]];
|
|
6
|
-
namespaces: Record<string, string>;
|
|
7
|
-
nsid: Record<string, number>;
|
|
8
|
-
parserFunction: [Record<string, string>, string[], string[], string[]];
|
|
9
|
-
doubleUnderscore: [string[], string[]];
|
|
10
|
-
protocol: string;
|
|
11
|
-
img: Record<string, string>;
|
|
12
|
-
variants: string[];
|
|
13
|
-
interwiki: string[];
|
|
14
|
-
excludes?: string[];
|
|
15
|
-
conversionTable?: [string, string][];
|
|
16
|
-
redirects?: [string, string][];
|
|
17
|
-
}
|
|
18
|
-
export interface LintError {
|
|
19
|
-
message: string;
|
|
20
|
-
severity: 'error' | 'warning';
|
|
21
|
-
startIndex: number;
|
|
22
|
-
endIndex: number;
|
|
23
|
-
startLine: number;
|
|
24
|
-
startCol: number;
|
|
25
|
-
endLine: number;
|
|
26
|
-
endCol: number;
|
|
27
|
-
excerpt: string;
|
|
28
|
-
}
|
|
29
|
-
declare interface Parser {
|
|
30
|
-
/** @browser */
|
|
31
|
-
config: string | Config;
|
|
32
|
-
/** @browser */
|
|
33
|
-
i18n?: string | Record<string, string>;
|
|
34
|
-
conversionTable: Map<string, string>;
|
|
35
|
-
redirects: Map<string, string>;
|
|
36
|
-
/**
|
|
37
|
-
* 规范化页面标题
|
|
38
|
-
* @browser
|
|
39
|
-
* @param title 标题(含或不含命名空间前缀)
|
|
40
|
-
* @param defaultNs 命名空间
|
|
41
|
-
* @param include 是否嵌入
|
|
42
|
-
* @param halfParsed 是否是半解析状态
|
|
43
|
-
* @param decode 是否需要解码
|
|
44
|
-
* @param selfLink 是否允许selfLink
|
|
45
|
-
*/
|
|
46
|
-
normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
|
|
47
|
-
/**
|
|
48
|
-
* 解析wikitext
|
|
49
|
-
* @browser
|
|
50
|
-
* @param include 是否嵌入
|
|
51
|
-
* @param maxStage 最大解析层级
|
|
52
|
-
*/
|
|
53
|
-
parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
|
|
54
|
-
/**
|
|
55
|
-
* 是否是跨维基链接
|
|
56
|
-
* @param title 链接标题
|
|
57
|
-
*/
|
|
58
|
-
isInterwiki(title: string, config?: Config): [string, string] | null;
|
|
59
|
-
}
|
|
60
|
-
declare const Parser: Parser;
|
|
61
|
-
export default Parser;
|
|
62
|
-
export type * from './internal';
|
package/dist/index.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
/**
|
|
6
|
-
* 从根路径require
|
|
7
|
-
* @param file 文件名
|
|
8
|
-
* @param dir 子路径
|
|
9
|
-
*/
|
|
10
|
-
const rootRequire = (file, dir = '') => require(`../${file.includes('/') ? '' : dir}${file}`);
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
12
|
-
const Parser = {
|
|
13
|
-
config: 'default',
|
|
14
|
-
conversionTable: new Map(),
|
|
15
|
-
redirects: new Map(),
|
|
16
|
-
MAX_STAGE: 11,
|
|
17
|
-
warning: true,
|
|
18
|
-
debugging: false,
|
|
19
|
-
running: false,
|
|
20
|
-
classes: {},
|
|
21
|
-
mixins: {},
|
|
22
|
-
parsers: {},
|
|
23
|
-
aliases: [
|
|
24
|
-
['AstText'],
|
|
25
|
-
['CommentToken', 'ExtToken', 'IncludeToken', 'NoincludeToken'],
|
|
26
|
-
['ArgToken', 'TranscludeToken', 'HeadingToken'],
|
|
27
|
-
['HtmlToken'],
|
|
28
|
-
['TableToken'],
|
|
29
|
-
['HrToken', 'DoubleUnderscoreToken'],
|
|
30
|
-
['LinkToken', 'FileToken', 'CategoryToken'],
|
|
31
|
-
['QuoteToken'],
|
|
32
|
-
['ExtLinkToken'],
|
|
33
|
-
['MagicLinkToken'],
|
|
34
|
-
['ListToken', 'DdToken'],
|
|
35
|
-
['ConverterToken'],
|
|
36
|
-
],
|
|
37
|
-
typeAliases: {
|
|
38
|
-
text: ['string', 'str'],
|
|
39
|
-
plain: ['regular', 'normal'],
|
|
40
|
-
// comment and extension
|
|
41
|
-
onlyinclude: ['only-include'],
|
|
42
|
-
noinclude: ['no-include'],
|
|
43
|
-
include: ['includeonly', 'include-only'],
|
|
44
|
-
comment: undefined,
|
|
45
|
-
ext: ['extension'],
|
|
46
|
-
'ext-attrs': ['extension-attrs', 'ext-attributes', 'extension-attributes'],
|
|
47
|
-
'ext-attr-dirty': ['extension-attr-dirty', 'ext-attribute-dirty', 'extension-attribute-dirty'],
|
|
48
|
-
'ext-attr': ['extension-attr', 'ext-attribute', 'extension-attribute'],
|
|
49
|
-
'attr-key': ['attribute-key'],
|
|
50
|
-
'attr-value': ['attribute-value', 'attr-val', 'attribute-val'],
|
|
51
|
-
'ext-inner': ['extension-inner'],
|
|
52
|
-
// triple braces
|
|
53
|
-
arg: ['argument'],
|
|
54
|
-
'arg-name': ['argument-name'],
|
|
55
|
-
'arg-default': ['argument-default'],
|
|
56
|
-
hidden: ['arg-redundant'],
|
|
57
|
-
// double braces
|
|
58
|
-
'magic-word': ['parser-function', 'parser-func'],
|
|
59
|
-
'magic-word-name': ['parser-function-name', 'parser-func-name'],
|
|
60
|
-
'invoke-function': ['invoke-func', 'lua-function', 'lua-func', 'module-function', 'module-func'],
|
|
61
|
-
'invoke-module': ['lua-module'],
|
|
62
|
-
template: undefined,
|
|
63
|
-
'template-name': undefined,
|
|
64
|
-
parameter: ['param'],
|
|
65
|
-
'parameter-key': ['param-key'],
|
|
66
|
-
'parameter-value': ['parameter-val', 'param-value', 'param-val'],
|
|
67
|
-
// heading
|
|
68
|
-
heading: ['header'],
|
|
69
|
-
'heading-title': ['header-title'],
|
|
70
|
-
'heading-trail': ['header-trail'],
|
|
71
|
-
// html
|
|
72
|
-
html: undefined,
|
|
73
|
-
'html-attrs': ['html-attributes'],
|
|
74
|
-
'html-attr-dirty': ['html-attribute-dirty'],
|
|
75
|
-
'html-attr': ['html-attribute'],
|
|
76
|
-
// table
|
|
77
|
-
table: undefined,
|
|
78
|
-
tr: ['table-row'],
|
|
79
|
-
td: ['table-cell', 'table-data'],
|
|
80
|
-
'table-syntax': undefined,
|
|
81
|
-
'table-attrs': ['tr-attrs', 'td-attrs', 'table-attributes', 'tr-attributes', 'td-attributes'],
|
|
82
|
-
'table-attr-dirty': ['tr-attr-dirty', 'td-attr-dirty', 'table-attribute-dirty', 'tr-attribute-dirty', 'td-attribute-dirty'],
|
|
83
|
-
'table-attr': ['tr-attr', 'td-attr', 'table-attribute', 'tr-attribute', 'td-attribute'],
|
|
84
|
-
'table-inter': undefined,
|
|
85
|
-
'td-inner': ['table-cell-inner', 'table-data-inner'],
|
|
86
|
-
// hr and double-underscore
|
|
87
|
-
hr: ['horizontal'],
|
|
88
|
-
'double-underscore': ['underscore', 'behavior-switch', 'behaviour-switch'],
|
|
89
|
-
// link
|
|
90
|
-
link: ['wikilink'],
|
|
91
|
-
'link-target': ['wikilink-target'],
|
|
92
|
-
'link-text': ['wikilink-text'],
|
|
93
|
-
category: ['category-link', 'cat', 'cat-link'],
|
|
94
|
-
file: ['file-link', 'image', 'image-link', 'img', 'img-link'],
|
|
95
|
-
'gallery-image': ['gallery-file', 'gallery-img'],
|
|
96
|
-
'imagemap-image': ['imagemap-file', 'imagemap-img', 'image-map-image', 'image-map-file', 'image-map-img'],
|
|
97
|
-
'image-parameter': ['img-parameter', 'image-param', 'img-param'],
|
|
98
|
-
// quotes
|
|
99
|
-
quote: ['quotes', 'quot', 'apostrophe', 'apostrophes', 'apos'],
|
|
100
|
-
// external link
|
|
101
|
-
'ext-link': ['external-link'],
|
|
102
|
-
'ext-link-text': ['external-link-text'],
|
|
103
|
-
'ext-link-url': ['external-link-url'],
|
|
104
|
-
// magic link
|
|
105
|
-
'free-ext-link': ['free-external-link', 'magic-link'],
|
|
106
|
-
// list
|
|
107
|
-
list: ['ol', 'ordered-list', 'ul', 'unordered-list', 'dl', 'description-list'],
|
|
108
|
-
dd: ['indent', 'indentation'],
|
|
109
|
-
// converter
|
|
110
|
-
converter: ['convert', 'conversion'],
|
|
111
|
-
'converter-flags': ['convert-flags', 'conversion-flags'],
|
|
112
|
-
'converter-flag': ['convert-flag', 'conversion-flag'],
|
|
113
|
-
'converter-rule': ['convert-rule', 'conversion-rule'],
|
|
114
|
-
'converter-rule-noconvert': ['convert-rule-noconvert', 'conversion-rule-noconvert'],
|
|
115
|
-
'converter-rule-variant': ['convert-rule-variant', 'conversion-rule-variant'],
|
|
116
|
-
'converter-rule-to': ['convert-rule-to', 'conversion-rule-to'],
|
|
117
|
-
'converter-rule-from': ['convert-rule-from', 'conversion-rule-from'],
|
|
118
|
-
// specific extensions
|
|
119
|
-
'param-line': ['parameter-line'],
|
|
120
|
-
'imagemap-link': ['image-map-link'],
|
|
121
|
-
},
|
|
122
|
-
promises: [Promise.resolve()],
|
|
123
|
-
/** @implements */
|
|
124
|
-
getConfig() {
|
|
125
|
-
if (typeof this.config === 'string') {
|
|
126
|
-
this.config = rootRequire(this.config, 'config/');
|
|
127
|
-
const { config: { conversionTable, redirects } } = this;
|
|
128
|
-
if (conversionTable) {
|
|
129
|
-
this.conversionTable = new Map(conversionTable);
|
|
130
|
-
}
|
|
131
|
-
if (redirects) {
|
|
132
|
-
this.redirects = new Map(redirects);
|
|
133
|
-
}
|
|
134
|
-
return this.getConfig();
|
|
135
|
-
}
|
|
136
|
-
return { ...this.config, excludes: [] };
|
|
137
|
-
},
|
|
138
|
-
/** @implements */
|
|
139
|
-
msg(msg, arg = '') {
|
|
140
|
-
if (typeof this.i18n === 'string') {
|
|
141
|
-
this.i18n = rootRequire(this.i18n, 'i18n/');
|
|
142
|
-
return this.msg(msg, arg);
|
|
143
|
-
}
|
|
144
|
-
return (this.i18n?.[msg] ?? msg).replace('$1', arg);
|
|
145
|
-
},
|
|
146
|
-
/** @implements */
|
|
147
|
-
normalizeTitle(title, defaultNs = 0, include = false, config = Parser.getConfig(), halfParsed = false, decode = false, selfLink = false) {
|
|
148
|
-
const { Title } = require('./lib/title');
|
|
149
|
-
if (halfParsed) {
|
|
150
|
-
return new Title(title, defaultNs, config, decode, selfLink);
|
|
151
|
-
}
|
|
152
|
-
const { Token } = require('./src');
|
|
153
|
-
const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token.firstChild), defaultNs, config, decode, selfLink);
|
|
154
|
-
this.run(() => {
|
|
155
|
-
for (const key of ['main', 'fragment']) {
|
|
156
|
-
if (titleObj[key]?.includes('\0')) {
|
|
157
|
-
titleObj[key] = token.buildFromStr(titleObj[key], 'text');
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
titleObj.conversionTable = this.conversionTable;
|
|
162
|
-
titleObj.redirects = this.redirects;
|
|
163
|
-
return titleObj;
|
|
164
|
-
},
|
|
165
|
-
/** @implements */
|
|
166
|
-
parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
|
|
167
|
-
const { Token } = require('./src');
|
|
168
|
-
let token;
|
|
169
|
-
this.run(() => {
|
|
170
|
-
token = new Token(wikitext, config);
|
|
171
|
-
try {
|
|
172
|
-
token.parse(maxStage, include);
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
if (e instanceof Error) {
|
|
176
|
-
const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
|
|
177
|
-
fs.writeFileSync(file, stage === this.MAX_STAGE ? wikitext : String(token));
|
|
178
|
-
fs.writeFileSync(`${file}.err`, e.stack);
|
|
179
|
-
fs.writeFileSync(`${file}.json`, JSON.stringify({
|
|
180
|
-
stage, include: token.getAttribute('include'), config: this.config,
|
|
181
|
-
}, null, '\t'));
|
|
182
|
-
}
|
|
183
|
-
throw e;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
if (this.debugging) {
|
|
187
|
-
let restored = String(token), process = '解析';
|
|
188
|
-
if (restored === wikitext) {
|
|
189
|
-
const entities = { lt: '<', gt: '>', amp: '&' };
|
|
190
|
-
restored = token.print().replace(/<[^<]+?>|&([lg]t|amp);/gu, (_, s) => s ? entities[s] : '');
|
|
191
|
-
process = '渲染HTML';
|
|
192
|
-
}
|
|
193
|
-
if (restored !== wikitext) {
|
|
194
|
-
const { diff } = require('./util/diff');
|
|
195
|
-
const { promises: { 0: cur, length } } = this;
|
|
196
|
-
this.promises.unshift((async () => {
|
|
197
|
-
await cur;
|
|
198
|
-
this.error(`${process}过程中不可逆地修改了原始文本!`);
|
|
199
|
-
return diff(wikitext, restored, length);
|
|
200
|
-
})());
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return token;
|
|
204
|
-
},
|
|
205
|
-
/** @implements */
|
|
206
|
-
run(callback) {
|
|
207
|
-
const { running } = this;
|
|
208
|
-
this.running = true;
|
|
209
|
-
try {
|
|
210
|
-
const result = callback();
|
|
211
|
-
this.running = running;
|
|
212
|
-
return result;
|
|
213
|
-
}
|
|
214
|
-
catch (e) {
|
|
215
|
-
this.running = running;
|
|
216
|
-
throw e;
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
/** @implements */
|
|
220
|
-
warn(msg, ...args) {
|
|
221
|
-
if (this.warning) {
|
|
222
|
-
console.warn('\x1B[33m%s\x1B[0m', msg, ...args);
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
/** @implements */
|
|
226
|
-
debug(msg, ...args) {
|
|
227
|
-
if (this.debugging) {
|
|
228
|
-
console.debug('\x1B[34m%s\x1B[0m', msg, ...args);
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
/** @implements */
|
|
232
|
-
error(msg, ...args) {
|
|
233
|
-
console.error('\x1B[31m%s\x1B[0m', msg, ...args);
|
|
234
|
-
},
|
|
235
|
-
/** @implements */
|
|
236
|
-
info(msg, ...args) {
|
|
237
|
-
console.info('\x1B[32m%s\x1B[0m', msg, ...args);
|
|
238
|
-
},
|
|
239
|
-
/** @implements */
|
|
240
|
-
log(f) {
|
|
241
|
-
if (typeof f === 'function') {
|
|
242
|
-
console.log(String(f));
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
/** @implements */
|
|
246
|
-
clearCache() {
|
|
247
|
-
const entries = [
|
|
248
|
-
...Object.entries(this.classes),
|
|
249
|
-
...Object.entries(this.mixins),
|
|
250
|
-
...Object.entries(this.parsers),
|
|
251
|
-
];
|
|
252
|
-
for (const [, filePath] of entries) {
|
|
253
|
-
try {
|
|
254
|
-
delete require.cache[require.resolve(filePath)];
|
|
255
|
-
}
|
|
256
|
-
catch { }
|
|
257
|
-
}
|
|
258
|
-
for (const [name, filePath] of entries) {
|
|
259
|
-
if (name in global) {
|
|
260
|
-
// @ts-expect-error noImplicitAny
|
|
261
|
-
global[name] = require(filePath);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
/** @implements */
|
|
266
|
-
isInterwiki(title, { interwiki } = Parser.getConfig()) {
|
|
267
|
-
return new RegExp(`^(${interwiki.join('|')})\\s*:`, 'iu')
|
|
268
|
-
.exec(title.replaceAll('_', ' ').replace(/^\s*:?\s*/u, ''));
|
|
269
|
-
},
|
|
270
|
-
/** @implements */
|
|
271
|
-
reparse(date) {
|
|
272
|
-
const main = fs.readdirSync(path.join(__dirname, '..', 'errors'))
|
|
273
|
-
.find(name => name.startsWith(date) && name.endsWith('Z'));
|
|
274
|
-
if (!main) {
|
|
275
|
-
throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
|
|
276
|
-
}
|
|
277
|
-
const file = path.join(__dirname, '..', 'errors', main), wikitext = fs.readFileSync(file, 'utf8');
|
|
278
|
-
const { stage, include, config } = require(`${file}.json`), { Token } = require('./src');
|
|
279
|
-
this.config = config;
|
|
280
|
-
return this.run(() => {
|
|
281
|
-
const halfParsed = stage < this.MAX_STAGE, token = new Token(wikitext, this.getConfig(), halfParsed);
|
|
282
|
-
if (halfParsed) {
|
|
283
|
-
token.setAttribute('stage', stage).parseOnce(stage, include);
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
token.parse(undefined, include);
|
|
287
|
-
}
|
|
288
|
-
fs.unlinkSync(file);
|
|
289
|
-
fs.unlinkSync(`${file}.err`);
|
|
290
|
-
fs.unlinkSync(`${file}.json`);
|
|
291
|
-
return token;
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
};
|
|
295
|
-
const def = {}, immutable = new Set(['MAX_STAGE', 'aliases', 'typeAliases', 'promises']), enumerable = new Set(['config', 'conversionTable', 'redirects', 'normalizeTitle', 'parse', 'isInterwiki']);
|
|
296
|
-
for (const key in Parser) {
|
|
297
|
-
if (immutable.has(key)) {
|
|
298
|
-
def[key] = { enumerable: false, writable: false };
|
|
299
|
-
}
|
|
300
|
-
else if (!enumerable.has(key)) {
|
|
301
|
-
def[key] = { enumerable: false };
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
Object.defineProperties(Parser, def);
|
|
305
|
-
exports.default = Parser;
|
package/dist/internal.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export type { AstNodes, } from './lib/node';
|
|
2
|
-
export type * from './lib/text';
|
|
3
|
-
export type * from './src';
|
|
4
|
-
export type * from './src/onlyinclude';
|
|
5
|
-
export type * from './src/nowiki/noinclude';
|
|
6
|
-
export type * from './src/tagPair/include';
|
|
7
|
-
export type * from './src/nowiki/comment';
|
|
8
|
-
export type * from './src/atom';
|
|
9
|
-
export type * from './src/attribute';
|
|
10
|
-
export type * from './src/attributes';
|
|
11
|
-
export type * from './src/tagPair/ext';
|
|
12
|
-
export type * from './src/hidden';
|
|
13
|
-
export type * from './src/arg';
|
|
14
|
-
export type * from './src/syntax';
|
|
15
|
-
export type * from './src/parameter';
|
|
16
|
-
export type * from './src/transclude';
|
|
17
|
-
export type * from './src/heading';
|
|
18
|
-
export type * from './src/html';
|
|
19
|
-
export type { TdToken } from './src/table/td';
|
|
20
|
-
export type * from './src/table/tr';
|
|
21
|
-
export type * from './src/table';
|
|
22
|
-
export type * from './src/nowiki/hr';
|
|
23
|
-
export type * from './src/nowiki/doubleUnderscore';
|
|
24
|
-
export type * from './src/link';
|
|
25
|
-
export type * from './src/link/category';
|
|
26
|
-
export type * from './src/imageParameter';
|
|
27
|
-
export type * from './src/link/file';
|
|
28
|
-
export type * from './src/link/galleryImage';
|
|
29
|
-
export type * from './src/nowiki/quote';
|
|
30
|
-
export type * from './src/magicLink';
|
|
31
|
-
export type * from './src/extLink';
|
|
32
|
-
export type * from './src/nowiki/dd';
|
|
33
|
-
export type * from './src/nowiki/list';
|
|
34
|
-
export type * from './src/converterFlags';
|
|
35
|
-
export type * from './src/converterRule';
|
|
36
|
-
export type * from './src/converter';
|
|
37
|
-
export type * from './src/nowiki';
|
|
38
|
-
export type * from './src/pre';
|
|
39
|
-
export type * from './src/paramTag';
|
|
40
|
-
export type * from './src/paramTag/inputbox';
|
|
41
|
-
export type * from './src/nested';
|
|
42
|
-
export type * from './src/gallery';
|
|
43
|
-
export type * from './src/imagemapLink';
|
|
44
|
-
export type * from './src/imagemap';
|
package/dist/lib/element.d.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { AstNode } from './node';
|
|
2
|
-
import type { LintError } from '../index';
|
|
3
|
-
import type { AstNodes, AstText, Token } from '../internal';
|
|
4
|
-
/** 类似HTMLElement */
|
|
5
|
-
export declare abstract class AstElement extends AstNode {
|
|
6
|
-
#private;
|
|
7
|
-
/** @browser */
|
|
8
|
-
name?: string;
|
|
9
|
-
/**
|
|
10
|
-
* 子节点总数
|
|
11
|
-
* @browser
|
|
12
|
-
*/
|
|
13
|
-
get length(): number;
|
|
14
|
-
/** 全部非文本子节点 */
|
|
15
|
-
get children(): Token[];
|
|
16
|
-
/** 首位非文本子节点 */
|
|
17
|
-
get firstElementChild(): Token | undefined;
|
|
18
|
-
/** 末位非文本子节点 */
|
|
19
|
-
get lastElementChild(): Token | undefined;
|
|
20
|
-
/** 非文本子节点总数 */
|
|
21
|
-
get childElementCount(): number;
|
|
22
|
-
/** 父节点 */
|
|
23
|
-
get parentElement(): Token | undefined;
|
|
24
|
-
/** AstElement.prototype.text()的getter写法 */
|
|
25
|
-
get outerText(): string;
|
|
26
|
-
/** 不可见 */
|
|
27
|
-
get hidden(): boolean;
|
|
28
|
-
/** 后一个可见的兄弟节点 */
|
|
29
|
-
get nextVisibleSibling(): AstNodes | undefined;
|
|
30
|
-
/** 前一个可见的兄弟节点 */
|
|
31
|
-
get previousVisibleSibling(): AstNodes | undefined;
|
|
32
|
-
/** 内部高度 */
|
|
33
|
-
get clientHeight(): number | undefined;
|
|
34
|
-
/** 内部宽度 */
|
|
35
|
-
get clientWidth(): number | undefined;
|
|
36
|
-
constructor();
|
|
37
|
-
/**
|
|
38
|
-
* 可见部分
|
|
39
|
-
* @browser
|
|
40
|
-
* @param separator 子节点间的连接符
|
|
41
|
-
*/
|
|
42
|
-
text(separator?: string): string;
|
|
43
|
-
/**
|
|
44
|
-
* 合并相邻的文本子节点
|
|
45
|
-
* @browser
|
|
46
|
-
*/
|
|
47
|
-
normalize(): void;
|
|
48
|
-
/**
|
|
49
|
-
* 移除子节点
|
|
50
|
-
* @browser
|
|
51
|
-
* @param i 移除位置
|
|
52
|
-
*/
|
|
53
|
-
removeAt(i: number): AstNodes;
|
|
54
|
-
/**
|
|
55
|
-
* 插入子节点
|
|
56
|
-
* @browser
|
|
57
|
-
* @param node 待插入的子节点
|
|
58
|
-
* @param i 插入位置
|
|
59
|
-
* @throws `RangeError` 不能插入祖先节点
|
|
60
|
-
*/
|
|
61
|
-
insertAt<T extends AstNodes>(node: T, i?: number): T;
|
|
62
|
-
/**
|
|
63
|
-
* 最近的祖先节点
|
|
64
|
-
* @browser
|
|
65
|
-
* @param selector 选择器
|
|
66
|
-
*/
|
|
67
|
-
closest(selector: string): Token | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* 在末尾批量插入子节点
|
|
70
|
-
* @browser
|
|
71
|
-
* @param elements 插入节点
|
|
72
|
-
*/
|
|
73
|
-
append(...elements: (AstNodes | string)[]): void;
|
|
74
|
-
/**
|
|
75
|
-
* 批量替换子节点
|
|
76
|
-
* @browser
|
|
77
|
-
* @param elements 新的子节点
|
|
78
|
-
*/
|
|
79
|
-
replaceChildren(...elements: (AstNodes | string)[]): void;
|
|
80
|
-
/**
|
|
81
|
-
* 修改文本子节点
|
|
82
|
-
* @browser
|
|
83
|
-
* @param str 新文本
|
|
84
|
-
* @param i 子节点位置
|
|
85
|
-
* @throws `RangeError` 对应位置的子节点不是文本节点
|
|
86
|
-
*/
|
|
87
|
-
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
|
-
/**
|
|
96
|
-
* Linter
|
|
97
|
-
* @browser
|
|
98
|
-
* @param start
|
|
99
|
-
*/
|
|
100
|
-
lint(start?: number): LintError[];
|
|
101
|
-
/**
|
|
102
|
-
* 以HTML格式打印
|
|
103
|
-
* @browser
|
|
104
|
-
* @param opt 选项
|
|
105
|
-
*/
|
|
106
|
-
print(opt?: PrintOpt): string;
|
|
107
|
-
/**
|
|
108
|
-
* 保存为JSON
|
|
109
|
-
* @browser
|
|
110
|
-
* @param file 文件名
|
|
111
|
-
*/
|
|
112
|
-
json(file?: string): unknown;
|
|
113
|
-
/** 销毁 */
|
|
114
|
-
destroy(): void;
|
|
115
|
-
/**
|
|
116
|
-
* 检查是否符合选择器
|
|
117
|
-
* @param selector 选择器
|
|
118
|
-
*/
|
|
119
|
-
matches(selector?: string): boolean;
|
|
120
|
-
/**
|
|
121
|
-
* 符合选择器的第一个后代节点
|
|
122
|
-
* @param selector 选择器
|
|
123
|
-
*/
|
|
124
|
-
querySelector(selector: string): Token | undefined;
|
|
125
|
-
/**
|
|
126
|
-
* 符合选择器的所有后代节点
|
|
127
|
-
* @param selector 选择器
|
|
128
|
-
*/
|
|
129
|
-
querySelectorAll(selector: string): Token[];
|
|
130
|
-
/**
|
|
131
|
-
* id选择器
|
|
132
|
-
* @param id id名
|
|
133
|
-
*/
|
|
134
|
-
getElementById(id: string): Token | undefined;
|
|
135
|
-
/**
|
|
136
|
-
* 类选择器
|
|
137
|
-
* @param className 类名之一
|
|
138
|
-
*/
|
|
139
|
-
getElementsByClassName(className: string): Token[];
|
|
140
|
-
/**
|
|
141
|
-
* 标签名选择器
|
|
142
|
-
* @param name 标签名
|
|
143
|
-
*/
|
|
144
|
-
getElementsByTagName(name: string): Token[];
|
|
145
|
-
/**
|
|
146
|
-
* 获取某一行的wikitext
|
|
147
|
-
* @param n 行号
|
|
148
|
-
*/
|
|
149
|
-
getLine(n: number): string | undefined;
|
|
150
|
-
/**
|
|
151
|
-
* 在开头批量插入子节点
|
|
152
|
-
* @param elements 插入节点
|
|
153
|
-
*/
|
|
154
|
-
prepend(...elements: (AstNodes | string)[]): void;
|
|
155
|
-
/**
|
|
156
|
-
* 移除子节点
|
|
157
|
-
* @param node 子节点
|
|
158
|
-
*/
|
|
159
|
-
removeChild<T extends AstNodes>(node: T): T;
|
|
160
|
-
/**
|
|
161
|
-
* 在末尾插入子节点
|
|
162
|
-
* @param node 插入节点
|
|
163
|
-
*/
|
|
164
|
-
appendChild(node: string): AstText;
|
|
165
|
-
/** @ignore */
|
|
166
|
-
appendChild<T extends AstNodes>(node: T): T;
|
|
167
|
-
/**
|
|
168
|
-
* 在指定位置前插入子节点
|
|
169
|
-
* @param child 插入节点
|
|
170
|
-
* @param reference 指定位置处的子节点
|
|
171
|
-
*/
|
|
172
|
-
insertBefore(child: string, reference?: AstNodes): AstText;
|
|
173
|
-
/** @ignore */
|
|
174
|
-
insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
|
|
175
|
-
/**
|
|
176
|
-
* 替换子节点
|
|
177
|
-
* @param newChild 新子节点
|
|
178
|
-
* @param oldChild 原子节点
|
|
179
|
-
*/
|
|
180
|
-
replaceChild<T extends AstNodes>(newChild: AstNodes | string, oldChild: T): T;
|
|
181
|
-
/**
|
|
182
|
-
* 输出AST
|
|
183
|
-
* @param depth 当前深度
|
|
184
|
-
*/
|
|
185
|
-
echo(depth?: number): void;
|
|
186
|
-
}
|