I have the words wi-fi
, spell-check
, line-break
in my .dic
file.
I want the following suggestions:
wifi
-> Suggest wi-fi
spellcheck
-> Suggest spell-check
linebreak
-> Suggest line-break
What aff setup do I need to allow that?
In Typo.js the alphabet of characters that can be used in suggestions is limited to a-z. See line 788 of the source code:
self.alphabet = "abcdefghijklmnopqrstuvwxyz";
Interestingly, below this line there is a commented out piece of code that determines the alphabet from the dictionary itself, which would have prevented the issue in the question. However, without using that code you can add characters manually in this list. Replace that line in the source by the following:
self.alphabet = "abcdefghijklmnopqrstuvwxyz-";
Then the suggestions will include dictionary items with a hyphen. Code (adapted from https://github.com/cfinke/Typo.js/blob/master/examples/node/index.js):
<!DOCTYPE html>
<html lang="en">
<head>
<script src="typo.js"></script>
<script>
function checkwords(){
var is_spelled_correctly = dictionary.check("normal");
console.log( "Is 'normal' spelled correctly? " + is_spelled_correctly );
var is_spelled_correctly = dictionary.check("line-break");
console.log( "Is 'line-break' spelled correctly? " + is_spelled_correctly );
var is_spelled_correctly = dictionary.check("linebreak");
console.log( "Is 'linebreak' spelled correctly? " + is_spelled_correctly );
var array_of_suggestions = dictionary.suggest("linebreak");
console.log( "Spelling suggestions for 'linebreak': " + array_of_suggestions.join( ', ' ) );
}
var dictionary = new Typo("yourdictionary", false, false, { dictionaryPath: ".", asyncLoad: 1, loadedCallback: checkwords });
</script>
<meta charset="utf-8" />
</head>
<body>
Typo.js test<br>
</body>
</html>
Dictionary used for testing:
5
normal
word
wi-fi
spell-check
line-break
Output:
Is 'normal' spelled correctly? true
Is 'line-break' spelled correctly? true
Is 'linebreak' spelled correctly? false
Spelling suggestions for 'linebreak': line-break