From c2805e03c84b6e598556fd06d1ede7aaeea7ce9c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 6 Mar 2012 16:17:54 -0800 Subject: Squashed commit FileIO-Build-Candidate into Master Fixing issues with HTML and CSS URLs. Adjusted RegEx logic. Also code a mirror update and undo/redo changes were merged into this request. Signed-off-by: Valerio Virgillito --- imports/codemirror/lib/util/runmode.js | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) mode change 100755 => 100644 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 old mode 100755 new mode 100644 index de4a7602..fc58d857 --- a/imports/codemirror/lib/util/runmode.js +++ b/imports/codemirror/lib/util/runmode.js @@ -1,15 +1,37 @@ -CodeMirror.runMode = function(string, modespec, callback) { - var mode = CodeMirror.getMode({indentUnit: 2}, modespec); +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 = []; - callback = function(string, style) { - if (string == "\n") + var node = callback, accum = [], col = 0; + callback = function(text, style) { + if (text == "\n") { accum.push("
"); - else if (style) - accum.push("" + CodeMirror.htmlEscape(string) + ""); + 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(CodeMirror.htmlEscape(string)); + accum.push(escaped); } } var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode); -- cgit v1.2.3