reverted 4622 codemirror3 because broke zencoding and drops support for IE7, we do not use the new features anyway. Sorry

This commit is contained in:
mdipierro
2013-01-23 08:17:59 -06:00
parent b7f2991246
commit b1f77b9c4a
47 changed files with 4458 additions and 7601 deletions
+20 -19
View File
@@ -1,44 +1,43 @@
CodeMirror.runMode = function(string, modespec, callback, options) {
var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
function esc(str) {
return str.replace(/[<&]/, function(ch) { return ch == "<" ? "&lt;" : "&amp;"; });
}
if (callback.nodeType == 1) {
var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
var node = callback, col = 0;
node.innerHTML = "";
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") {
node.appendChild(document.createElement("br"));
accum.push("<br>");
col = 0;
return;
}
var content = "";
// replace tabs
var escaped = "";
// HTML-escape and replace tabs
for (var pos = 0;;) {
var idx = text.indexOf("\t", pos);
if (idx == -1) {
content += text.slice(pos);
escaped += esc(text.slice(pos));
col += text.length - pos;
break;
} else {
col += idx - pos;
content += text.slice(pos, idx);
escaped += esc(text.slice(pos, idx));
var size = tabSize - col % tabSize;
col += size;
for (var i = 0; i < size; ++i) content += " ";
for (var i = 0; i < size; ++i) escaped += " ";
pos = idx + 1;
}
}
if (style) {
var sp = node.appendChild(document.createElement("span"));
sp.className = "cm-" + style.replace(/ +/g, " cm-");
sp.appendChild(document.createTextNode(content));
} else {
node.appendChild(document.createTextNode(content));
}
if (style)
accum.push("<span class=\"cm-" + esc(style) + "\">" + escaped + "</span>");
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");
@@ -49,4 +48,6 @@ CodeMirror.runMode = function(string, modespec, callback, options) {
stream.start = stream.pos;
}
}
if (isNode)
node.innerHTML = accum.join("");
};