|
13 | 13 |
|
14 | 14 | CodeMirror.defineMode("jinja2", function() { |
15 | 15 | var keywords = ["and", "as", "block", "endblock", "by", "cycle", "debug", "else", "elif", |
16 | | - "extends", "filter", "endfilter", "firstof", "for", |
| 16 | + "extends", "filter", "endfilter", "firstof", "do", "for", |
17 | 17 | "endfor", "if", "endif", "ifchanged", "endifchanged", |
18 | | - "ifequal", "endifequal", "ifnotequal", |
| 18 | + "ifequal", "endifequal", "ifnotequal", "set", "raw", "endraw", |
19 | 19 | "endifnotequal", "in", "include", "load", "not", "now", "or", |
20 | | - "parsed", "regroup", "reversed", "spaceless", |
21 | | - "endspaceless", "ssi", "templatetag", "openblock", |
22 | | - "closeblock", "openvariable", "closevariable", |
| 20 | + "parsed", "regroup", "reversed", "spaceless", "call", "endcall", "macro", |
| 21 | + "endmacro", "endspaceless", "ssi", "templatetag", "openblock", |
| 22 | + "closeblock", "openvariable", "closevariable", "without", "context", |
23 | 23 | "openbrace", "closebrace", "opencomment", |
24 | 24 | "closecomment", "widthratio", "url", "with", "endwith", |
25 | 25 | "get_current_language", "trans", "endtrans", "noop", "blocktrans", |
26 | 26 | "endblocktrans", "get_available_languages", |
27 | | - "get_current_language_bidi", "plural"], |
| 27 | + "get_current_language_bidi", "pluralize", "autoescape", "endautoescape"], |
28 | 28 | operator = /^[+\-*&%=<>!?|~^]/, |
29 | 29 | sign = /^[:\[\(\{]/, |
30 | 30 | atom = ["true", "false"], |
|
78 | 78 | state.instring = ch; |
79 | 79 | stream.next(); |
80 | 80 | return "string"; |
81 | | - } else if(stream.match(state.intag + "}") || stream.eat("-") && stream.match(state.intag + "}")) { |
| 81 | + } |
| 82 | + else if (state.inbraces > 0 && ch ==")") { |
| 83 | + stream.next() |
| 84 | + state.inbraces--; |
| 85 | + } |
| 86 | + else if (ch == "(") { |
| 87 | + stream.next() |
| 88 | + state.inbraces++; |
| 89 | + } |
| 90 | + else if (state.inbrackets > 0 && ch =="]") { |
| 91 | + stream.next() |
| 92 | + state.inbrackets--; |
| 93 | + } |
| 94 | + else if (ch == "[") { |
| 95 | + stream.next() |
| 96 | + state.inbrackets++; |
| 97 | + } |
| 98 | + else if (!state.lineTag && (stream.match(state.intag + "}") || stream.eat("-") && stream.match(state.intag + "}"))) { |
82 | 99 | state.intag = false; |
83 | 100 | return "tag"; |
84 | 101 | } else if(stream.match(operator)) { |
|
87 | 104 | } else if(stream.match(sign)) { |
88 | 105 | state.sign = true; |
89 | 106 | } else { |
| 107 | + if (stream.column() == 1 && state.lineTag && stream.match(keywords)) { |
| 108 | + //allow nospace after tag before the keyword |
| 109 | + return "keyword"; |
| 110 | + } |
90 | 111 | if(stream.eat(" ") || stream.sol()) { |
91 | 112 | if(stream.match(keywords)) { |
92 | 113 | return "keyword"; |
|
120 | 141 | } else if (ch = stream.eat(/\{|%/)) { |
121 | 142 | //Cache close tag |
122 | 143 | state.intag = ch; |
| 144 | + state.inbraces = 0; |
| 145 | + state.inbrackets = 0; |
123 | 146 | if(ch == "{") { |
124 | 147 | state.intag = "}"; |
125 | 148 | } |
126 | 149 | stream.eat("-"); |
127 | 150 | return "tag"; |
128 | 151 | } |
| 152 | + //Line statements |
| 153 | + } else if (stream.eat('#')) { |
| 154 | + if (stream.peek() == '#') { |
| 155 | + stream.skipToEnd(); |
| 156 | + return "comment" |
| 157 | + } |
| 158 | + else if (!stream.eol()) { |
| 159 | + state.intag = true; |
| 160 | + state.lineTag = true; |
| 161 | + state.inbraces = 0; |
| 162 | + state.inbrackets = 0; |
| 163 | + return "tag"; |
| 164 | + } |
129 | 165 | } |
130 | 166 | stream.next(); |
131 | 167 | }; |
132 | 168 |
|
133 | 169 | return { |
134 | 170 | startState: function () { |
135 | | - return {tokenize: tokenBase}; |
| 171 | + return { |
| 172 | + tokenize: tokenBase, |
| 173 | + inbrackets:0, |
| 174 | + inbraces:0 |
| 175 | + }; |
136 | 176 | }, |
137 | | - token: function (stream, state) { |
138 | | - return state.tokenize(stream, state); |
| 177 | + token: function(stream, state) { |
| 178 | + var style = state.tokenize(stream, state); |
| 179 | + if (stream.eol() && state.lineTag && !state.instring && state.inbraces == 0 && state.inbrackets == 0) { |
| 180 | + //Close line statement at the EOL |
| 181 | + state.intag = false |
| 182 | + state.lineTag = false |
| 183 | + } |
| 184 | + return style; |
139 | 185 | }, |
140 | 186 | blockCommentStart: "{#", |
141 | | - blockCommentEnd: "#}" |
| 187 | + blockCommentEnd: "#}", |
| 188 | + lineComment: "##", |
142 | 189 | }; |
143 | 190 | }); |
144 | 191 |
|
|
0 commit comments