retextjs / retext-spell

plugin to check spelling
https://unifiedjs.com
MIT License
71 stars 16 forks source link

Is it possible to use it on the client-side ? #16

Closed vasco3 closed 5 years ago

vasco3 commented 5 years ago

I would like to check spelling on an online editor in a web app. I see that the dictionaries use file-system. Is there a way to bypass that?

wooorm commented 5 years ago

Yep, it’s possible, but then you need to find some way to load the dictionaries indeed. You could, instead of something like require('dictionary-nl'), use fs.readFile in combination with something like brfs with browserify instead. Other bundlers probably have similar features.

vasco3 commented 5 years ago

Awesome, that helps! Dank u zeer

wooorm commented 5 years ago

Asjeblieft!

vasco3 commented 5 years ago

I ended up loading the dictionary as js files stored in a string template. And in the utility function I had to mimick the load function from the woorm dictionaries

 const spell = retext()
    .use(retextSpell, callback => {
      callback(null, {
        aff: en_us_aff,
        dic: en_us_dic,
      });
    })
    .use(retextSyntaxUrls);

works perfectly 🎉