5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"),
7
require("../../addon/mode/overlay"));
8
else if (typeof define == "function" && define.amd)
9
define(["../../lib/codemirror", "../htmlmixed/htmlmixed",
10
"../../addon/mode/overlay"], mod);
13
})(function(CodeMirror) {
16
CodeMirror.defineMode("tornado:inner", function() {
17
var keywords = ["and","as","assert","autoescape","block","break","class","comment","context",
18
"continue","datetime","def","del","elif","else","end","escape","except",
19
"exec","extends","false","finally","for","from","global","if","import","in",
20
"include","is","json_encode","lambda","length","linkify","load","module",
21
"none","not","or","pass","print","put","raise","raw","return","self","set",
22
"squeeze","super","true","try","url_escape","while","with","without","xhtml_escape","yield"];
23
keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b");
25
function tokenBase (stream, state) {
26
stream.eatWhile(/[^\{]/);
27
var ch = stream.next();
29
if (ch = stream.eat(/\{|%|#/)) {
30
state.tokenize = inTag(ch);
35
function inTag (close) {
39
return function (stream, state) {
40
var ch = stream.next();
41
if ((ch == close) && stream.eat("}")) {
42
state.tokenize = tokenBase;
45
if (stream.match(keywords)) {
48
return close == "#" ? "comment" : "string";
52
startState: function () {
53
return {tokenize: tokenBase};
55
token: function (stream, state) {
56
return state.tokenize(stream, state);
61
CodeMirror.defineMode("tornado", function(config) {
62
var htmlBase = CodeMirror.getMode(config, "text/html");
63
var tornadoInner = CodeMirror.getMode(config, "tornado:inner");
64
return CodeMirror.overlayMode(htmlBase, tornadoInner);
67
CodeMirror.defineMIME("text/x-tornado", "tornado");