-
-
Save xergio/a2199a51c577a4859c780445d1b8e0dc to your computer and use it in GitHub Desktop.
Liquid syntax highlighting for CodeMirror.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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