From 93d4f7e23f91ebd072b5dd2889cd9f784139d4f5 Mon Sep 17 00:00:00 2001 From: Jonathan Ginn Date: Mon, 28 Mar 2016 07:17:08 -0400 Subject: [PATCH 1/2] added htmlmin:remove comment chunks with passing tests --- .gitignore | 17 +++++++++-------- src/htmlminifier.js | 4 ++++ test.js | 3 ++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 5a30657a..cacee493 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ -*.sublime-project -*.sublime-workspace -.DS_Store -/.jekyll-metadata -/_site/ -/benchmarks/generated -/node_modules/ -/npm-debug.log +*.sublime-project +*.sublime-workspace +.DS_Store +/.jekyll-metadata +/_site/ +/benchmarks/generated +/node_modules/ +/npm-debug.log +/nbproject/ diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 2d51044d..2afa7506 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -703,6 +703,10 @@ function minify(value, options, partialMarkup) { return token; }); + // Remove specific comment chunks. Usefull to delete markup that isn't wanted + // in dist(ex: browsersync or livereload) + value = value.replace(/[\s\S]*?/g, ''); + var customFragments = (options.ignoreCustomFragments || [ /<%[\s\S]*?%>/, /<\?[\s\S]*?\?>/ diff --git a/test.js b/test.js index e7d5e52c..a64e2aa2 100644 --- a/test.js +++ b/test.js @@ -11,7 +11,8 @@ testrunner.run({ code: './src/htmlminifier.js', tests: [ './tests/lint.js', - './tests/minifier.js' + './tests/minifier.js', + './tests/remove.js' ], maxBlockDuration: 5000 }, function(err, report) { From 9be8bc9697a25f79c888d1c05ba1f7d35136696b Mon Sep 17 00:00:00 2001 From: Jonathan Ginn Date: Mon, 28 Mar 2016 07:18:36 -0400 Subject: [PATCH 2/2] added test file --- tests/remove.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/remove.js diff --git a/tests/remove.js b/tests/remove.js new file mode 100644 index 00000000..d58e500d --- /dev/null +++ b/tests/remove.js @@ -0,0 +1,34 @@ +/* global minify */ +'use strict'; + +if (typeof minify === 'undefined') { + self.minify = require('html-minifier').minify; +} + +var input, output; + +test('removing comment chunks', function () { + input = ''; + equal(minify(input), ''); + + input = 'FOOBAR'; + equal(minify(input), ''); + + input = '' + + '
\n' + + '

ignored

\n' + + ' \n' + + '
\n' + + ' removed chunk \n' + + '
\n' + + ' \n' + + '
'; + output = '' + + '
\n' + + '

ignored

\n' + + // Note there's two spaces that linger before our + ' \n' + + '
'; + + equal(minify(input), output); +});