github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/app/public/codemirror/mode/handlebars/handlebars.js (about) 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 // Distributed under an MIT license: http://codemirror.net/LICENSE 3 4 (function(mod) { 5 if (typeof exports == "object" && typeof module == "object") // CommonJS 6 mod(require("../../lib/codemirror"), require("../../addon/mode/simple"), require("../../addon/mode/multiplex")); 7 else if (typeof define == "function" && define.amd) // AMD 8 define(["../../lib/codemirror", "../../addon/mode/simple", "../../addon/mode/multiplex"], mod); 9 else // Plain browser env 10 mod(CodeMirror); 11 })(function(CodeMirror) { 12 "use strict"; 13 14 CodeMirror.defineSimpleMode("handlebars-tags", { 15 start: [ 16 { regex: /\{\{!--/, push: "dash_comment", token: "comment" }, 17 { regex: /\{\{!/, push: "comment", token: "comment" }, 18 { regex: /\{\{/, push: "handlebars", token: "tag" } 19 ], 20 handlebars: [ 21 { regex: /\}\}/, pop: true, token: "tag" }, 22 23 // Double and single quotes 24 { regex: /"(?:[^\\"]|\\.)*"?/, token: "string" }, 25 { regex: /'(?:[^\\']|\\.)*'?/, token: "string" }, 26 27 // Handlebars keywords 28 { regex: />|[#\/]([A-Za-z_]\w*)/, token: "keyword" }, 29 { regex: /(?:else|this)\b/, token: "keyword" }, 30 31 // Numeral 32 { regex: /\d+/i, token: "number" }, 33 34 // Atoms like = and . 35 { regex: /=|~|@|true|false/, token: "atom" }, 36 37 // Paths 38 { regex: /(?:\.\.\/)*(?:[A-Za-z_][\w\.]*)+/, token: "variable-2" } 39 ], 40 dash_comment: [ 41 { regex: /--\}\}/, pop: true, token: "comment" }, 42 43 // Commented code 44 { regex: /./, token: "comment"} 45 ], 46 comment: [ 47 { regex: /\}\}/, pop: true, token: "comment" }, 48 { regex: /./, token: "comment" } 49 ] 50 }); 51 52 CodeMirror.defineMode("handlebars", function(config, parserConfig) { 53 var handlebars = CodeMirror.getMode(config, "handlebars-tags"); 54 if (!parserConfig || !parserConfig.base) return handlebars; 55 return CodeMirror.multiplexingMode( 56 CodeMirror.getMode(config, parserConfig.base), 57 {open: "{{", close: "}}", mode: handlebars, parseDelimiters: true} 58 ); 59 }); 60 61 CodeMirror.defineMIME("text/x-handlebars-template", "handlebars"); 62 });