diff options
author | Nivesh Rajbhandari | 2012-02-20 11:14:44 -0800 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-02-20 11:14:44 -0800 |
commit | abf78e2d7a97d295ce5a1c425fd359d47379137e (patch) | |
tree | d08c91bd2aef31e6325e0b499b2ffc390018bec6 /imports/codemirror/mode/jinja2 | |
parent | e80a79bff57fecf3aa9b869d8ed2de5fd815287c (diff) | |
parent | e23708721a71ca4c71365f5f8e8ac7d6113926db (diff) | |
download | ninja-abf78e2d7a97d295ce5a1c425fd359d47379137e.tar.gz |
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'imports/codemirror/mode/jinja2')
-rwxr-xr-x | imports/codemirror/mode/jinja2/index.html | 37 | ||||
-rwxr-xr-x | imports/codemirror/mode/jinja2/jinja2.js | 42 |
2 files changed, 79 insertions, 0 deletions
diff --git a/imports/codemirror/mode/jinja2/index.html b/imports/codemirror/mode/jinja2/index.html new file mode 100755 index 00000000..021a2829 --- /dev/null +++ b/imports/codemirror/mode/jinja2/index.html | |||
@@ -0,0 +1,37 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: Jinja2 mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="jinja2.js"></script> | ||
8 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
9 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
10 | </head> | ||
11 | <body> | ||
12 | <h1>CodeMirror: Jinja2 mode</h1> | ||
13 | <form><textarea id="code" name="code"> | ||
14 | <html style="color: green"> | ||
15 | <!-- this is a comment --> | ||
16 | <head> | ||
17 | <title>Jinja2 Example</title> | ||
18 | </head> | ||
19 | <body> | ||
20 | <ul> | ||
21 | {# this is a comment #} | ||
22 | {%- for item in li -%} | ||
23 | <li> | ||
24 | {{ item.label }} | ||
25 | </li> | ||
26 | {% endfor -%} | ||
27 | </ul> | ||
28 | </body> | ||
29 | </html> | ||
30 | </textarea></form> | ||
31 | <script> | ||
32 | var editor = | ||
33 | CodeMirror.fromTextArea(document.getElementById("code"), {mode: | ||
34 | {name: "jinja2", htmlMode: true}}); | ||
35 | </script> | ||
36 | </body> | ||
37 | </html> | ||
diff --git a/imports/codemirror/mode/jinja2/jinja2.js b/imports/codemirror/mode/jinja2/jinja2.js new file mode 100755 index 00000000..75419d84 --- /dev/null +++ b/imports/codemirror/mode/jinja2/jinja2.js | |||
@@ -0,0 +1,42 @@ | |||
1 | CodeMirror.defineMode("jinja2", function(config, parserConf) { | ||
2 | var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false", | ||
3 | "loop", "none", "self", "super", "if", "as", "not", "and", | ||
4 | "else", "import", "with", "without", "context"]; | ||
5 | keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b"); | ||
6 | |||
7 | function tokenBase (stream, state) { | ||
8 | var ch = stream.next(); | ||
9 | if (ch == "{") { | ||
10 | if (ch = stream.eat(/\{|%|#/)) { | ||
11 | stream.eat("-"); | ||
12 | state.tokenize = inTag(ch); | ||
13 | return "tag"; | ||
14 | } | ||
15 | } | ||
16 | } | ||
17 | function inTag (close) { | ||
18 | if (close == "{") { | ||
19 | close = "}"; | ||
20 | } | ||
21 | return function (stream, state) { | ||
22 | var ch = stream.next(); | ||
23 | if ((ch == close || (ch == "-" && stream.eat(close))) | ||
24 | && stream.eat("}")) { | ||
25 | state.tokenize = tokenBase; | ||
26 | return "tag"; | ||
27 | } | ||
28 | if (stream.match(keywords)) { | ||
29 | return "keyword"; | ||
30 | } | ||
31 | return close == "#" ? "comment" : "string"; | ||
32 | }; | ||
33 | } | ||
34 | return { | ||
35 | startState: function () { | ||
36 | return {tokenize: tokenBase}; | ||
37 | }, | ||
38 | token: function (stream, state) { | ||
39 | return state.tokenize(stream, state); | ||
40 | } | ||
41 | }; | ||
42 | }); | ||