From d2a8202277f05c0d0bd15f6f1ed576745952938b Mon Sep 17 00:00:00 2001 From: Micky Hulse Date: Tue, 3 Sep 2013 19:27:42 -0700 Subject: [PATCH] Ignored tags: Final tweaks before sending PR. See: kangax/html-minifier#10 --- dist/all.js | 7 ++++--- src/htmlparser.js | 7 ++++--- tests/minifier.js | 10 ++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dist/all.js b/dist/all.js index beeb700..f16f70b 100644 --- a/dist/all.js +++ b/dist/all.js @@ -83,6 +83,7 @@ else if (html.search(startIgnore) === 0) { index = html.search(endIgnore); // Find closing tag. if (index >= 0) { // Found? + // @TODO: Pass matched open/close tags back to handler. handler.ignore && handler.ignore(html.substring(0, index + 2)); // Return ignored string if callback exists. html = html.substring(index + 2); // Next starting point for parser. chars = false; // Chars flag. @@ -255,7 +256,7 @@ results += ""; }, ignore: function(text) { - // Need to test this. + results += text; } }); @@ -346,8 +347,8 @@ comment: function( /*text*/ ) { // create comment node }, - ignore: function(text) { - // Need to test this. + ignore: function( /* text */ ) { + // What to do here? } }); diff --git a/src/htmlparser.js b/src/htmlparser.js index c82564c..f4f74ae 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -83,6 +83,7 @@ else if (html.search(startIgnore) === 0) { index = html.search(endIgnore); // Find closing tag. if (index >= 0) { // Found? + // @TODO: Pass matched open/close tags back to handler. handler.ignore && handler.ignore(html.substring(0, index + 2)); // Return ignored string if callback exists. html = html.substring(index + 2); // Next starting point for parser. chars = false; // Chars flag. @@ -255,7 +256,7 @@ results += ""; }, ignore: function(text) { - // Need to test this. + results += text; } }); @@ -346,8 +347,8 @@ comment: function( /*text*/ ) { // create comment node }, - ignore: function(text) { - // Need to test this. + ignore: function( /* text */ ) { + // What to do here? } }); diff --git a/tests/minifier.js b/tests/minifier.js index 475f5b0..cdaa556 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -689,17 +689,23 @@ equal(minify(input, { html5: true }), minify(input)); }); + // https://github.com/kangax/html-minifier/issues/10 test('Ignored tags: enabled by default', function() { - // https://github.com/kangax/html-minifier/issues/10 input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start.<% ... %><%= ... %>No comment, but middle.Hello, this is the end!'; equal(minify(input, {}), input); equal(minify(input, { removeComments: true, collapseWhitespace: true }), output); - output = 'This is the start.No comment, but middle.Hello, this is the end!'; equal(minify(input, { removeComments: true, collapseWhitespace: true, removeIgnored: true }), output); + input = '<% if foo? %>\r\n
\r\n ...\r\n
\r\n<% end %>'; + output = '<% if foo? %>
...
<% end %>'; + equal(minify(input, {}), input); + equal(minify(input, { collapseWhitespace: true }), output); + output = '
...
'; + equal(minify(input, { collapseWhitespace: true, removeIgnored: true }), output); + }); })(typeof exports === 'undefined' ? window : exports); -- 2.34.1