|
| 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("../htmlmixed/htmlmixed"), |
| 7 | + require("../../addon/mode/overlay")); |
| 8 | + else if (typeof define == "function" && define.amd) // AMD |
| 9 | + define(["../../lib/codemirror", "../htmlmixed/htmlmixed", |
| 10 | + "../../addon/mode/overlay"], mod); |
| 11 | + else // Plain browser env |
| 12 | + mod(CodeMirror); |
| 13 | +})(function(CodeMirror) { |
| 14 | + "use strict"; |
| 15 | + |
| 16 | + CodeMirror.defineMode("tornado:inner", function() { |
| 17 | + var keywords = ["block", "for", "in", "true", "false", |
| 18 | + "none", "self", "super", "if", "end", "as", "not", "and", |
| 19 | + "else", "import", "with", "without", "context", |
| 20 | + "try", "except", "put", "escape", "xhtml_escape", "url_escape", |
| 21 | + "json_encode", "squeeze", "linkify", "datetime", |
| 22 | + "extends", "include", "load", "length", "comment", |
| 23 | + "pass", "while", "set", "import", "from", |
| 24 | + "autoescape", "raw", "module"]; |
| 25 | + keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b"); |
| 26 | + |
| 27 | + function tokenBase (stream, state) { |
| 28 | + stream.eatWhile(/[^\{]/); |
| 29 | + var ch = stream.next(); |
| 30 | + if (ch == "{") { |
| 31 | + if (ch = stream.eat(/\{|%|#/)) { |
| 32 | + state.tokenize = inTag(ch); |
| 33 | + return "tag"; |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + function inTag (close) { |
| 38 | + if (close == "{") { |
| 39 | + close = "}"; |
| 40 | + } |
| 41 | + return function (stream, state) { |
| 42 | + var ch = stream.next(); |
| 43 | + if ((ch == close) && stream.eat("}")) { |
| 44 | + state.tokenize = tokenBase; |
| 45 | + return "tag"; |
| 46 | + } |
| 47 | + if (stream.match(keywords)) { |
| 48 | + return "keyword"; |
| 49 | + } |
| 50 | + return close == "#" ? "comment" : "string"; |
| 51 | + }; |
| 52 | + } |
| 53 | + return { |
| 54 | + startState: function () { |
| 55 | + return {tokenize: tokenBase}; |
| 56 | + }, |
| 57 | + token: function (stream, state) { |
| 58 | + return state.tokenize(stream, state); |
| 59 | + } |
| 60 | + }; |
| 61 | + }); |
| 62 | + |
| 63 | + CodeMirror.defineMode("tornado", function(config) { |
| 64 | + var htmlBase = CodeMirror.getMode(config, "text/html"); |
| 65 | + var tornadoInner = CodeMirror.getMode(config, "tornado:inner"); |
| 66 | + return CodeMirror.overlayMode(htmlBase, tornadoInner); |
| 67 | + }); |
| 68 | + |
| 69 | + CodeMirror.defineMIME("text/x-tornado", "tornado"); |
| 70 | +}); |
0 commit comments