]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/jsonminify/report/assets/scripts/vendor/codemirror/util/runmode.js
Remove mc config
[rbdr/dotfiles] / atom / packages / pretty-json / node_modules / jsonminify / report / assets / scripts / vendor / codemirror / util / runmode.js
1 CodeMirror.runMode = function(string, modespec, callback, options) {
2 var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
3
4 if (callback.nodeType == 1) {
5 var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
6 var node = callback, col = 0;
7 node.innerHTML = "";
8 callback = function(text, style) {
9 if (text == "\n") {
10 node.appendChild(document.createElement("br"));
11 col = 0;
12 return;
13 }
14 var content = "";
15 // replace tabs
16 for (var pos = 0;;) {
17 var idx = text.indexOf("\t", pos);
18 if (idx == -1) {
19 content += text.slice(pos);
20 col += text.length - pos;
21 break;
22 } else {
23 col += idx - pos;
24 content += text.slice(pos, idx);
25 var size = tabSize - col % tabSize;
26 col += size;
27 for (var i = 0; i < size; ++i) content += " ";
28 pos = idx + 1;
29 }
30 }
31
32 if (style) {
33 var sp = node.appendChild(document.createElement("span"));
34 sp.className = "cm-" + style.replace(/ +/g, " cm-");
35 sp.appendChild(document.createTextNode(content));
36 } else {
37 node.appendChild(document.createTextNode(content));
38 }
39 };
40 }
41
42 var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
43 for (var i = 0, e = lines.length; i < e; ++i) {
44 if (i) callback("\n");
45 var stream = new CodeMirror.StringStream(lines[i]);
46 while (!stream.eol()) {
47 var style = mode.token(stream, state);
48 callback(stream.current(), style, i, stream.start);
49 stream.start = stream.pos;
50 }
51 }
52 };