]>
git.r.bdr.sh - rbdr/dotfiles/blob - 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
);
4 if (callback
.nodeType
== 1) {
5 var tabSize
= (options
&& options
.tabSize
) || CodeMirror
.defaults
.tabSize
;
6 var node
= callback
, col
= 0;
8 callback = function(text
, style
) {
10 node
.appendChild(document
.createElement("br"));
17 var idx
= text
.indexOf("\t", pos
);
19 content
+= text
.slice(pos
);
20 col
+= text
.length
- pos
;
24 content
+= text
.slice(pos
, idx
);
25 var size
= tabSize
- col
% tabSize
;
27 for (var i
= 0; i
< size
; ++i
) content
+= " ";
33 var sp
= node
.appendChild(document
.createElement("span"));
34 sp
.className
= "cm-" + style
.replace(/ +/g
, " cm-");
35 sp
.appendChild(document
.createTextNode(content
));
37 node
.appendChild(document
.createTextNode(content
));
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
;