Inscryb / inscryb-markdown-editor

A simple, beautiful, and embeddable JavaScript Markdown editor. Based off SimpleMDE by Sparksuite.
MIT License
90 stars 16 forks source link

Spellchecker language #5

Open Akirami opened 6 years ago

Akirami commented 6 years ago

Hi,

I'm using vue-simpleMDE for my project and i found your package, i'm interested by it and happy to know that someone continue the work.

So i would like to know if you've found a way to integrate spellchecker in other language than english, if not i'll do it in the next week / month (pass option to typo.js, search for common dictionnaries in other language, integrate it in SimpleMDE / InscrybMDE).

Let me know if you are interested and like tou see i really need a spellchecker ;) (i'm french)

Also, it would be a great thing if you could briefly summarize the change you made to SimpleMDE.

Thanks.

CWharton commented 6 years ago

Right now the project is using codemirror-spell-checker for spell checking, another project by sparksuite. I like the idea of moving to standardized dictionaries. If typo.js is currently maintained then I think it would be a great move. I would love a PR if you find the time.

As far as changes, I have updated the libraries due to security issues and added Font Awesome 5 support. Nothing really big yet. I have noticed a few bugs and feature that I plan to implement in the near future.

Akirami commented 6 years ago

I saw codemirror-spell-checker and there is no option to select a different language than en_US, it need many rewrite.

I've make test this night with the use of codemirror-typo instead of codemirror-spell-checker and it work,

in simplemde.js

var codeMirrorTypo = require("codemirror-typo");
//--- add en replace at line 1466 //
var mode, backdrop;
    /*if(options.spellChecker !== false) {
        mode = "spell-checker";
        backdrop = options.parsingConfig;
        backdrop.name = "gfm";
        backdrop.gitHubSpice = false;

        CodeMirrorSpellChecker({
            codeMirrorInstance: CodeMirror
        });
    } else {
        mode = options.parsingConfig;
        mode.name = "gfm";
        mode.gitHubSpice = false;
    }*/

    // Find language options
    if (options.isSpellCheck !== false) {
        mode = "spell-checker";
        backdrop = options.parsingConfig;
        backdrop.name = "gfm";
        backdrop.gitHubSpice = false;
    } else {
        mode = options.parsingConfig;
        mode.name = "gfm";
        mode.gitHubSpice = false;
    }   

    this.codemirror = CodeMirror.fromTextArea(el, {
        mode: mode,
        backdrop: backdrop,
        theme: "paper",
        tabSize: (options.tabSize != undefined) ? options.tabSize : 2,
        indentUnit: (options.tabSize != undefined) ? options.tabSize : 2,
        indentWithTabs: (options.indentWithTabs === false) ? false : true,
        lineNumbers: false,
        autofocus: (options.autofocus === true) ? true : false,
        extraKeys: keyMaps,
        lineWrapping: (options.lineWrapping === false) ? false : true,
        allowDropFileTypes: ["text/plain"],
        placeholder: options.placeholder || el.getAttribute("placeholder") || "",
        styleSelectedText: (options.styleSelectedText != undefined) ? options.styleSelectedText : true
    }); 
    if (options.isSpellCheck !== false) {
        codeMirrorTypo(this.codemirror, options.spellCheckerLang.lang, options.spellCheckerLang.path);
    }

And in simplemde configs, only add:

configs: {
  autofocus: true,
  forceSync: true,
  ...,
  spellChecker: false,
  isSpellCheck: true,
  spellCheckerLang: {
    lang: 'fr_FR',
    path: 'path/to/dictionary/fr_FR/'
  }

It's just a work around and i notice some problem, the dic is loaded every time the editor is called (XMLHttpRequest in codemirror-typo/typo-tools.js) and it make 2 second to scan every word (in dev mod), even with short text, i think it's maybe the gutter with the proposal word's replacement and maybe i need to disable this before continue.

I think I'll have time in the next days, so i continue but some help will be welcome ;)

eutampieri commented 5 years ago

I don't think spark suite-spell-check needs a lot of rewrite: I had made a PR a long time ago but it didn't go through. If you want to integrate my code it's on https://github.com/ETSoftware/codemirror-spell-checker. Also, it supports standard dicts.