Update I just remembered that my mode changer would never work unless I provided the mime type code mirror expects, not the mode name. i.e. pass it text/x-markdown
and not markdown
I'm using the latest release of codemirror on my site http://pste.me.
Via a select menu, the mode can be changed using:
$('#mode').change(function(){
editor.setOption("mode", $(this).val() );
});
Where editor
is a reference to an CodeMirror.fromTextArea
object.
I'm not a codemirror expert but I believe the addition mode/autoload methods are no longer used. I'm not having any problem with it auto-loading the needed files, but you could always dynamically build a new script tag and append it to the document head
before setting the mode.
That's the method we use for the editor themes:
// Append the theme styles
var link = document.createElement('link');
link.onload = function(){
pste.editor.setOption("theme", theme);
};
link.rel = "stylesheet";
link.media = "all";
link.href = INTERFACE_URL+"/codemirror/theme/"+theme+".css";
document.getElementsByTagName('head')[0].appendChild(link);