From 99f904adcc37d93c90defcd8ce898598e25be212 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Wed, 11 Mar 2015 16:55:04 +0100 Subject: Lot of plugins --- .../lib/CodeMirror-2.3/lib/util/runmode.js | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js (limited to 'codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js') diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js new file mode 100644 index 0000000..fc58d85 --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js @@ -0,0 +1,49 @@ +CodeMirror.runMode = function(string, modespec, callback, options) { + var mode = CodeMirror.getMode(CodeMirror.defaults, modespec); + var isNode = callback.nodeType == 1; + var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize; + if (isNode) { + var node = callback, accum = [], col = 0; + callback = function(text, style) { + if (text == "\n") { + accum.push("
"); + col = 0; + return; + } + var escaped = ""; + // HTML-escape and replace tabs + for (var pos = 0;;) { + var idx = text.indexOf("\t", pos); + if (idx == -1) { + escaped += CodeMirror.htmlEscape(text.slice(pos)); + col += text.length - pos; + break; + } else { + col += idx - pos; + escaped += CodeMirror.htmlEscape(text.slice(pos, idx)); + var size = tabSize - col % tabSize; + col += size; + for (var i = 0; i < size; ++i) escaped += " "; + pos = idx + 1; + } + } + + if (style) + accum.push("" + escaped + ""); + else + accum.push(escaped); + } + } + 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