Search code examples
codemirror

CodeMirror determine the name of the mode


How can I tell the name of the "mode" for each language in CodeMirror?

For example, the mode "HTML Embedded" gives this page: http://codemirror.net/mode/htmlembedded/index.html

On this page, there is a script, but it doesn't set the mode.

  var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    matchBrackets: true,
    continueComments: "Enter",
    extraKeys: {"Ctrl-Q": "toggleComment"}
  });

I would expect a mode: "somemode" to be in this. How else can we tell the name of it?


Solution

  • The first mode loaded becomes the default mode. You can do editor.getMode().name to get the name of the mode loaded in an editor instance.