Reputation: 43617
How to dynamically switch modes with CodeMirror?
I have the default set, but need to switch it.
Upvotes: 20
Views: 12137
Reputation: 1553
Something like this would help you.
First, set CodeMirror:
this.editor = CodeMirror.fromTextArea(document.getElementById("textAreaCodeMirror"), {
lineNumbers: true,
matchBrackets: true,
styleActiveLine: true,
theme:"eclipse",
mode:language
});
Then, to change the mode
this.editor.setOption("mode", language);
Upvotes: 26
Reputation: 8929
If this is CodeMirror 2 or 3, use setOption("mode", <new mode>)
(docs for setOption
, "mode"
).
For CodeMirror 1, use the setParser
method.
Upvotes: 14