I am trying to use CodeMirror in my project with the clike mode for vertex and fragment snippets, but for some reason the syntax highlighting doesn't work for anything but numbers and string literals. The javascript syntax highlighter works fine.
I load all of the relevant files:
<link rel="stylesheet" href="js/third-party/codemirror/lib/codemirror.css">
<script src='js/third-party/codemirror/lib/codemirror.js'></script>
<script src='js/third-party/codemirror/mode/clike/clike.js'></script>
I create a textarea in the index.html:
<textarea id = "WEEE"></textarea>
Then I initialize an editor:
<script>
const myTextarea = document.getElementById("WEEE");
var editor = CodeMirror.fromTextArea(myTextarea, {
lineNumbers: true,
mode: "clike"
});
</script>
The result is no syntax highlighting. The online examples clearly still work. CodeMirror.modes returns a list of modes, and clike seems to be fully loaded. What am I missing?
For clike (c-like), we have different modes for different languages
mode: "text/x-csrc" mode: "text/x-c++src"mode: "text/x-java"mode: "text/x-objectivec"It wasn't obvious to me, but I need to use a separate mode name defined in clike, since clike is a bunch of modes. I chose "x-shader/x-fragment".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With