diff options
Diffstat (limited to 'codemirror_ui/lib/CodeMirror-2.3/mode/jinja2')
-rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/jinja2/index.html | 37 | ||||
-rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/jinja2/jinja2.js | 42 |
2 files changed, 79 insertions, 0 deletions
diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/jinja2/index.html b/codemirror_ui/lib/CodeMirror-2.3/mode/jinja2/index.html new file mode 100644 index 0000000..021a282 --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/jinja2/index.html @@ -0,0 +1,37 @@ +<!doctype html> +<html> + <head> + <title>CodeMirror: Jinja2 mode</title> + <link rel="stylesheet" href="../../lib/codemirror.css"> + <script src="../../lib/codemirror.js"></script> + <script src="jinja2.js"></script> + <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> + <link rel="stylesheet" href="../../doc/docs.css"> + </head> + <body> + <h1>CodeMirror: Jinja2 mode</h1> + <form><textarea id="code" name="code"> +<html style="color: green"> + <!-- this is a comment --> + <head> + <title>Jinja2 Example</title> + </head> + <body> + <ul> + {# this is a comment #} + {%- for item in li -%} + <li> + {{ item.label }} + </li> + {% endfor -%} + </ul> + </body> +</html> +</textarea></form> + <script> + var editor = + CodeMirror.fromTextArea(document.getElementById("code"), {mode: + {name: "jinja2", htmlMode: true}}); + </script> + </body> +</html> diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/jinja2/jinja2.js b/codemirror_ui/lib/CodeMirror-2.3/mode/jinja2/jinja2.js new file mode 100644 index 0000000..75419d8 --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/jinja2/jinja2.js @@ -0,0 +1,42 @@ +CodeMirror.defineMode("jinja2", function(config, parserConf) { + var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false", + "loop", "none", "self", "super", "if", "as", "not", "and", + "else", "import", "with", "without", "context"]; + keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b"); + + function tokenBase (stream, state) { + var ch = stream.next(); + if (ch == "{") { + if (ch = stream.eat(/\{|%|#/)) { + stream.eat("-"); + state.tokenize = inTag(ch); + return "tag"; + } + } + } + function inTag (close) { + if (close == "{") { + close = "}"; + } + return function (stream, state) { + var ch = stream.next(); + if ((ch == close || (ch == "-" && stream.eat(close))) + && stream.eat("}")) { + state.tokenize = tokenBase; + return "tag"; + } + if (stream.match(keywords)) { + return "keyword"; + } + return close == "#" ? "comment" : "string"; + }; + } + return { + startState: function () { + return {tokenize: tokenBase}; + }, + token: function (stream, state) { + return state.tokenize(stream, state); + } + }; +}); |