-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed to using CodeMirror.runMode for better performance
- Loading branch information
1 parent
bb3801b
commit 151c271
Showing
5 changed files
with
102 additions
and
59 deletions.
There are no files selected for viewing
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("<br>"); | ||
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>"); | ||
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(""); | ||
}; |