wikiparser-node 1.21.3 → 1.22.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/README.md +6 -0
- package/bundle/bundle-es8.min.js +24 -24
- package/bundle/bundle-lsp.min.js +26 -26
- package/bundle/bundle.min.js +24 -24
- package/config/default.json +17 -11
- package/config/enwiki.json +1 -1
- package/config/jawiki.json +1 -1
- package/config/minimum.json +3 -3
- package/config/moegirl.json +154 -15
- package/config/zhwiki.json +1 -1
- package/dist/addon/token.js +3 -0
- package/dist/base.d.mts +10 -8
- package/dist/base.d.ts +10 -8
- package/dist/bin/config.js +23 -11
- package/dist/index.d.ts +31 -2
- package/dist/index.js +27 -1
- package/dist/lib/document.js +1 -1
- package/dist/lib/element.d.ts +4 -4
- package/dist/lib/element.js +7 -7
- package/dist/lib/lintConfig.js +123 -6
- package/dist/lib/lsp.d.ts +7 -7
- package/dist/lib/lsp.js +36 -23
- package/dist/lib/node.d.ts +1 -1
- package/dist/lib/node.js +1 -1
- package/dist/lib/range.d.ts +2 -2
- package/dist/lib/range.js +10 -4
- package/dist/lib/text.js +72 -62
- package/dist/lib/title.d.ts +11 -4
- package/dist/lib/title.js +16 -6
- package/dist/mixin/readOnly.js +3 -1
- package/dist/parser/commentAndExt.js +6 -4
- package/dist/parser/converter.js +1 -1
- package/dist/parser/selector.js +11 -9
- package/dist/src/arg.js +11 -10
- package/dist/src/attribute.js +31 -19
- package/dist/src/attributes.js +10 -8
- package/dist/src/commented.js +1 -1
- package/dist/src/converterRule.js +2 -2
- package/dist/src/gallery.js +26 -19
- package/dist/src/heading.js +32 -36
- package/dist/src/html.js +64 -51
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +10 -8
- package/dist/src/link/base.d.ts +1 -1
- package/dist/src/link/base.js +22 -15
- package/dist/src/link/file.js +22 -14
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/link/index.js +1 -1
- package/dist/src/magicLink.js +16 -12
- package/dist/src/nowiki/index.js +1 -1
- package/dist/src/nowiki/quote.js +19 -38
- package/dist/src/table/index.js +33 -27
- package/dist/src/table/td.d.ts +1 -1
- package/dist/src/table/td.js +27 -25
- package/dist/src/table/trBase.js +13 -10
- package/dist/src/tagPair/ext.js +6 -3
- package/dist/src/tagPair/index.js +2 -3
- package/dist/src/transclude.d.ts +15 -1
- package/dist/src/transclude.js +43 -13
- package/dist/util/lint.js +3 -5
- package/dist/util/sharable.js +1 -1
- package/dist/util/sharable.mjs +2 -2
- package/extensions/dist/base.js +8 -1
- package/extensions/typings.d.ts +2 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +8 -3
package/dist/base.d.ts
CHANGED
|
@@ -112,7 +112,7 @@ interface Token extends AstNode {
|
|
|
112
112
|
* Get all descendants that match the selector
|
|
113
113
|
*
|
|
114
114
|
* 符合选择器的所有后代节点
|
|
115
|
-
* @param selector 选择器
|
|
115
|
+
* @param selector selector / 选择器
|
|
116
116
|
*/
|
|
117
117
|
querySelectorAll<T = Token>(selector: string): T[];
|
|
118
118
|
/**
|
|
@@ -175,7 +175,7 @@ export interface LanguageService {
|
|
|
175
175
|
*
|
|
176
176
|
* 提供自动补全
|
|
177
177
|
* @param text source Wikitext / 源代码
|
|
178
|
-
* @param position 位置
|
|
178
|
+
* @param position position / 位置
|
|
179
179
|
*/
|
|
180
180
|
provideCompletionItems(text: string, position: Position): Promise<CompletionItem[] | undefined>;
|
|
181
181
|
/**
|
|
@@ -205,7 +205,7 @@ export interface LanguageService {
|
|
|
205
205
|
*
|
|
206
206
|
* 提供引用
|
|
207
207
|
* @param text source Wikitext / 源代码
|
|
208
|
-
* @param position 位置
|
|
208
|
+
* @param position position / 位置
|
|
209
209
|
*/
|
|
210
210
|
provideReferences(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
|
|
211
211
|
/**
|
|
@@ -213,7 +213,7 @@ export interface LanguageService {
|
|
|
213
213
|
*
|
|
214
214
|
* 提供定义
|
|
215
215
|
* @param text source Wikitext / 源代码
|
|
216
|
-
* @param position 位置
|
|
216
|
+
* @param position position / 位置
|
|
217
217
|
*/
|
|
218
218
|
provideDefinition(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
|
|
219
219
|
/**
|
|
@@ -221,7 +221,7 @@ export interface LanguageService {
|
|
|
221
221
|
*
|
|
222
222
|
* 提供变量更名准备
|
|
223
223
|
* @param text source Wikitext / 源代码
|
|
224
|
-
* @param position 位置
|
|
224
|
+
* @param position position / 位置
|
|
225
225
|
*/
|
|
226
226
|
resolveRenameLocation(text: string, position: Position): Promise<Range | undefined>;
|
|
227
227
|
/**
|
|
@@ -229,7 +229,7 @@ export interface LanguageService {
|
|
|
229
229
|
*
|
|
230
230
|
* 变量更名
|
|
231
231
|
* @param text source Wikitext / 源代码
|
|
232
|
-
* @param position 位置
|
|
232
|
+
* @param position position / 位置
|
|
233
233
|
* @param newName new name / 新名称
|
|
234
234
|
*/
|
|
235
235
|
provideRenameEdits(text: string, position: Position, newName: string): Promise<WorkspaceEdit | undefined>;
|
|
@@ -238,7 +238,7 @@ export interface LanguageService {
|
|
|
238
238
|
*
|
|
239
239
|
* 提供悬停信息
|
|
240
240
|
* @param text source Wikitext / 源代码
|
|
241
|
-
* @param position 位置
|
|
241
|
+
* @param position position / 位置
|
|
242
242
|
*/
|
|
243
243
|
provideHover(text: string, position: Position): Promise<Hover | undefined>;
|
|
244
244
|
/**
|
|
@@ -246,7 +246,7 @@ export interface LanguageService {
|
|
|
246
246
|
*
|
|
247
247
|
* 提供魔术字帮助
|
|
248
248
|
* @param text source Wikitext / 源代码
|
|
249
|
-
* @param position 位置
|
|
249
|
+
* @param position position / 位置
|
|
250
250
|
*/
|
|
251
251
|
provideSignatureHelp(text: string, position: Position): Promise<SignatureHelp | undefined>;
|
|
252
252
|
/**
|
|
@@ -286,6 +286,8 @@ export interface LintConfiguration extends LintConfig {
|
|
|
286
286
|
export interface Parser {
|
|
287
287
|
config: ConfigData | string;
|
|
288
288
|
i18n: Record<string, string> | string | undefined;
|
|
289
|
+
/** @since v1.22.0 */
|
|
290
|
+
lintConfig: LintConfiguration;
|
|
289
291
|
/** @since v1.9.0 */
|
|
290
292
|
viewOnly: boolean;
|
|
291
293
|
/**
|
package/dist/bin/config.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const strict_1 = __importDefault(require("assert/strict"));
|
|
10
|
-
const
|
|
10
|
+
const cm_util_1 = require("@bhsd/cm-util");
|
|
11
11
|
const diff_1 = require("../util/diff");
|
|
12
12
|
/**
|
|
13
13
|
* Converts an array to an object.
|
|
@@ -85,11 +85,23 @@ let mwConfig;
|
|
|
85
85
|
* @param internal for internal use
|
|
86
86
|
*/
|
|
87
87
|
exports.default = async (site, url, force, internal) => {
|
|
88
|
+
// wrong calls
|
|
88
89
|
if (!site || !url) {
|
|
89
|
-
(
|
|
90
|
-
|
|
90
|
+
if (internal) {
|
|
91
|
+
throw new RangeError('Site nickname and script path are required!');
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
(0, diff_1.error)('Usage: npx getParserConfig <site> <script path> [force]');
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// internal calls with stored configuration
|
|
99
|
+
const dir = path_1.default.join('..', '..', 'config'), file = path_1.default.join(__dirname, dir, `${site}.json`);
|
|
100
|
+
if (internal && !force && fs_1.default.existsSync(file)) {
|
|
101
|
+
return require(file);
|
|
91
102
|
}
|
|
92
|
-
|
|
103
|
+
// fetching configuration
|
|
104
|
+
if (/(?:\.php|\/)$/u.test(url)) {
|
|
93
105
|
url = url.slice(0, url.lastIndexOf('/'));
|
|
94
106
|
}
|
|
95
107
|
const m = await (await fetch(`${url}/load.php?modules=ext.CodeMirror.data|ext.CodeMirror`)).text(), params = {
|
|
@@ -103,14 +115,14 @@ exports.default = async (site, url, force, internal) => {
|
|
|
103
115
|
if (!mwConfig) {
|
|
104
116
|
throw new RangeError('Extension:CodeMirror is not installed!');
|
|
105
117
|
}
|
|
106
|
-
const
|
|
118
|
+
const ns = Object.entries(namespaces).filter(([id]) => filterGadget(id))
|
|
107
119
|
.flatMap(([id, { name, canonical = '' }]) => [
|
|
108
120
|
[id, name],
|
|
109
121
|
...name === canonical ? [] : [[id, canonical]],
|
|
110
122
|
]), config = {
|
|
111
|
-
...(0,
|
|
112
|
-
...(0,
|
|
113
|
-
variants: (0,
|
|
123
|
+
...(0, cm_util_1.getParserConfig)(require(path_1.default.join(dir, 'minimum')), mwConfig),
|
|
124
|
+
...(0, cm_util_1.getKeywords)(magicwords),
|
|
125
|
+
variants: (0, cm_util_1.getVariants)(variants),
|
|
114
126
|
namespaces: Object.fromEntries(ns),
|
|
115
127
|
nsid: Object.fromEntries([
|
|
116
128
|
...ns.map(([id, canonical]) => [canonical.toLowerCase(), Number(id)]),
|
|
@@ -120,7 +132,7 @@ exports.default = async (site, url, force, internal) => {
|
|
|
120
132
|
};
|
|
121
133
|
config.doubleUnderscore[0] = [];
|
|
122
134
|
config.doubleUnderscore[1] = [];
|
|
123
|
-
Object.assign(config.parserFunction[0], (0,
|
|
135
|
+
Object.assign(config.parserFunction[0], (0, cm_util_1.getConfig)(magicwords, ({ name }) => name === 'msgnw'));
|
|
124
136
|
config.parserFunction[2] = getAliases(magicwords, new Set(['msg', 'raw']));
|
|
125
137
|
config.parserFunction[3] = getAliases(magicwords, new Set(['subst', 'safesubst']));
|
|
126
138
|
if (!mwConfig.functionHooks) {
|
|
@@ -137,11 +149,11 @@ exports.default = async (site, url, force, internal) => {
|
|
|
137
149
|
config.variable.splice(i, 1);
|
|
138
150
|
}
|
|
139
151
|
}
|
|
140
|
-
|
|
152
|
+
// saving configuration
|
|
141
153
|
if (force || !fs_1.default.existsSync(file)) {
|
|
142
154
|
fs_1.default.writeFileSync(file, `${JSON.stringify(config, null, '\t')}\n`);
|
|
143
155
|
}
|
|
144
|
-
else
|
|
156
|
+
else {
|
|
145
157
|
const oldConfig = arrToObj(require(file)), newConfig = arrToObj(config);
|
|
146
158
|
for (const [k, v] of Object.entries(newConfig)) {
|
|
147
159
|
try {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Config, ConfigData, LintError, LintConfiguration, TokenTypes, Parser as ParserBase, Stage, AST } from './base';
|
|
2
2
|
import type { Title, TitleOptions } from './lib/title';
|
|
3
3
|
import type { LanguageService, QuickFixData } from './lib/lsp';
|
|
4
|
-
import type { Token } from './internal';
|
|
4
|
+
import type { Token, TranscludeToken, ExtToken } from './internal';
|
|
5
|
+
declare type FunctionHook = (token: TranscludeToken, context?: TranscludeToken) => string;
|
|
6
|
+
declare type TagHook = (token: ExtToken) => string;
|
|
5
7
|
declare interface Parser extends ParserBase {
|
|
8
|
+
default: Parser;
|
|
6
9
|
/** @since v1.5.1 */
|
|
7
10
|
rules: readonly LintError.Rule[];
|
|
8
11
|
conversionTable: Map<string, string>;
|
|
@@ -38,6 +41,14 @@ declare interface Parser extends ParserBase {
|
|
|
38
41
|
* @since v1.16.1
|
|
39
42
|
*/
|
|
40
43
|
createLanguageService(uri?: object): LanguageService;
|
|
44
|
+
/**
|
|
45
|
+
* get the name of a WMF site from a URL
|
|
46
|
+
*
|
|
47
|
+
* 获取一个WMF网站的名称
|
|
48
|
+
* @param url script path
|
|
49
|
+
* @since v1.22.0
|
|
50
|
+
*/
|
|
51
|
+
getWMFSite(url: string): [string, string];
|
|
41
52
|
/**
|
|
42
53
|
* Get the parser configuration for a MediaWiki project with Extension:CodeMirror installed
|
|
43
54
|
*
|
|
@@ -47,11 +58,29 @@ declare interface Parser extends ParserBase {
|
|
|
47
58
|
* @since v1.18.4
|
|
48
59
|
*/
|
|
49
60
|
fetchConfig(site: string, url: string): Promise<Config>;
|
|
61
|
+
/**
|
|
62
|
+
* Define how to expand a parser function
|
|
63
|
+
*
|
|
64
|
+
* 定义如何展开一个解析器函数
|
|
65
|
+
* @param name parser function name / 解析器函数名
|
|
66
|
+
* @param hook handler function / 处理函数
|
|
67
|
+
* @since v1.22.0
|
|
68
|
+
*/
|
|
69
|
+
setFunctionHook(name: string, hook: FunctionHook): void;
|
|
70
|
+
/**
|
|
71
|
+
* Define how to convert an extension tag to HTML
|
|
72
|
+
*
|
|
73
|
+
* 定义如何将一个扩展标签转换为HTML
|
|
74
|
+
* @param name tag name / 标签名
|
|
75
|
+
* @param hook handler function / 处理函数
|
|
76
|
+
* @since v1.22.0
|
|
77
|
+
*/
|
|
78
|
+
setHook(name: string, hook: TagHook): void;
|
|
50
79
|
/**
|
|
51
80
|
* Check if the title is an interwiki link
|
|
52
81
|
*
|
|
53
82
|
* 是否是跨维基链接
|
|
54
|
-
* @param title 链接标题
|
|
83
|
+
* @param title title / 链接标题
|
|
55
84
|
*/
|
|
56
85
|
isInterwiki(title: string, config?: Config): RegExpExecArray | null;
|
|
57
86
|
}
|
package/dist/index.js
CHANGED
|
@@ -15,9 +15,11 @@ const redirectMap_1 = require("./lib/redirectMap");
|
|
|
15
15
|
/* NOT FOR BROWSER ONLY */
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const common_2 = require("@bhsd/common");
|
|
18
19
|
const diff_1 = require("./util/diff");
|
|
19
20
|
const config_1 = __importDefault(require("./bin/config"));
|
|
20
21
|
/* NOT FOR BROWSER ONLY */
|
|
22
|
+
const re = new RegExp(String.raw `^https?:\/\/([^./]+)\.(${common_2.wmf})\.org`, 'iu');
|
|
21
23
|
/**
|
|
22
24
|
* 从根路径require
|
|
23
25
|
* @param file 文件名
|
|
@@ -72,6 +74,8 @@ const Parser = {
|
|
|
72
74
|
templates: new redirectMap_1.RedirectMap(undefined, false),
|
|
73
75
|
warning: true,
|
|
74
76
|
debugging: false,
|
|
77
|
+
functionHooks: new Map(),
|
|
78
|
+
tagHooks: new Map(),
|
|
75
79
|
/* NOT FOR BROWSER END */
|
|
76
80
|
/* NOT FOR BROWSER ONLY */
|
|
77
81
|
lintCSS: true,
|
|
@@ -145,6 +149,7 @@ const Parser = {
|
|
|
145
149
|
root.type = 'root';
|
|
146
150
|
root.parseOnce(0, include).parseOnce();
|
|
147
151
|
const t = new Title(root.toString(), defaultNs, config, opt);
|
|
152
|
+
root.build();
|
|
148
153
|
for (const key of ['main', 'fragment']) {
|
|
149
154
|
const str = t[key];
|
|
150
155
|
if (str?.includes('\0')) {
|
|
@@ -271,14 +276,31 @@ const Parser = {
|
|
|
271
276
|
}
|
|
272
277
|
},
|
|
273
278
|
/* NOT FOR BROWSER ONLY */
|
|
279
|
+
/** @implements */
|
|
280
|
+
getWMFSite(url) {
|
|
281
|
+
const mt = re.exec(url);
|
|
282
|
+
if (!mt) {
|
|
283
|
+
throw new RangeError('Not a recognizable WMF site!');
|
|
284
|
+
}
|
|
285
|
+
const type = mt[2].toLowerCase();
|
|
286
|
+
return [mt[1].toLowerCase() + (type === 'wikipedia' ? 'wiki' : type), mt[0]];
|
|
287
|
+
},
|
|
274
288
|
/* istanbul ignore next */
|
|
275
289
|
/** @implements */
|
|
276
290
|
async fetchConfig(site, url) {
|
|
277
291
|
return this.getConfig(await (0, config_1.default)(site, url, false, true));
|
|
278
292
|
},
|
|
279
|
-
/* NOT FOR BROWSER ONLY */
|
|
293
|
+
/* NOT FOR BROWSER ONLY END */
|
|
280
294
|
/* NOT FOR BROWSER */
|
|
281
295
|
/** @implements */
|
|
296
|
+
setFunctionHook(name, hook) {
|
|
297
|
+
this.functionHooks.set(name, hook);
|
|
298
|
+
},
|
|
299
|
+
/** @implements */
|
|
300
|
+
setHook(name, hook) {
|
|
301
|
+
this.tagHooks.set(name, hook);
|
|
302
|
+
},
|
|
303
|
+
/** @implements */
|
|
282
304
|
warn(msg, ...args) {
|
|
283
305
|
/* istanbul ignore if */
|
|
284
306
|
if (this.warning) {
|
|
@@ -372,9 +394,13 @@ const Parser = {
|
|
|
372
394
|
const def = {
|
|
373
395
|
default: { value: Parser },
|
|
374
396
|
}, enumerable = new Set([
|
|
397
|
+
'lintConfig',
|
|
375
398
|
'normalizeTitle',
|
|
376
399
|
'parse',
|
|
377
400
|
'createLanguageService',
|
|
401
|
+
/* NOT FOR BROWSER ONLY */
|
|
402
|
+
'fetchConfig',
|
|
403
|
+
/* NOT FOR BROWSER ONLY END */
|
|
378
404
|
/* NOT FOR BROWSER */
|
|
379
405
|
'warning',
|
|
380
406
|
'debugging',
|
package/dist/lib/document.js
CHANGED
|
@@ -113,7 +113,7 @@ class EmbeddedDocument {
|
|
|
113
113
|
this.languageId = id;
|
|
114
114
|
this.lineCount = root.getLines().length;
|
|
115
115
|
this.#root = root;
|
|
116
|
-
this.#content =
|
|
116
|
+
this.#content = token.toString();
|
|
117
117
|
this.#offset = token.getAbsoluteIndex();
|
|
118
118
|
this.pre = pre;
|
|
119
119
|
this.#post = post;
|
package/dist/lib/element.d.ts
CHANGED
|
@@ -69,21 +69,21 @@ export declare abstract class AstElement extends AstNode {
|
|
|
69
69
|
* Get the closest ancestor node that matches the selector
|
|
70
70
|
*
|
|
71
71
|
* 最近的符合选择器的祖先节点
|
|
72
|
-
* @param selector 选择器
|
|
72
|
+
* @param selector selector / 选择器
|
|
73
73
|
*/
|
|
74
74
|
closest<T = Token>(selector: string): T | undefined;
|
|
75
75
|
/**
|
|
76
76
|
* Get the first descendant that matches the selector
|
|
77
77
|
*
|
|
78
78
|
* 符合选择器的第一个后代节点
|
|
79
|
-
* @param selector 选择器
|
|
79
|
+
* @param selector selector / 选择器
|
|
80
80
|
*/
|
|
81
81
|
querySelector<T = Token>(selector: string): T | undefined;
|
|
82
82
|
/**
|
|
83
83
|
* Get all descendants that match the selector
|
|
84
84
|
*
|
|
85
85
|
* 符合选择器的所有后代节点
|
|
86
|
-
* @param selector 选择器
|
|
86
|
+
* @param selector selector / 选择器
|
|
87
87
|
*/
|
|
88
88
|
querySelectorAll<T = Token>(selector: string): T[];
|
|
89
89
|
/**
|
|
@@ -143,7 +143,7 @@ export declare abstract class AstElement extends AstNode {
|
|
|
143
143
|
* Check if the current element matches the selector
|
|
144
144
|
*
|
|
145
145
|
* 检查是否符合选择器
|
|
146
|
-
* @param selector 选择器
|
|
146
|
+
* @param selector selector / 选择器
|
|
147
147
|
*/
|
|
148
148
|
matches<T>(selector?: string): this is T;
|
|
149
149
|
/**
|
package/dist/lib/element.js
CHANGED
|
@@ -215,7 +215,7 @@ let AstElement = (() => {
|
|
|
215
215
|
* Get the closest ancestor node that matches the selector
|
|
216
216
|
*
|
|
217
217
|
* 最近的符合选择器的祖先节点
|
|
218
|
-
* @param selector 选择器
|
|
218
|
+
* @param selector selector / 选择器
|
|
219
219
|
*/
|
|
220
220
|
closest(selector) {
|
|
221
221
|
const condition = (0, selector_1.getCondition)(selector, this);
|
|
@@ -251,7 +251,7 @@ let AstElement = (() => {
|
|
|
251
251
|
* Get the first descendant that matches the selector
|
|
252
252
|
*
|
|
253
253
|
* 符合选择器的第一个后代节点
|
|
254
|
-
* @param selector 选择器
|
|
254
|
+
* @param selector selector / 选择器
|
|
255
255
|
*/
|
|
256
256
|
querySelector(selector) {
|
|
257
257
|
const condition = (0, selector_1.getCondition)(selector, this);
|
|
@@ -260,9 +260,9 @@ let AstElement = (() => {
|
|
|
260
260
|
/**
|
|
261
261
|
* 符合条件的所有后代节点
|
|
262
262
|
* @param condition 条件
|
|
263
|
+
* @param descendants 已经找到的后代节点
|
|
263
264
|
*/
|
|
264
|
-
#getElementsBy(condition) {
|
|
265
|
-
let descendants = [];
|
|
265
|
+
#getElementsBy(condition, descendants = []) {
|
|
266
266
|
for (const child of this.childNodes) {
|
|
267
267
|
if (child.type === 'text') {
|
|
268
268
|
continue;
|
|
@@ -270,7 +270,7 @@ let AstElement = (() => {
|
|
|
270
270
|
else if (condition(child)) {
|
|
271
271
|
descendants.push(child);
|
|
272
272
|
}
|
|
273
|
-
|
|
273
|
+
child.#getElementsBy(condition, descendants);
|
|
274
274
|
}
|
|
275
275
|
return descendants;
|
|
276
276
|
}
|
|
@@ -278,7 +278,7 @@ let AstElement = (() => {
|
|
|
278
278
|
* Get all descendants that match the selector
|
|
279
279
|
*
|
|
280
280
|
* 符合选择器的所有后代节点
|
|
281
|
-
* @param selector 选择器
|
|
281
|
+
* @param selector selector / 选择器
|
|
282
282
|
*/
|
|
283
283
|
querySelectorAll(selector) {
|
|
284
284
|
const condition = (0, selector_1.getCondition)(selector, this);
|
|
@@ -469,7 +469,7 @@ let AstElement = (() => {
|
|
|
469
469
|
* Check if the current element matches the selector
|
|
470
470
|
*
|
|
471
471
|
* 检查是否符合选择器
|
|
472
|
-
* @param selector 选择器
|
|
472
|
+
* @param selector selector / 选择器
|
|
473
473
|
*/
|
|
474
474
|
matches(selector) {
|
|
475
475
|
return selector === undefined || (0, selector_1.getCondition)(selector, this)(this);
|
package/dist/lib/lintConfig.js
CHANGED
|
@@ -11,10 +11,23 @@ const severities = new Set([0, 1, 2]), dict = new Map([
|
|
|
11
11
|
[2, 'error'],
|
|
12
12
|
]);
|
|
13
13
|
const defaultLintConfig = {
|
|
14
|
+
'bold-header': [
|
|
15
|
+
1,
|
|
16
|
+
{
|
|
17
|
+
// b: 1,
|
|
18
|
+
// strong: 1,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
14
21
|
'format-leakage': [
|
|
15
|
-
|
|
22
|
+
1,
|
|
23
|
+
{
|
|
24
|
+
// apostrophe: 1,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
'fostered-content': [
|
|
28
|
+
1,
|
|
16
29
|
{
|
|
17
|
-
//
|
|
30
|
+
// transclusion: 1,
|
|
18
31
|
},
|
|
19
32
|
],
|
|
20
33
|
h1: [
|
|
@@ -23,11 +36,20 @@ const defaultLintConfig = {
|
|
|
23
36
|
// html: 1,
|
|
24
37
|
},
|
|
25
38
|
],
|
|
39
|
+
'illegal-attr': [
|
|
40
|
+
2,
|
|
41
|
+
{
|
|
42
|
+
// tabindex: 2,
|
|
43
|
+
// unknown: 2,
|
|
44
|
+
// value: 2,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
'insecure-style': 2,
|
|
26
48
|
'invalid-gallery': [
|
|
27
49
|
2,
|
|
28
50
|
{
|
|
29
|
-
|
|
30
|
-
|
|
51
|
+
// image: 2,
|
|
52
|
+
parameter: 1,
|
|
31
53
|
},
|
|
32
54
|
],
|
|
33
55
|
'invalid-imagemap': [
|
|
@@ -37,24 +59,68 @@ const defaultLintConfig = {
|
|
|
37
59
|
// link: 2,
|
|
38
60
|
},
|
|
39
61
|
],
|
|
62
|
+
'invalid-invoke': [
|
|
63
|
+
2,
|
|
64
|
+
{
|
|
65
|
+
// function: 2,
|
|
66
|
+
// name: 2,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
'invalid-isbn': 2,
|
|
70
|
+
'lonely-apos': [
|
|
71
|
+
1,
|
|
72
|
+
{
|
|
73
|
+
// word: 1,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
'lonely-bracket': [
|
|
77
|
+
1,
|
|
78
|
+
{
|
|
79
|
+
// converter: 1,
|
|
80
|
+
// double: 1,
|
|
81
|
+
extLink: 2,
|
|
82
|
+
// single: 1,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
'lonely-http': [
|
|
86
|
+
1,
|
|
87
|
+
{
|
|
88
|
+
// ISBN: 1,
|
|
89
|
+
// PMID: 1,
|
|
90
|
+
// RFC: 1,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
40
93
|
'nested-link': [
|
|
41
94
|
2,
|
|
42
95
|
{
|
|
43
96
|
// file: 2,
|
|
44
97
|
},
|
|
45
98
|
],
|
|
99
|
+
'no-arg': 1,
|
|
46
100
|
'no-duplicate': [
|
|
47
101
|
2,
|
|
48
102
|
{
|
|
49
|
-
//
|
|
103
|
+
// attribute: 2,
|
|
104
|
+
category: 1,
|
|
50
105
|
id: 1,
|
|
106
|
+
// imageParameter: 2,
|
|
107
|
+
// parameter: 2,
|
|
108
|
+
unknownImageParameter: 1,
|
|
51
109
|
},
|
|
52
110
|
],
|
|
53
111
|
'no-ignored': [
|
|
54
112
|
2,
|
|
55
113
|
{
|
|
114
|
+
// arg: 2,
|
|
115
|
+
// closingTag: 2,
|
|
56
116
|
// conversionFlag: 2,
|
|
117
|
+
fragment: 1,
|
|
118
|
+
galleryComment: 1,
|
|
119
|
+
// galleryImage: 2,
|
|
120
|
+
galleryNoImage: 1,
|
|
57
121
|
include: 1,
|
|
122
|
+
// invalidAttributes: 2,
|
|
123
|
+
nonWordAttributes: 1,
|
|
58
124
|
redirect: 1,
|
|
59
125
|
// choose: 2,
|
|
60
126
|
// combobox: 2,
|
|
@@ -63,6 +129,33 @@ const defaultLintConfig = {
|
|
|
63
129
|
// references: 2,
|
|
64
130
|
},
|
|
65
131
|
],
|
|
132
|
+
'obsolete-attr': 1,
|
|
133
|
+
'obsolete-tag': 1,
|
|
134
|
+
'parsing-order': [
|
|
135
|
+
2,
|
|
136
|
+
{
|
|
137
|
+
// ext: 2,
|
|
138
|
+
// heading: 2,
|
|
139
|
+
// html: 2,
|
|
140
|
+
templateInTable: 1,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
'pipe-like': [
|
|
144
|
+
1,
|
|
145
|
+
{
|
|
146
|
+
double: 2,
|
|
147
|
+
// link: 1,
|
|
148
|
+
// td: 1,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
'table-layout': 1,
|
|
152
|
+
'tag-like': [
|
|
153
|
+
2,
|
|
154
|
+
{
|
|
155
|
+
disallowed: 1,
|
|
156
|
+
invalid: 1,
|
|
157
|
+
},
|
|
158
|
+
],
|
|
66
159
|
'unbalanced-header': 2,
|
|
67
160
|
'unclosed-comment': [
|
|
68
161
|
1,
|
|
@@ -70,7 +163,27 @@ const defaultLintConfig = {
|
|
|
70
163
|
// include: 1,
|
|
71
164
|
},
|
|
72
165
|
],
|
|
166
|
+
'unclosed-quote': 1,
|
|
167
|
+
'unclosed-table': 2,
|
|
73
168
|
unescaped: 2,
|
|
169
|
+
'unknown-page': 1,
|
|
170
|
+
'unmatched-tag': [
|
|
171
|
+
1,
|
|
172
|
+
{
|
|
173
|
+
// both: 1,
|
|
174
|
+
// closing: 1,
|
|
175
|
+
// conditional: 1,
|
|
176
|
+
// opening: 1,
|
|
177
|
+
// selfClosing: 1,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
'unterminated-url': [
|
|
181
|
+
1,
|
|
182
|
+
{
|
|
183
|
+
// pipe: 1,
|
|
184
|
+
// punctuation: 1,
|
|
185
|
+
},
|
|
186
|
+
],
|
|
74
187
|
'url-encoding': [
|
|
75
188
|
1,
|
|
76
189
|
{
|
|
@@ -87,9 +200,10 @@ const defaultLintConfig = {
|
|
|
87
200
|
'void-ext': [
|
|
88
201
|
2,
|
|
89
202
|
{
|
|
203
|
+
// img: 2,
|
|
90
204
|
// languages: 2,
|
|
91
|
-
// templatestyles: 2,
|
|
92
205
|
// section: 2,
|
|
206
|
+
// templatestyles: 2,
|
|
93
207
|
},
|
|
94
208
|
],
|
|
95
209
|
/* NOT FOR BROWSER ONLY */
|
|
@@ -144,6 +258,9 @@ class LintConfiguration {
|
|
|
144
258
|
}
|
|
145
259
|
/** @implements */
|
|
146
260
|
getSeverity(rule, key) {
|
|
261
|
+
if (!(rule in this)) {
|
|
262
|
+
throw new RangeError(`Unknown rule: ${rule}`);
|
|
263
|
+
}
|
|
147
264
|
const value = this[rule];
|
|
148
265
|
if (typeof value === 'number') {
|
|
149
266
|
return dict.get(value);
|
package/dist/lib/lsp.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
48
48
|
*
|
|
49
49
|
* 提供自动补全
|
|
50
50
|
* @param text source Wikitext / 源代码
|
|
51
|
-
* @param position 位置
|
|
51
|
+
* @param position position / 位置
|
|
52
52
|
*/
|
|
53
53
|
provideCompletionItems(text: string, position: Position): Promise<CompletionItem[] | undefined>;
|
|
54
54
|
/**
|
|
@@ -78,7 +78,7 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
78
78
|
*
|
|
79
79
|
* 提供引用
|
|
80
80
|
* @param text source Wikitext / 源代码
|
|
81
|
-
* @param position 位置
|
|
81
|
+
* @param position position / 位置
|
|
82
82
|
*/
|
|
83
83
|
provideReferences(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
|
|
84
84
|
/**
|
|
@@ -86,7 +86,7 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
86
86
|
*
|
|
87
87
|
* 提供定义
|
|
88
88
|
* @param text source Wikitext / 源代码
|
|
89
|
-
* @param position 位置
|
|
89
|
+
* @param position position / 位置
|
|
90
90
|
*/
|
|
91
91
|
provideDefinition(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
|
|
92
92
|
/**
|
|
@@ -94,7 +94,7 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
94
94
|
*
|
|
95
95
|
* 提供变量更名准备
|
|
96
96
|
* @param text source Wikitext / 源代码
|
|
97
|
-
* @param position 位置
|
|
97
|
+
* @param position position / 位置
|
|
98
98
|
*/
|
|
99
99
|
resolveRenameLocation(text: string, position: Position): Promise<Range | undefined>;
|
|
100
100
|
/**
|
|
@@ -102,7 +102,7 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
102
102
|
*
|
|
103
103
|
* 变量更名
|
|
104
104
|
* @param text source Wikitext / 源代码
|
|
105
|
-
* @param position 位置
|
|
105
|
+
* @param position position / 位置
|
|
106
106
|
* @param newName new name / 新名称
|
|
107
107
|
*/
|
|
108
108
|
provideRenameEdits(text: string, position: Position, newName: string): Promise<WorkspaceEdit | undefined>;
|
|
@@ -111,7 +111,7 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
111
111
|
*
|
|
112
112
|
* 提供悬停信息
|
|
113
113
|
* @param text source Wikitext / 源代码
|
|
114
|
-
* @param position 位置
|
|
114
|
+
* @param position position / 位置
|
|
115
115
|
*/
|
|
116
116
|
provideHover(text: string, position: Position): Promise<Hover | undefined>;
|
|
117
117
|
/**
|
|
@@ -119,7 +119,7 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
119
119
|
*
|
|
120
120
|
* 提供魔术字帮助
|
|
121
121
|
* @param text source Wikitext / 源代码
|
|
122
|
-
* @param position 位置
|
|
122
|
+
* @param position position / 位置
|
|
123
123
|
*/
|
|
124
124
|
provideSignatureHelp(text: string, position: Position): Promise<SignatureHelp | undefined>;
|
|
125
125
|
/**
|