How to make syntax highlight work with compressed codemirror?

Hi, all

I compressed codemirror with:

./bin/compress --local /usr/bin/uglifyjs
codemirror
active-line annotatescrollbar colorize comment dialog mark-selection
match-highlighter matchbrackets merge rulers runmode selection-pointer
simplescrollbars trailingspace clike cmake css diff dtd erlang go
groovy idl javascript lua markdown mllike pascal perl php properties
python r ruby sass shell solr soy sql swift toml velocity xml yaml
meta loadmode simple multiplex overlay jump-to-line
> codemirror-5.10.0.min.js

and the following code in html:

mergeView.edit.setOption(‘mode’, info.mime); //variable “info” has been successfully fetched.
CodeMirror.autoLoadMode(mergeView.edit, info.mode);

However, the above code didn’t make the syntax highlight work. Any suggestions?

Thanks!

Is the value of info.mime mode you put in your bundle, or one that should be dynamically loaded? In the second case, do you see any http errors in your browser console?

Thank you for the reply, Marijn. The mode is in the bundle.

Code:

if (m) {
var info = CodeMirror.findModeByExtension(m[1]);
if (info) {
console.log(info);
mergeView.edit.setOption(‘mode’, info.mime);
CodeMirror.autoLoadMode(mergeView.edit, info.mode);
}
}

And the info:

Object {name: “Go”, mime: “text/x-go”, mode: “go”, ext: Array[1]}ext: Array[1]0: "go"length: 1__proto__: Array[0]mime: "text/x-go"mode: "go"name: "Go"proto: Object

I didn’t see any http request for the mode file in browser console and no error message.

Any suggestions? The bundle was created by the compress command I pasted in the first message.

Thanks!

If you’re using a client-side module loader, you may end up accidentally loading the main lib multiple times, and thus get different mode registries.

Other than that, I have no idea. Debug by looking at CodeMirror.modes, look for error messages, etc.

Thank you, Marijn!

After the debugging I found the problem and solved it. The reason is simply that I called:

.setOption('mode', info.mime);

and the problem was fixed with:

.setOption('mode', info.mode);