##// END OF EJS Templates
update CodeMirror2 to 2.32
update CodeMirror2 to 2.32

File last commit:

r8053:58574fbf
r8053:58574fbf
Show More
runmode.js
49 lines | 1.6 KiB | application/javascript | JavascriptLexer
Matthias BUSSONNIER
update CodeMirror2 to 2.32
r8053 CodeMirror.runMode = function(string, modespec, callback, options) {
var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
Brian E. Granger
Updating CodeMirror to v 2.12....
r4504 var isNode = callback.nodeType == 1;
Matthias BUSSONNIER
update CodeMirror2 to 2.32
r8053 var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
Brian E. Granger
Updating CodeMirror to v 2.12....
r4504 if (isNode) {
Matthias BUSSONNIER
update CodeMirror2 to 2.32
r8053 var node = callback, accum = [], col = 0;
callback = function(text, style) {
if (text == "\n") {
Brian E. Granger
Updating CodeMirror to v 2.12....
r4504 accum.push("<br>");
Matthias BUSSONNIER
update CodeMirror2 to 2.32
r8053 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("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + escaped + "</span>");
Brian E. Granger
Updating CodeMirror to v 2.12....
r4504 else
Matthias BUSSONNIER
update CodeMirror2 to 2.32
r8053 accum.push(escaped);
Brian E. Granger
Updating CodeMirror to v 2.12....
r4504 }
}
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);
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 callback(stream.current(), style, i, stream.start);
Brian E. Granger
Updating CodeMirror to v 2.12....
r4504 stream.start = stream.pos;
}
}
if (isNode)
node.innerHTML = accum.join("");
};