Skip to content

Instantly share code, notes, and snippets.

@ruemic
Forked from kylefox/liquid-mode.js
Created January 6, 2017 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruemic/96351f0f8acf0cf42b6953db579dea61 to your computer and use it in GitHub Desktop.
Save ruemic/96351f0f8acf0cf42b6953db579dea61 to your computer and use it in GitHub Desktop.
Liquid syntax highlighting for CodeMirror.
/*
This overlay provides a 'liquid' mode to the excellent CodeMirror editor (http://codemirror.net/).
Add something like this to your CSS:
.cm-liquid-tag {
color: #32273f;
background: #ead9ff;
}
.cm-liquid-variable {
color: #29739b
background: #c2e0f0;
}
*/
CodeMirror.defineMode("liquid", function(config, parserConfig) {
var liquidOverlay = {
token: function(stream, state) {
// Variables.
if (stream.match("{{")) {
while ((ch = stream.next()) != null)
if (ch == "}" && stream.next() == "}") break;
return "liquid-variable";
}
// Tags.
if(stream.match("{%")) {
while ((ch = stream.next()) != null)
if (ch == "%" && stream.next() == "}") break;
return "liquid-tag";
}
while (stream.next() != null && !stream.match("{{", false) && !stream.match("{%", false)) {}
return null;
}
};
return CodeMirror.overlayParser(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), liquidOverlay);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment