The example of Usachi has special processing, because for processing two-character separators (for example, there are two characters in '{{' and '}}' ). I have never used CodeMirror before, so this is just a hunch, but try something like this:
CodeMirror.defineMode("mymode", function(config, parserConfig) { var mymodeOverlay = { token: function(stream, state) { if (stream.match("{")) { while ((ch = stream.next()) != null) if (ch == "}") break; return "mymode"; } while (stream.next() != null && !stream.match("{", false)) {} return null; } }; return CodeMirror.overlayParser(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), mymodeOverlay); });
Edit
it works (although it also highlights words with lowercase letters)
This should work:
token: function(stream, state) { if (stream.match("{")) { while ((ch = stream.next()) != null && ch === ch.toUpperCase()) if (ch == "}") break; return "mymode"; } while (stream.next() != null && !stream.match("{", false)) {} return null; }
Matt ball
source share