Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to mix both the CodeMirror: Velocity mode and the CodeMirror: HTML mixed mode?

Does anyone have made a 'htmlmixed' + 'Velocity' mode for codemirror? Or anyone can advice how to achieve that?

like image 648
iNc0ming Avatar asked Jun 06 '12 07:06

iNc0ming


2 Answers

I was able to achieve this easily with the overlay.js addon:

CodeMirror.defineMode("velocityOverlay", function(config, parserConfig) {
  return CodeMirror.overlayMode(CodeMirror.getMode(config, "htmlmixed"), CodeMirror.getMode(config, "velocity"));
});

Then in the editor set the mode option to be "velocityOverlay" and you are done.

However, the velocity mode highlights characters like <,>, etc as velocity operators which you may not want as it will make your html higlighting look ugly. To deal with this I changed the following line of code in velocity.js:

var isOperatorChar = /[+\-*&%=<>!?:\/|]/;

to

var isOperatorChar = /[+\*&%=?:|]/;
like image 100
gerry Avatar answered Oct 17 '22 19:10

gerry


You might be able to get somewhere using the mode-multiplexer, if there are specific strings that you want to use to switch mode on. But it looks like Velocity would require something more advanced. So you'd have to write your own super-mode, similar to what the htmlmixed mode does, which intelligently switches between modes.

like image 31
Marijn Avatar answered Oct 17 '22 18:10

Marijn