☕️ Classic, reliable, trusted test framework for Node.js and the browser
move highlight code to utils.js
TJ Holowaychuk34f8ed6f79d0
diff --git a/lib/utils.js b/lib/utils.jsindex 2dbb53b4..2563adea 100644--- a/lib/utils.js+++ b/lib/utils.js@@ -229,4 +229,38 @@ exports.escapeRegexp = function(str){exports.trim = function(str){return str.replace(/^\s+|\s+$/g, '');+};++/**+ * Highlight the given string of `js`.+ *+ * @param {String} js+ * @return {String}+ * @api private+ */++function highlight(js) {+ return js+ .replace(/</g, '<')+ .replace(/>/g, '>')+ .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')+ .replace(/('.*?')/gm, '<span class="string">$1</span>')+ .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')+ .replace(/(\d+)/gm, '<span class="number">$1</span>')+ .replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')+ .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')+}++/**+ * Highlight the contents of tag `name`.+ *+ * @param {String} name+ * @api private+ */++exports.highlightTags = function(name) {+ var code = document.getElementsByTagName(name);+ for (var i = 0, len = code.length; i < len; ++i) {+ code[i].innerHTML = highlight(code[i].innerHTML);+ }};\ No newline at end of filediff --git a/support/tail.js b/support/tail.jsindex d6c5e5cd..842e92e6 100644--- a/support/tail.js+++ b/support/tail.js@@ -70,33 +70,6 @@ process.on = function(e, fn){var Mocha = window.Mocha = require('mocha'),mocha = window.mocha = new Mocha({ reporter: 'html' });- /**- * Highlight the given string of `js`.- */-- function highlight(js) {- return js- .replace(/</g, '<')- .replace(/>/g, '>')- .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')- .replace(/('.*?')/gm, '<span class="string">$1</span>')- .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')- .replace(/(\d+)/gm, '<span class="number">$1</span>')- .replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')- .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')- }-- /**- * Highlight code contents.- */-- function highlightCode() {- var code = document.getElementsByTagName('code');- for (var i = 0, len = code.length; i < len; ++i) {- code[i].innerHTML = highlight(code[i].innerHTML);- }- }-/*** Parse the given `qs`.*/@@ -146,7 +119,7 @@ process.on = function(e, fn){if (query.grep) this.grep(query.grep);return Mocha.prototype.run.call(this, function () {- highlightCode();+ Mocha.utils.highlightTags('code');if (fn) fn();});};