-
Notifications
You must be signed in to change notification settings - Fork 2
wikiparse (EN)
Table of Contents
This is a global variable added by the browser extension, which can perform various operations such as highlighting static code or text boxes, reporting potential grammar errors, etc.
Expand
type: string
The version of WikiParser-Node.
Expand
Requires CodeJar extension.
type: Promise<(textbox: HTMLTextAreaElement, include?: boolean, linenums?: boolean) => CodeJar>
Highlight text box.
(await wikiparse.codejar)(document.getElementsByTagName('textarea')[0]);
Expand
param: Record<string, string>
Set the language. The default language is English, and other preset languages include Simplified Chinese and Traditional Chinese.
// setI18N (browser)
(async () => {
const wikitext = '{{';
assert.strictEqual(
(await wikiparse.lint(wikitext))[0].message,
'lonely "{"',
);
const i18n = await (await fetch(
'https://cdn.jsdelivr.net/npm/wikiparser-node/i18n/zh-hans.json',
)).json();
wikiparse.setI18N(i18n);
assert.strictEqual(
(await wikiparse.lint(wikitext))[0].message,
'孤立的"{"',
);
})();
Expand
param: Config
Set the parsing configuration. Preset configurations include English Wikipedia (enwiki
), Chinese Wikipedia (zhwiki
), Moegirlpedia (moegirl
) and LLWiki (llwiki
). To customize the parsing configuration of a MediaWiki site, please refer to .schema.json
for the relevant content.
const config = await (await fetch(
'https://cdn.jsdelivr.net/npm/wikiparser-node/config/zhwiki.json',
)).json();
wikiparse.setConfig(config);
Expand
returns: Promise<Config>
Get the parsing configuration.
const config = await wikiparse.getConfig();
Expand
param: string
Wikitext
param: boolean
Whether to be transcluded, default to false
returns: Promise<LintError[]>
Report potential grammar errors.
// lint (browser)
(async () => {
assert.deepStrictEqual(
await wikiparse.lint('[[a]'),
[
{
rule: 'lonely-bracket',
message: 'lonely "["',
severity: 'error',
startIndex: 0,
startLine: 0,
startCol: 0,
endIndex: 2,
endLine: 0,
endCol: 2,
},
],
);
})();
Expand
param: string
Wikitext
param: boolean
Whether to be transcluded, default to false
returns: Promise<AST>
Produce an abstract syntax tree in JSON format.
// json (browser)
(async () => {
assert.deepStrictEqual(
await wikiparse.json('[[a]]'),
{
range: [0, 5],
type: 'root',
childNodes: [
{
range: [0, 5],
type: 'link',
name: 'A',
childNodes: [
{
range: [2, 3],
type: 'link-target',
childNodes: [
{
range: [2, 3],
data: 'a',
},
],
},
],
},
],
},
);
})();
Expand
param: HTMLElement
The HTML element for the static code
param: number
The starting value of line numbers, optional
param: number
The top padding, optional
returns: Promise<void>
Add line numbers to the code block.
wikiparse.lineNumbers(document.getElementsByTagName('pre')[0]);
Expand
Requires Highlight extension.
param: HTMLElement
The HTML element for the static code
param: boolean
Whether to be transcluded, default to false
param: boolean
Whether to add line numbers, default to false
param: number
The starting value of line numbers, optional
returns: Promise<void>
Highlight static code.
wikiparse.highlight(document.getElementsByTagName('pre')[0], false, true);
Expand
(Deprecated) Requires Editor extension.
param: HTMLTextAreaElement
Text box
param: boolean
Whether to be transcluded, default to false
Highlight text box.
wikiparse.edit(document.getElementsByTagName('textarea')[0]);
See Linter.
See LanguageService.
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext