diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/codemirror/lib/runmode.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/codemirror/lib/runmode.js')
-rw-r--r-- | js/codemirror/lib/runmode.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/js/codemirror/lib/runmode.js b/js/codemirror/lib/runmode.js new file mode 100644 index 00000000..163e720c --- /dev/null +++ b/js/codemirror/lib/runmode.js | |||
@@ -0,0 +1,27 @@ | |||
1 | CodeMirror.runMode = function(string, modespec, callback) { | ||
2 | var mode = CodeMirror.getMode({indentUnit: 2}, modespec); | ||
3 | var isNode = callback.nodeType == 1; | ||
4 | if (isNode) { | ||
5 | var node = callback, accum = []; | ||
6 | callback = function(string, style) { | ||
7 | if (string == "\n") | ||
8 | accum.push("<br>"); | ||
9 | else if (style) | ||
10 | accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + CodeMirror.htmlEscape(string) + "</span>"); | ||
11 | else | ||
12 | accum.push(CodeMirror.htmlEscape(string)); | ||
13 | } | ||
14 | } | ||
15 | var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode); | ||
16 | for (var i = 0, e = lines.length; i < e; ++i) { | ||
17 | if (i) callback("\n"); | ||
18 | var stream = new CodeMirror.StringStream(lines[i]); | ||
19 | while (!stream.eol()) { | ||
20 | var style = mode.token(stream, state); | ||
21 | callback(stream.current(), style); | ||
22 | stream.start = stream.pos; | ||
23 | } | ||
24 | } | ||
25 | if (isNode) | ||
26 | node.innerHTML = accum.join(""); | ||
27 | }; | ||