5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.runMode = function(string, modespec, callback, options) {
15
var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
16
var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
19
if (callback.appendChild) {
20
var ie = /MSIE \d/.test(navigator.userAgent);
21
var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);
22
var node = callback, col = 0;
24
callback = function(text, style) {
28
node.appendChild(document.createTextNode(ie_lt9 ? '\r' : text));
35
var idx = text.indexOf("\t", pos);
37
content += text.slice(pos);
38
col += text.length - pos;
42
content += text.slice(pos, idx);
43
var size = tabSize - col % tabSize;
45
for (var i = 0; i < size; ++i) content += " ";
51
var sp = node.appendChild(document.createElement("span"));
52
sp.className = "cm-" + style.replace(/ +/g, " cm-");
53
sp.appendChild(document.createTextNode(content));
55
node.appendChild(document.createTextNode(content));
60
var lines = CodeMirror.splitLines(string), state = (options && options.state) || CodeMirror.startState(mode);
61
for (var i = 0, e = lines.length; i < e; ++i) {
62
if (i) callback("\n");
63
var stream = new CodeMirror.StringStream(lines[i], null, {
64
lookAhead: function(n) { return lines[i + n] },
65
baseToken: function() {}
67
if (!stream.string && mode.blankLine) mode.blankLine(state);
68
while (!stream.eol()) {
69
var style = mode.token(stream, state);
70
callback(stream.current(), style, i, stream.start, state, mode);
71
stream.start = stream.pos;