Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

Commit

Permalink
Merge pull request #32 from idyll-lang/remove-spellcheck
Browse files Browse the repository at this point in the history
remove spellcheck
  • Loading branch information
mathisonian authored Jul 23, 2017
2 parents 986af06 + 7452a1a commit 2be0481
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 31 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,5 @@
"lex": "^1.7.9",
"nearley": "^2.7.12",
"smartquotes": "^2.0.0"
},
"optionalDependencies": {
"spellchecker": "^3.3.1"
}
}
30 changes: 2 additions & 28 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
const grammar = require('./grammar');
const nearley = require('nearley');
const smartquotes = require('smartquotes');
let Spellcheck;
try {
Spellcheck = require('spellchecker');
} catch(e) {}

module.exports = function(input, tokens, positions, options) {
options = options || {};
let misspellings = 0;

/**
* Clean results removes unnecessary
* <p> tags inside of other blocks.
*/
const cleanResults = (node) => {
if (typeof node === 'string') {
if (options.spellcheck && Spellcheck) {
node.split(/\s/).forEach((word) => {
word = word.trim();
if (Spellcheck.isMisspelled(word)) {
const suggestions = Spellcheck.getCorrectionsForMisspelling(word);
misspellings++;
if (suggestions.length) {
console.log(word + ': did you mean ' + Spellcheck.getCorrectionsForMisspelling(word)[0]);
} else {
console.log(word + ': no suggestions found');
}
}
})
}
if (options.smartquotes) {
return smartquotes(node);
}
Expand Down Expand Up @@ -73,16 +55,8 @@ module.exports = function(input, tokens, positions, options) {
// console.log(JSON.stringify(results, null, 2));
// console.log(str);
}
misspellings = 0;
if (options.spellcheck && Spellcheck) {
console.log('\n\nSpellcheck:');
}
// console.log(JSON.stringify(results[0]));
const ret = results[0].map(cleanResults);
if (options.spellcheck && Spellcheck && misspellings === 0) {
console.log('No misspellings found.');
}
return ret;
return results[0].map(cleanResults);
}

throw new Error('No parse results');
Expand Down

0 comments on commit 2be0481

Please sign in to comment.