1 CodeMirror.defineMode("jade", function () {
2 var symbol_regex1 = /^(?:~|!|%|\^|\*|\+|=|\\|:|;|,|\/|\?|&|<|>|\|)/;
3 var open_paren_regex = /^(\(|\[)/;
4 var close_paren_regex = /^(\)|\])/;
5 var keyword_regex1 = /^(if|else|return|var|function|include|doctype|each)/;
6 var keyword_regex2 = /^(#|{|}|\.)/;
7 var keyword_regex3 = /^(in)/;
8 var html_regex1 = /^(html|head|title|meta|link|script|body|br|div|input|span|a|img)/;
9 var html_regex2 = /^(h1|h2|h3|h4|h5|p|strong|em)/;
11 startState: function () {
16 justMatchedKeyword: false,
20 token: function (stream, state) {
21 //check for state changes
22 if (!state.inString && ((stream.peek() == '"') || (stream.peek() == "'"))) {
23 state.stringType = stream.peek();
24 stream.next(); // Skip quote
25 state.inString = true; // Update state
30 if (stream.skipTo(state.stringType)) { // Quote found on this line
31 stream.next(); // Skip quote
32 state.inString = false; // Clear flag
34 stream.skipToEnd(); // Rest of line is string
36 state.justMatchedKeyword = false;
37 return "string"; // Token style
38 } else if (stream.sol() && stream.eatSpace()) {
39 if (stream.match(keyword_regex1)) {
40 state.justMatchedKeyword = true;
44 if (stream.match(html_regex1) || stream.match(html_regex2)) {
45 state.justMatchedKeyword = true;
48 } else if (stream.sol() && stream.match(keyword_regex1)) {
49 state.justMatchedKeyword = true;
52 } else if (stream.sol() && (stream.match(html_regex1) || stream.match(html_regex2))) {
53 state.justMatchedKeyword = true;
55 } else if (stream.eatSpace()) {
56 state.justMatchedKeyword = false;
57 if (stream.match(keyword_regex3) && stream.eatSpace()) {
58 state.justMatchedKeyword = true;
61 } else if (stream.match(symbol_regex1)) {
62 state.justMatchedKeyword = false;
64 } else if (stream.match(open_paren_regex)) {
65 state.afterParen = true;
66 state.justMatchedKeyword = true;
68 } else if (stream.match(close_paren_regex)) {
69 state.afterParen = false;
70 state.justMatchedKeyword = true;
72 } else if (stream.match(keyword_regex2)) {
73 state.justMatchedKeyword = true;
75 } else if (stream.eatSpace()) {
76 state.justMatchedKeyword = false;
79 if (state.justMatchedKeyword) {
81 } else if (state.afterParen) {
90 CodeMirror.defineMIME('text/x-jade', 'jade');