-
Notifications
You must be signed in to change notification settings - Fork 3
wikiparse.Linter
Bhsd edited this page Apr 18, 2026
·
15 revisions
这是浏览器端的插件添加的全局构造器,可以用于报告潜在的语法错误,并用于 CodeMirror 和 Monaco 等网页编辑器(示例)。
展开
type: boolean
是否嵌入,默认为 false。
展开
param: string 待分析的维基文本
returns: Promise<LintError[]>
报告潜在的语法错误。默认使用英文,如需使用其他预设的语言(简体中文或繁体中文)请参考 wikiparse.setI18N 方法。
// queue (browser)
(async () => {
assert.deepStrictEqual(
await new wikiparse.Linter().queue("{{{a}}}"),
[
{
rule: "no-arg",
message: "unexpected template argument",
severity: "warning",
startIndex: 0,
startLine: 0,
startCol: 0,
endIndex: 7,
endLine: 0,
endCol: 7,
},
],
);
assert.deepStrictEqual(
await new wikiparse.Linter(true).queue("{{{a}}}"),
[],
);
})();展开
param: string 待分析的维基文本
returns: Promise<Diagnostic[]>
类似 queue 方法,但已将结果转换为 CodeMirror 需要的格式。
// codemirror (browser)
(async () => {
const errors = await new wikiparse.Linter().codemirror("http://a]"),
[{actions: [{apply}]}] = errors;
assert.deepStrictEqual(
errors,
[
{
source: "WikiLint",
rule: "lonely-bracket",
message: 'lonely "]" (lonely-bracket)',
severity: "error",
from: 8,
to: 9,
actions: [
{
name: "Suggestion: opening bracket",
apply,
},
],
},
],
);
assert.equal(typeof apply, "function");
})();展开
加入的版本:1.7.1
param: string 待分析的维基文本
returns: Promise<editor.IMarkerData[]>
类似 queue 方法,但已将结果转换为 Monaco 需要的格式。
// monaco (browser)
(async () => {
assert.deepStrictEqual(
await new wikiparse.Linter().monaco("http://a]"),
[
{
source: "WikiLint",
code: "lonely-bracket",
message: 'lonely "]"',
severity: 8,
startLineNumber: 1,
startColumn: 9,
endLineNumber: 1,
endColumn: 10,
},
],
);
})();对维基文本批量执行语法检查的命令行工具
轻量级的维基模板解析器
维基文本语言服务器协议实现
用于维基文本的 VS Code 扩展
A command-line tool that performs linting on Wikitext in bulk
A lightweight Wikitext template parser
An implementation of the Language Server Protocol for Wikitext
VS Code extension for Wikitext