From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 27 Jan 2012 12:05:17 -0800 Subject: Merged old FileIO --- imports/codemirror/lib/util/runmode.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 imports/codemirror/lib/util/runmode.js (limited to 'imports/codemirror/lib/util/runmode.js') 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 @@ +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, i, stream.start); + stream.start = stream.pos; + } + } + if (isNode) + node.innerHTML = accum.join(""); +}; -- cgit v1.2.3