Merge pull request #5987 from WoltLab/acp-dahsboard-box-hight
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / addon / runmode / colorize.js
CommitLineData
44f4c339 1// CodeMirror, copyright (c) by Marijn Haverbeke and others
373d1232 2// Distributed under an MIT license: https://codemirror.net/LICENSE
44f4c339 3
837afb80
TD
4(function(mod) {
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
10 mod(CodeMirror);
11})(function(CodeMirror) {
12 "use strict";
77b7b761
TD
13
14 var isBlock = /^(p|li|div|h\\d|pre|blockquote|td)$/;
15
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) {
19 textContent(ch, out);
20 if (isBlock.test(node.nodeType)) out.push("\n");
21 }
22 }
23
837afb80 24 CodeMirror.colorize = function(collection, defaultMode) {
77b7b761
TD
25 if (!collection) collection = document.body.getElementsByTagName("pre");
26
27 for (var i = 0; i < collection.length; ++i) {
28 var node = collection[i];
29 var mode = node.getAttribute("data-lang") || defaultMode;
30 if (!mode) continue;
31
32 var text = [];
33 textContent(node, text);
34 node.innerHTML = "";
35 CodeMirror.runMode(text.join(""), mode, node);
36
37 node.className += " cm-s-default";
38 }
39 };
837afb80 40});