Add a whitelist of words which should not be spellchecked

This commit is contained in:
Shane Kilkelly 2017-06-22 09:23:47 +01:00
parent 0229794616
commit 7842bcd24f
2 changed files with 26 additions and 4 deletions

View file

@ -3,6 +3,16 @@ LearnedWordsManager = require './LearnedWordsManager'
async = require 'async'
module.exports = SpellingAPIManager =
wordWhitelist: [
'ShareLaTeX',
'sharelatex',
'LaTeX',
'http',
'https',
'www'
]
runRequest: (token, request, callback = (error, result) ->) ->
if !request.words?
return callback(new Error("malformed JSON"))
@ -13,10 +23,13 @@ module.exports = SpellingAPIManager =
ASpell.checkWords lang, words, (error, misspellings) ->
callback error, misspellings: misspellings
wordsToCheck = (request.words || []).filter (word) ->
SpellingAPIManager.wordWhitelist.indexOf(word) == -1
if token?
LearnedWordsManager.getLearnedWords token, (error, learnedWords) ->
return callback(error) if error?
words = (request.words || []).slice(0,10000)
words = (wordsToCheck).slice(0,10000)
check words, (error, result) ->
return callback error if error?
result.misspellings = result.misspellings.filter (m) ->
@ -24,7 +37,7 @@ module.exports = SpellingAPIManager =
learnedWords.indexOf(word) == -1
callback error, result
else
check(request.words, callback)
check(wordsToCheck, callback)
learnWord: (token, request, callback = (error) ->) ->
if !request.word?

View file

@ -80,6 +80,15 @@ describe "SpellingAPIManager", ->
it "should truncate to 10,000 words", ->
@ASpell.checkWords.calledWith(sinon.match.any, @manyWords.slice(0, 10000)).should.equal true
describe 'with words from the whitelist', ->
beforeEach (done) ->
@whitelistWord = @SpellingAPIManager.wordWhitelist[0]
@words = ["One", @whitelistWord, "Two"]
@SpellingAPIManager.runRequest @token, words: @words, (error, @result) => done()
it 'should ignore the white-listed word', ->
expect(@ASpell.checkWords.lastCall.args[1]).to.deep.equal ["One", "Two"]
describe "learnWord", ->
describe "without a token", ->
beforeEach (done) -> @SpellingAPIManager.learnWord null, word: "banana", (@error) => done()