Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codemirror Clike Mode Doesn't seem to work

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?

like image 441
synchronizer Avatar asked Jan 29 '26 19:01

synchronizer


2 Answers

For clike (c-like), we have different modes for different languages

  • For C
    mode: "text/x-csrc"
  • For Cpp
    mode: "text/x-c++src"
  • For Java
    mode: "text/x-java"
  • For Objective-C
    mode: "text/x-objectivec"
like image 140
himanshu Avatar answered Jan 31 '26 07:01

himanshu


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".

like image 29
synchronizer Avatar answered Jan 31 '26 09:01

synchronizer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!