Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature remove chunk #596

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here? Why are all the lines changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't mean to commit that. I'm new to the whole pull requests thing so I'm making some mistakes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I'm pretty new to this as well 👻

I am genuinely confused as to why it flags all the lines as changed even though most of them are visually identical.

/nbproject/
4 changes: 4 additions & 0 deletions src/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<!-- htmlmin:remove -->[\s\S]*?<!-- htmlmin:remove -->/g, '');

var customFragments = (options.ignoreCustomFragments || [
/<%[\s\S]*?%>/,
/<\?[\s\S]*?\?>/
Expand Down
3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ testrunner.run({
code: './src/htmlminifier.js',
tests: [
'./tests/lint.js',
'./tests/minifier.js'
'./tests/minifier.js',
'./tests/remove.js'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to make sure the new tests will run in the web version as well.

],
maxBlockDuration: 5000
}, function(err, report) {
Expand Down
34 changes: 34 additions & 0 deletions tests/remove.js
Original file line number Diff line number Diff line change
@@ -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 = '<!-- htmlmin:remove --><!-- htmlmin:remove -->';
equal(minify(input), '');

input = '<!-- htmlmin:remove -->FOOBAR<!-- htmlmin:remove -->';
equal(minify(input), '');

input = '' +
'<div class="wrapper">\n' +
' <p> ignored </p>\n' +
' <!-- htmlmin:remove -->\n' +
' <div class="removed" style="color: red">\n' +
' removed <span> <input disabled/> chunk </span>\n' +
' </div>\n' +
' <!-- htmlmin:remove -->\n' +
'</div>';
output = '' +
'<div class="wrapper">\n' +
' <p> ignored </p>\n' +
// Note there's two spaces that linger before our <!-- htmlmin:remove -->
' \n' +
'</div>';

equal(minify(input), output);
});