|
| 1 | +(function(CodeMirror) { |
| 2 | + "use strict"; |
| 3 | + |
| 4 | + CodeMirror.defineMode("django:inner", function() { |
| 5 | + var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false", |
| 6 | + "loop", "none", "self", "super", "if", "endif", "as", "not", "and", |
| 7 | + "else", "import", "with", "endwith", "without", "context", "ifequal", "endifequal", |
| 8 | + "ifnotequal", "endifnotequal", "extends", "include", "load", "length", "comment", |
| 9 | + "endcomment", "empty"]; |
| 10 | + keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b"); |
| 11 | + |
| 12 | + function tokenBase (stream, state) { |
| 13 | + stream.eatWhile(/[^\{]/); |
| 14 | + var ch = stream.next(); |
| 15 | + if (ch == "{") { |
| 16 | + if (ch = stream.eat(/\{|%|#/)) { |
| 17 | + state.tokenize = inTag(ch); |
| 18 | + return "tag"; |
| 19 | + } |
| 20 | + } |
| 21 | + } |
| 22 | + function inTag (close) { |
| 23 | + if (close == "{") { |
| 24 | + close = "}"; |
| 25 | + } |
| 26 | + return function (stream, state) { |
| 27 | + var ch = stream.next(); |
| 28 | + if ((ch == close) && stream.eat("}")) { |
| 29 | + state.tokenize = tokenBase; |
| 30 | + return "tag"; |
| 31 | + } |
| 32 | + if (stream.match(keywords)) { |
| 33 | + return "keyword"; |
| 34 | + } |
| 35 | + return close == "#" ? "comment" : "string"; |
| 36 | + }; |
| 37 | + } |
| 38 | + return { |
| 39 | + startState: function () { |
| 40 | + return {tokenize: tokenBase}; |
| 41 | + }, |
| 42 | + token: function (stream, state) { |
| 43 | + return state.tokenize(stream, state); |
| 44 | + } |
| 45 | + }; |
| 46 | + }); |
| 47 | + |
| 48 | + CodeMirror.defineMode("django", function(config) { |
| 49 | + var htmlBase = CodeMirror.getMode(config, "text/html"); |
| 50 | + var djangoInner = CodeMirror.getMode(config, "django:inner"); |
| 51 | + return CodeMirror.overlayMode(htmlBase, djangoInner); |
| 52 | + }); |
| 53 | + |
| 54 | + CodeMirror.defineMIME("text/x-django", "django"); |
| 55 | +})(CodeMirror); |
0 commit comments