Skip to content

Instantly share code, notes, and snippets.

@lukemorton
Created November 14, 2011 16:58
Show Gist options
  • Save lukemorton/1364437 to your computer and use it in GitHub Desktop.
Save lukemorton/1364437 to your computer and use it in GitHub Desktop.
CodeMirror mustache support
CodeMirror.defineMode("mustache", function (config, parserConfig) {
var mustacheOverlay = {
token: function (stream, state) {
if (stream.match("{{")) {
while ((ch = stream.next()) != null)
if (ch == "}" && stream.next() == "}") break;
return "mustache";
}
while (stream.next() != null && !stream.match("{{", false)) {}
return null;
}
};
return CodeMirror.overlayParser(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"),
mustacheOverlay);
});
//Credit unknown :(
@peterflynn
Copy link

This looks like an older version of the code at https://github.com/marijnh/CodeMirror/blob/master/demo/mustache.html

@bbugh
Copy link

bbugh commented Apr 24, 2020

I'm trying to upgrade some an old CodeMirror code mode and comparing this with the newer version that @peterflynn posted of mustache helped me solve the issue I was having (overlayParser is now overlayMode). Thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment