diff --git a/README.md b/README.md index 8e589e4..a2c15ec 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,24 @@ CodeMirror.fromTextArea(document.getElementById("textarea"), { That's it! +## Other languages +In order to use another language instead of `en_US` you just have to provide an additional piece of configuration: + +```JS +CodeMirrorSpellChecker({ + codeMirrorInstance: CodeMirror, + customDict: { + dic: "https://github.com/titoBouzout/Dictionaries/blob/master/Italian.dic", + aff: "https://github.com/titoBouzout/Dictionaries/blob/master/Italian.aff" + } +}); + +CodeMirror.fromTextArea(document.getElementById("textarea"), { + mode: "spell-checker", + backdrop: "gfm" // Your desired mode +}); +``` + ## Customizing You can customize the misspelled word appearance by updating the CSS. All misspelled words will have the `.cm-spell-error` class. diff --git a/src/js/spell-checker.js b/src/js/spell-checker.js index a292034..195122c 100644 --- a/src/js/spell-checker.js +++ b/src/js/spell-checker.js @@ -34,7 +34,14 @@ function CodeMirrorSpellChecker(options) { if(!CodeMirrorSpellChecker.aff_loading) { CodeMirrorSpellChecker.aff_loading = true; var xhr_aff = new XMLHttpRequest(); - xhr_aff.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff", true); + var affUrl; + if(options.customDict===undefined){ + affUrl="https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff"; + } + else{ + affUrl=options.customDict.aff; + } + xhr_aff.open("GET", affUrl, true); xhr_aff.onload = function() { if(xhr_aff.readyState === 4 && xhr_aff.status === 200) { CodeMirrorSpellChecker.aff_data = xhr_aff.responseText; @@ -53,7 +60,14 @@ function CodeMirrorSpellChecker(options) { if(!CodeMirrorSpellChecker.dic_loading) { CodeMirrorSpellChecker.dic_loading = true; var xhr_dic = new XMLHttpRequest(); - xhr_dic.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic", true); + var dicUrl + if(options.customDict===undefined){ + dicUrl="https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic"; + } + else{ + affUrl=options.customDict.dic; + } + xhr_dic.open("GET", dicUrl, true); xhr_dic.onload = function() { if(xhr_dic.readyState === 4 && xhr_dic.status === 200) { CodeMirrorSpellChecker.dic_data = xhr_dic.responseText;