From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- js/codemirror/lib/runmode.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 js/codemirror/lib/runmode.js (limited to 'js/codemirror/lib/runmode.js') 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 @@ +CodeMirror.runMode = function(string, modespec, callback) { + var mode = CodeMirror.getMode({indentUnit: 2}, modespec); + var isNode = callback.nodeType == 1; + if (isNode) { + var node = callback, accum = []; + callback = function(string, style) { + if (string == "\n") + accum.push("
"); + else if (style) + accum.push("" + CodeMirror.htmlEscape(string) + ""); + else + accum.push(CodeMirror.htmlEscape(string)); + } + } + var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode); + for (var i = 0, e = lines.length; i < e; ++i) { + if (i) callback("\n"); + var stream = new CodeMirror.StringStream(lines[i]); + while (!stream.eol()) { + var style = mode.token(stream, state); + callback(stream.current(), style); + stream.start = stream.pos; + } + } + if (isNode) + node.innerHTML = accum.join(""); +}; -- cgit v1.2.3