2 if (typeof exports
== "object" && typeof module
== "object") // CommonJS
3 mod(require("../../lib/codemirror"), require("./runmode"));
4 else if (typeof define
== "function" && define
.amd
) // AMD
5 define(["../../lib/codemirror", "./runmode"], mod
);
6 else // Plain browser env
8 })(function(CodeMirror
) {
11 var isBlock
= /^(p|li|div|h\\d|pre|blockquote|td)$/;
13 function textContent(node
, out
) {
14 if (node
.nodeType
== 3) return out
.push(node
.nodeValue
);
15 for (var ch
= node
.firstChild
; ch
; ch
= ch
.nextSibling
) {
17 if (isBlock
.test(node
.nodeType
)) out
.push("\n");
21 CodeMirror
.colorize = function(collection
, defaultMode
) {
22 if (!collection
) collection
= document
.body
.getElementsByTagName("pre");
24 for (var i
= 0; i
< collection
.length
; ++i
) {
25 var node
= collection
[i
];
26 var mode
= node
.getAttribute("data-lang") || defaultMode
;
30 textContent(node
, text
);
32 CodeMirror
.runMode(text
.join(""), mode
, node
);
34 node
.className
+= " cm-s-default";