wikiparse.Linter (EN) - bhsd-harry/wikiparser-node GitHub Wiki

Other Languages

Introduction

This is a global constructor added by the browser extension, which can be used to report potential grammar errors and for online editors such as CodeMirror and Monaco (demo).

Properties

include

Expand

type: boolean
Whether to be transcluded, default to false.

Methods

queue

Expand

param: string Wikitext to be analyzed
returns: Promise<LintError[]>
Report potential grammar errors. The default language is English. To use other preset languages (Simplified Chinese or Traditional Chinese), please refer to wikiparse.setI18N method.

// 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}}}"),
		[],
	);
})();

codemirror

Expand

param: string Wikitext to be analyzed
returns: Promise<Diagnostic[]>
Similar to queue method, but the result has been converted to the format required by 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");
})();

monaco

Expand

version added: 1.7.1

param: string Wikitext to be analyzed
returns: Promise<editor.IMarkerData[]>
Similar to queue method, but the result has been converted to the format required by 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,
			},
		],
	);
})();
⚠️ **GitHub.com Fallback** ⚠️