Documentation Center

Editor.SpellChecking.setSpellCheckingFunction

This API allows to define a callback function for custom spellchecking.

Syntax

Editor.SpellChecking.setSpellCheckingFunction(callbackFunction: Function)

Arguments

callbackFunction (word:String, lang:String) : Number || Promise
Function. A callback function which gets word and language code as arguments. It is then expected to return either a Number, or a Promise object that resolves with a Number.
word
String. Current spellchecking word.
lang
String. Language code of the current XML node where this word has been entered.
eg: de-de, en-ca, en-gb, en-us, es-es, fr-ch, fr-fr, nl-nl

To Return

Editor.SpellChecking.UNKNOWN = 0
When spell doesn't match any word in dictionary list, and cannot decide if word is correct or not.
Editor.SpellChecking.CORRECT = 1
When word is correct.
Editor.SpellChecking.WARNING_CASE = 3
Word matches as in dictionary list, but in different case.
Editor.SpellChecking.WARNING_CONCAT = 4
Word is a concatenation of two existing words.
Editor.SpellChecking.FORBIDDEN_TERM = 5
Word not to use.
Editor.SpellChecking.ERROR = 6
Word has incorrect spelling.
Promise
That eventually `resolve(:Number)`

Example

Synchronous spell checker

Editor.SpellChecking.setSpellCheckingFunction(function(word, lang) {
	console.log('custom spellchecking sync:', word, lang);
	var list = ['Example', 'About'];
	return ( list.indexOf(word) >= 0 ) ? Editor.SpellChecking.CORRECT : Editor.SpellChecking.ERROR;
});

Asynchronous spell checker

Editor.SpellChecking.setSpellCheckingFunction(function(word, lang) {
	return new Promise(function (resolve) {
		setTimeout(function() {
			console.log('custom spellchecking async:', word, lang);
			var list = ['Example', 'About'];
			resolve((list.indexOf(word) >= 0) ? Editor.SpellChecking.CORRECT : Editor.SpellChecking.ERROR);
		}, Math.random() * 1000);
	});
})