sparksuite / codemirror-spell-checker

Dead-simple spell checking in CodeMirror
http://sparksuite.github.io/codemirror-spell-checker/
MIT License
83 stars 52 forks source link

Problem when using CDN file #40

Open arvindpdmn opened 6 years ago

arvindpdmn commented 6 years ago

This is what I have in <head>:

<script src="https://cdn.jsdelivr.net/npm/codemirror-spell-checker@1.1.2/src/js/spell-checker.min.js"  type="text/javascript"></script>
<script src="https://codemirror.net/addon/mode/overlay.js"  type="text/javascript"></script>

This fails with error ReferenceError: require is not defined due to an attempt to require typo-js. What I understand is that require will work within Node.js runtime but not in browser. What's the solution?

arvindpdmn commented 6 years ago

I removed the require and export from . My code is now:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/codemirror.spell-checker/latest/spell-checker.min.css">
<script src="https://cdn.jsdelivr.net/npm/typo-js@1.0.3/typo.min.js"></script>
<script src={localpath}/js/spell-checker.min.js"></script>
<script src="https://codemirror.net/addon/mode/overlay.js"></script>

No errors this time but spell check is not happening. In CodeMirror, textarea content is actually within <div class="CodeMirror-code" role="presentation>". Nothing happens when spell checker is invoked this way:

    CodeMirrorSpellChecker({
        codeMirrorInstance: CodeMirror,
    });
    CodeMirror.fromTextArea(jQuery(".CodeMirror-code")[0], {
        mode: "spell-checker"
    });