aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/lib/util/runmode.js
diff options
context:
space:
mode:
authorEric Guzman2012-02-16 00:22:43 -0800
committerEric Guzman2012-02-16 00:22:43 -0800
commit82b1a273219f0ae3d119e156c7acccdbe478f441 (patch)
tree74c45e5e3afc6706b2f7a7918807f72c54cdcfc5 /imports/codemirror/lib/util/runmode.js
parentaf20ca9b11133dd5cefb9275dbe8fb101c3380d0 (diff)
parent966f0adaf1d4b7f2dd5a6e31643df58bff713884 (diff)
downloadninja-82b1a273219f0ae3d119e156c7acccdbe478f441.tar.gz
Merge branch 'refs/heads/TreeComponents' into PresetsPanel
Diffstat (limited to 'imports/codemirror/lib/util/runmode.js')
-rwxr-xr-ximports/codemirror/lib/util/runmode.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/imports/codemirror/lib/util/runmode.js b/imports/codemirror/lib/util/runmode.js
new file mode 100755
index 00000000..de4a7602
--- /dev/null
+++ b/imports/codemirror/lib/util/runmode.js
@@ -0,0 +1,27 @@
1CodeMirror.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, i, stream.start);
22 stream.start = stream.pos;
23 }
24 }
25 if (isNode)
26 node.innerHTML = accum.join("");
27};