Last active
December 24, 2017 10:50
-
-
Save sprintr/0a6dafd7204fd4002c39 to your computer and use it in GitHub Desktop.
Brackets' CodeMirror simple-mode demo
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
define(function (require, exports, module) { | |
var CodeMirror = brackets.getModule("thirdparty/CodeMirror/lib/codemirror"), | |
LanguageManager = brackets.getModule("language/LanguageManager"); | |
CodeMirror.defineSimpleMode("handlebars", { | |
start: [ | |
{ regex: /\{\{!--/, push: "dash_comment", token: "comment" }, | |
{ regex: /\{\{!/, push: "comment", token: "comment" }, | |
{ regex: /\{\{/, push: "handlebars", token: "tag" } | |
], | |
handlebars: [ | |
{ regex: /\}\}/, pop: true, token: "tag" }, | |
// Double and single quotes | |
{ regex: /"(?:[^\\]|\\.)*?"/, token: "string" }, | |
{ regex: /'(?:[^\\]|\\.)*?'/, token: "string" }, | |
// Handlebars keywords | |
{ regex: />|[#\/]([A-Za-z_]\w*)/, token: "keyword" }, | |
{ regex: /(?:else|this)\b/, token: "keyword" }, | |
// Numeral | |
{ regex: /\d+/i, token: "number" }, | |
// Atoms like = and . | |
{ regex: /=|~|@|true|false/, token: "atom" }, | |
// Paths | |
{ regex: /(?:\.\.\/)*(?:[A-Za-z_][\w\.]*)+/, token: "variable-2" } | |
], | |
dash_comment: [ | |
{ regex: /--\}\}/, pop: true, token: "comment" }, | |
// Commented code | |
{ regex: /./, token: "comment"} | |
], | |
comment: [ | |
{ regex: /\}\}/, pop: true, token: "comment" }, | |
{ regex: /./, token: "comment" } | |
] | |
}); | |
CodeMirror.defineMIME("text/x-handlebars-template", "handlebars"); | |
LanguageManager.defineLanguage("handlebars", { | |
name: "Handlebars", | |
mode: ["handlebars", "text/x-handlebars-template"], | |
fileExtensions: ["hbrs"] | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment