Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/jade/jade.js
1293 views
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)/;
10
return {
11
startState: function () {
12
return {
13
inString: false,
14
stringType: "",
15
beforeTag: true,
16
justMatchedKeyword: false,
17
afterParen: false
18
};
19
},
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
26
}
27
28
//return state
29
if (state.inString) {
30
if (stream.skipTo(state.stringType)) { // Quote found on this line
31
stream.next(); // Skip quote
32
state.inString = false; // Clear flag
33
} else {
34
stream.skipToEnd(); // Rest of line is string
35
}
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;
41
stream.eatSpace();
42
return "keyword";
43
}
44
if (stream.match(html_regex1) || stream.match(html_regex2)) {
45
state.justMatchedKeyword = true;
46
return "variable";
47
}
48
} else if (stream.sol() && stream.match(keyword_regex1)) {
49
state.justMatchedKeyword = true;
50
stream.eatSpace();
51
return "keyword";
52
} else if (stream.sol() && (stream.match(html_regex1) || stream.match(html_regex2))) {
53
state.justMatchedKeyword = true;
54
return "variable";
55
} else if (stream.eatSpace()) {
56
state.justMatchedKeyword = false;
57
if (stream.match(keyword_regex3) && stream.eatSpace()) {
58
state.justMatchedKeyword = true;
59
return "keyword";
60
}
61
} else if (stream.match(symbol_regex1)) {
62
state.justMatchedKeyword = false;
63
return "atom";
64
} else if (stream.match(open_paren_regex)) {
65
state.afterParen = true;
66
state.justMatchedKeyword = true;
67
return "def";
68
} else if (stream.match(close_paren_regex)) {
69
state.afterParen = false;
70
state.justMatchedKeyword = true;
71
return "def";
72
} else if (stream.match(keyword_regex2)) {
73
state.justMatchedKeyword = true;
74
return "keyword";
75
} else if (stream.eatSpace()) {
76
state.justMatchedKeyword = false;
77
} else {
78
stream.next();
79
if (state.justMatchedKeyword) {
80
return "property";
81
} else if (state.afterParen) {
82
return "property";
83
}
84
}
85
return null;
86
}
87
};
88
});
89
90
CodeMirror.defineMIME('text/x-jade', 'jade');
91
92