wikiparser-node 1.18.0 → 1.18.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/bin/config.js +3 -1
- package/bundle/bundle-es7.min.js +22 -22
- package/bundle/bundle-lsp.min.js +26 -26
- package/bundle/bundle.min.js +22 -22
- package/config/.schema.json +1 -1
- package/data/signatures.json +141 -353
- package/dist/base.d.mts +9 -1
- package/dist/base.d.ts +9 -1
- package/dist/bin/config.js +62 -56
- package/dist/index.js +4 -4
- package/dist/lib/lsp.d.ts +20 -3
- package/dist/lib/lsp.js +211 -69
- package/dist/src/attribute.js +10 -4
- package/dist/src/index.js +2 -2
- package/dist/src/nowiki/doubleUnderscore.js +3 -2
- package/dist/util/diff.js +1 -1
- package/dist/util/lint.js +31 -1
- package/extensions/dist/base.js +1 -1
- package/extensions/es7/base.js +1 -1
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +6 -2
package/dist/base.d.mts
CHANGED
|
@@ -266,6 +266,13 @@ export interface LanguageService {
|
|
|
266
266
|
* @param text source Wikitext / 源代码
|
|
267
267
|
*/
|
|
268
268
|
provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
|
|
269
|
+
/**
|
|
270
|
+
* Set the target Wikipedia
|
|
271
|
+
*
|
|
272
|
+
* 设置目标维基百科
|
|
273
|
+
* @param wiki Wikipedia URL / 维基百科网址
|
|
274
|
+
*/
|
|
275
|
+
setTargetWikipedia(wiki: string): Promise<void>;
|
|
269
276
|
}
|
|
270
277
|
export interface Parser {
|
|
271
278
|
config: Config | string;
|
|
@@ -275,8 +282,9 @@ export interface Parser {
|
|
|
275
282
|
* Get the current parser configuration
|
|
276
283
|
*
|
|
277
284
|
* 获取当前的解析设置
|
|
285
|
+
* @param config unprocessed parser configuration / 未处理的解析设置
|
|
278
286
|
*/
|
|
279
|
-
getConfig(): Config;
|
|
287
|
+
getConfig(config?: Config): Config;
|
|
280
288
|
/**
|
|
281
289
|
* Parse wikitext
|
|
282
290
|
*
|
package/dist/base.d.ts
CHANGED
|
@@ -266,6 +266,13 @@ export interface LanguageService {
|
|
|
266
266
|
* @param text source Wikitext / 源代码
|
|
267
267
|
*/
|
|
268
268
|
provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
|
|
269
|
+
/**
|
|
270
|
+
* Set the target Wikipedia
|
|
271
|
+
*
|
|
272
|
+
* 设置目标维基百科
|
|
273
|
+
* @param wiki Wikipedia URL / 维基百科网址
|
|
274
|
+
*/
|
|
275
|
+
setTargetWikipedia(wiki: string): Promise<void>;
|
|
269
276
|
}
|
|
270
277
|
export interface Parser {
|
|
271
278
|
config: Config | string;
|
|
@@ -275,8 +282,9 @@ export interface Parser {
|
|
|
275
282
|
* Get the current parser configuration
|
|
276
283
|
*
|
|
277
284
|
* 获取当前的解析设置
|
|
285
|
+
* @param config unprocessed parser configuration / 未处理的解析设置
|
|
278
286
|
*/
|
|
279
|
-
getConfig(): Config;
|
|
287
|
+
getConfig(config?: Config): Config;
|
|
280
288
|
/**
|
|
281
289
|
* Parse wikitext
|
|
282
290
|
*
|
package/dist/bin/config.js
CHANGED
|
@@ -8,64 +8,69 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const assert_1 = __importDefault(require("assert"));
|
|
10
10
|
const cm_1 = require("@bhsd/common/dist/cm");
|
|
11
|
-
const { argv } = process, [, , site, , force, old] = argv;
|
|
12
|
-
let [, , , url] = argv;
|
|
13
|
-
if (!site || !url) {
|
|
14
|
-
console.error('Usage: npx getParserConfig <site> <script path> [force]');
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
else if (/(?:\.php|\/)$/u.test(url)) {
|
|
18
|
-
url = url.slice(0, url.lastIndexOf('/'));
|
|
19
|
-
}
|
|
20
|
-
let mwConfig;
|
|
21
|
-
const mw = {
|
|
22
|
-
loader: {
|
|
23
|
-
/** @ignore */
|
|
24
|
-
impl(callback) {
|
|
25
|
-
Object.entries(callback()[1].files).find(([k]) => k.endsWith('.data.js'))[1]();
|
|
26
|
-
},
|
|
27
|
-
/** @ignore */
|
|
28
|
-
implement(_, callback) {
|
|
29
|
-
callback();
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
config: {
|
|
33
|
-
/** @ignore */
|
|
34
|
-
set({ extCodeMirrorConfig }) {
|
|
35
|
-
mwConfig = extCodeMirrorConfig;
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
11
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
12
|
+
* Get the parser configuration for a Wikimedia Foundation project.
|
|
13
|
+
* @param site site nickname
|
|
14
|
+
* @param url script path
|
|
15
|
+
* @param force whether to overwrite the existing configuration
|
|
16
|
+
* @param old whether to target an older version of MediaWiki
|
|
43
17
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
18
|
+
exports.default = async (site, url, force, old) => {
|
|
19
|
+
if (!site || !url) {
|
|
20
|
+
console.error('Usage: npx getParserConfig <site> <script path> [force]');
|
|
21
|
+
process.exit(1);
|
|
49
22
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
23
|
+
else if (/(?:\.php|\/)$/u.test(url)) {
|
|
24
|
+
url = url.slice(0, url.lastIndexOf('/'));
|
|
25
|
+
}
|
|
26
|
+
let mwConfig;
|
|
27
|
+
const mw = {
|
|
28
|
+
loader: {
|
|
29
|
+
/** @ignore */
|
|
30
|
+
impl(callback) {
|
|
31
|
+
Object.entries(callback()[1].files).find(([k]) => k.endsWith('.data.js'))[1]();
|
|
32
|
+
},
|
|
33
|
+
/** @ignore */
|
|
34
|
+
implement(_, callback) {
|
|
35
|
+
callback();
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
config: {
|
|
39
|
+
/** @ignore */
|
|
40
|
+
set({ extCodeMirrorConfig }) {
|
|
41
|
+
mwConfig = extCodeMirrorConfig;
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Converts an array to an object.
|
|
47
|
+
* @param config parser configuration
|
|
48
|
+
* @param config.articlePath article path
|
|
49
|
+
*/
|
|
50
|
+
const arrToObj = ({ articlePath, ...obj }) => {
|
|
51
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
52
|
+
if (Array.isArray(v) && v.every(x => typeof x === 'string')) {
|
|
53
|
+
Object.assign(obj, { [k]: Object.fromEntries(v.map(x => [x, true])) });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return obj;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Gets the aliases of magic words.
|
|
60
|
+
* @param magicwords magic words
|
|
61
|
+
* @param targets magic word names
|
|
62
|
+
*/
|
|
63
|
+
const getAliases = (magicwords, targets) => magicwords
|
|
64
|
+
.filter(({ name }) => targets.has(name))
|
|
65
|
+
.flatMap(({ aliases }) => aliases.map(s => s.replace(/:$/u, '').toLowerCase()));
|
|
66
|
+
/**
|
|
67
|
+
* Filters out gadget-related namespaces.
|
|
68
|
+
* @param id namespace ID
|
|
69
|
+
*/
|
|
70
|
+
const filterGadget = (id) => {
|
|
71
|
+
const n = Number(id);
|
|
72
|
+
return n < 2300 || n > 2303; // Gadget, Gadget talk, Gadget definition, Gadget definition talk
|
|
73
|
+
};
|
|
69
74
|
const m = await (await fetch(`${url}/load.php?modules=ext.CodeMirror${old ? '.data' : ''}`)).text(), params = {
|
|
70
75
|
action: 'query',
|
|
71
76
|
meta: 'siteinfo',
|
|
@@ -109,4 +114,5 @@ const filterGadget = (id) => {
|
|
|
109
114
|
if (force || !exists) {
|
|
110
115
|
fs_1.default.writeFileSync(file, `${JSON.stringify(config, null, '\t')}\n`);
|
|
111
116
|
}
|
|
112
|
-
|
|
117
|
+
return config;
|
|
118
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -74,9 +74,9 @@ const Parser = {
|
|
|
74
74
|
debugging: false,
|
|
75
75
|
/* NOT FOR BROWSER END */
|
|
76
76
|
/** @implements */
|
|
77
|
-
getConfig() {
|
|
77
|
+
getConfig(config) {
|
|
78
78
|
/* NOT FOR BROWSER ONLY */
|
|
79
|
-
if (typeof this.config === 'string') {
|
|
79
|
+
if (!config && typeof this.config === 'string') {
|
|
80
80
|
this.config = rootRequire(this.config, 'config');
|
|
81
81
|
/* istanbul ignore if */
|
|
82
82
|
if (this.config.doubleUnderscore.length < 3 || Array.isArray(this.config.parserFunction[1])) {
|
|
@@ -96,14 +96,14 @@ const Parser = {
|
|
|
96
96
|
return this.getConfig();
|
|
97
97
|
}
|
|
98
98
|
/* NOT FOR BROWSER ONLY END */
|
|
99
|
-
const { doubleUnderscore } =
|
|
99
|
+
const parserConfig = config ?? this.config, { doubleUnderscore } = parserConfig;
|
|
100
100
|
for (let i = 0; i < 2; i++) {
|
|
101
101
|
if (doubleUnderscore.length > i + 2 && doubleUnderscore[i].length === 0) {
|
|
102
102
|
doubleUnderscore[i] = Object.keys(doubleUnderscore[i + 2]);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
return {
|
|
106
|
-
...
|
|
106
|
+
...parserConfig,
|
|
107
107
|
excludes: [],
|
|
108
108
|
};
|
|
109
109
|
},
|
package/dist/lib/lsp.d.ts
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import Parser from '../index';
|
|
2
2
|
import type { Range, Position, ColorInformation, ColorPresentation, FoldingRange, DocumentLink, Location, WorkspaceEdit, Diagnostic as DiagnosticBase, TextEdit, Hover, SignatureHelp, InlayHint, CodeAction, DocumentSymbol } from 'vscode-languageserver-types';
|
|
3
|
-
import type { LanguageService as LanguageServiceBase, CompletionItem, SignatureData } from '../base';
|
|
4
|
-
import type { AttributeToken } from '../internal';
|
|
3
|
+
import type { Config, LanguageService as LanguageServiceBase, CompletionItem, SignatureData } from '../base';
|
|
4
|
+
import type { Token, AttributeToken } from '../internal';
|
|
5
5
|
export interface QuickFixData extends TextEdit {
|
|
6
6
|
title: string;
|
|
7
7
|
fix: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare const tasks: WeakMap<object, Parser.LanguageService>;
|
|
10
|
+
/**
|
|
11
|
+
* Check if a token is a plain attribute.
|
|
12
|
+
* @param token
|
|
13
|
+
* @param token.type
|
|
14
|
+
* @param token.parentNode
|
|
15
|
+
* @param token.length
|
|
16
|
+
* @param token.firstChild
|
|
17
|
+
* @param style whether it is a style attribute
|
|
18
|
+
*/
|
|
19
|
+
export declare const isAttr: ({ type, parentNode, length, firstChild }: Token, style?: boolean) => boolean | undefined;
|
|
10
20
|
/** VSCode-style language service */
|
|
11
21
|
export declare class LanguageService implements LanguageServiceBase {
|
|
12
22
|
#private;
|
|
13
23
|
include: boolean;
|
|
14
24
|
lilypond: string;
|
|
15
|
-
lilypondData: string[];
|
|
16
25
|
/** @param uri 任务标识 */
|
|
17
26
|
constructor(uri: object);
|
|
18
27
|
/** @implements */
|
|
@@ -133,4 +142,12 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
133
142
|
* @param text source Wikitext / 源代码
|
|
134
143
|
*/
|
|
135
144
|
provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
|
|
145
|
+
/**
|
|
146
|
+
* Set the target Wikipedia
|
|
147
|
+
*
|
|
148
|
+
* 设置目标维基百科
|
|
149
|
+
* @param wiki Wikipedia URL / 维基百科网址
|
|
150
|
+
* @throws `RangeError` 不是有效的维基百科网址
|
|
151
|
+
*/
|
|
152
|
+
setTargetWikipedia(wiki: string): Promise<void>;
|
|
136
153
|
}
|