From 038a9204b4413900de7fbac8986bd54508d563ae Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 18 May 2021 16:05:40 -0700 Subject: [PATCH] Allow for specifying a custom spell-checker for EasyMDE --- README.md | 2 +- src/js/easymde.js | 12 +++++++++--- types/easymde.d.ts | 6 +++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f418fd5..bbc4869 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ easyMDE.value('New input for **EasyMDE**'); - **sanitizerFunction**: Custom function for sanitizing the HTML output of markdown renderer. - **shortcuts**: Keyboard shortcuts associated with this instance. Defaults to the [array of shortcuts](#keyboard-shortcuts). - **showIcons**: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar. -- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`. +- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`. Optionally pass a CodeMirrorSpellChecker compliant function. - **inputStyle**: `textarea` or `contenteditable`. Defaults to `textarea` for desktop and `contenteditable` for mobile. `contenteditable` option is necessary to enable nativeSpellcheck. - **nativeSpellcheck**: If set to `false`, disable native spell checker. Defaults to `true`. - **sideBySideFullscreen**: If set to `false`, allows side-by-side editing without going into fullscreen. Defaults to `true`. diff --git a/src/js/easymde.js b/src/js/easymde.js index f7c1e46..eddb90e 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -2052,9 +2052,15 @@ EasyMDE.prototype.render = function (el) { backdrop.name = 'gfm'; backdrop.gitHubSpice = false; - CodeMirrorSpellChecker({ - codeMirrorInstance: CodeMirror, - }); + if (typeof options.spellChecker === 'function') { + options.spellChecker({ + codeMirrorInstance: CodeMirror, + }); + } else { + CodeMirrorSpellChecker({ + codeMirrorInstance: CodeMirror, + }); + } } // eslint-disable-next-line no-unused-vars diff --git a/types/easymde.d.ts b/types/easymde.d.ts index f74d6f4..2ba1502 100644 --- a/types/easymde.d.ts +++ b/types/easymde.d.ts @@ -165,6 +165,10 @@ declare namespace EasyMDE { combine?: boolean } + interface SpellCheckerOptions { + codeMirrorInstance: CodeMirror.Editor + } + interface Options { autoDownloadFontAwesome?: boolean; autofocus?: boolean; @@ -190,7 +194,7 @@ declare namespace EasyMDE { renderingConfig?: RenderingOptions; shortcuts?: Shortcuts; showIcons?: ReadonlyArray; - spellChecker?: boolean; + spellChecker?: boolean | ((options: SpellCheckerOptions) => void); inputStyle?: 'textarea' | 'contenteditable'; nativeSpellcheck?: boolean; sideBySideFullscreen?: boolean;