3be5411506ed84815025ee0a4b7efa83764ee199
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: https://codemirror.net/LICENSE
5 if (typeof exports
== "object" && typeof module
== "object") // CommonJS
6 mod(require("../../lib/codemirror"), require("./runmode"));
7 else if (typeof define
== "function" && define
.amd
) // AMD
8 define(["../../lib/codemirror", "./runmode"], mod
);
9 else // Plain browser env
11 })(function(CodeMirror
) {
14 var isBlock
= /^(p|li|div|h\\d|pre|blockquote|td)$/;
16 function textContent(node
, out
) {
17 if (node
.nodeType
== 3) return out
.push(node
.nodeValue
);
18 for (var ch
= node
.firstChild
; ch
; ch
= ch
.nextSibling
) {
20 if (isBlock
.test(node
.nodeType
)) out
.push("\n");
24 CodeMirror
.colorize = function(collection
, defaultMode
) {
25 if (!collection
) collection
= document
.body
.getElementsByTagName("pre");
27 for (var i
= 0; i
< collection
.length
; ++i
) {
28 var node
= collection
[i
];
29 var mode
= node
.getAttribute("data-lang") || defaultMode
;
33 textContent(node
, text
);
35 CodeMirror
.runMode(text
.join(""), mode
, node
);
37 node
.className
+= " cm-s-default";