xonecas.io
117
Ht

htmlKompressor / commit 72d3706

remove comments early, less to parse

xonecas2011-06-03 72d370613f744040d635c9b4c8bfa7a1837d484e parent 759e41a

2 files changed

lib/kompressor.js+4−4
@@ -1,5 +1,9 @@
11 // by @xonecas based on https://github.com/tylerhall/html-compressor.git
22 module.exports = function (source, noComments) {
3+ if (noComments) { // remove comments
4+ source = source.replace(/<\!--.*?--\>/g, "");
5+ }
6+
37 var lines = source.split("\n"),
48 insidePre = false, kompressed = "";
59
@@ -34,10 +38,6 @@ module.exports = function (source, noComments) {
3438 kompressed += (insidePre)? line+"\n": line;
3539 } // end while
3640
37- if (noComments) { // remove comments
38- kompressed = kompressed.replace(/<\!--.*?--\>/g, "");
39- }
40-
4141 return kompressed;
4242 }
4343
test/test.js+2−2
@@ -1,7 +1,7 @@
1-var kompressor = require("./lib/kompressor.js"),
1+var kompressor = require("../lib/kompressor.js"),
22 fs = require('fs');
33
4-fs.readFile("./index.html", "utf8", function (err, file) {
4+fs.readFile("./test/index.html", "utf8", function (err, file) {
55 if (err) throw err;
66
77 console.log(kompressor(file, true));