Ignored tags: Final tweaks before sending PR.
authorMicky Hulse <mickyhulse@gmail.com>
Wed, 4 Sep 2013 02:27:42 +0000 (19:27 -0700)
committerMicky Hulse <mickyhulse@gmail.com>
Wed, 4 Sep 2013 02:27:42 +0000 (19:27 -0700)
See: kangax/html-minifier#10

dist/all.js
src/htmlparser.js
tests/minifier.js

index beeb700..f16f70b 100644 (file)
@@ -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.
         results += "<!--" + text + "-->";
       },
       ignore: function(text) {
-        // Need to test this.
+        results += text;
       }
     });
 
       comment: function( /*text*/ ) {
         // create comment node
       },
-      ignore: function(text) {
-        // Need to test this.
+      ignore: function( /* text */ ) {
+        // What to do here?
       }
     });
 
index c82564c..f4f74ae 100644 (file)
@@ -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.
         results += "<!--" + text + "-->";
       },
       ignore: function(text) {
-        // Need to test this.
+        results += text;
       }
     });
 
       comment: function( /*text*/ ) {
         // create comment node
       },
-      ignore: function(text) {
-        // Need to test this.
+      ignore: function( /* text */ ) {
+        // What to do here?
       }
     });
 
index 475f5b0..cdaa556 100644 (file)
     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<!-- This is the middle, and a comment. -->\r\nNo comment, but middle.\r\n<?= ... ?>\r\n<?php ... ?>\r\n<?xml ... ?>\r\nHello, this is the end!';
     output = 'This is the start.<% ... %><%= ... %><? ... ?>No comment, but middle.<?= ... ?><?php ... ?><?xml ... ?>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  <div class="bar">\r\n    ...\r\n  </div>\r\n<% end %>';
+    output = '<% if foo? %><div class="bar">...</div><% end %>';
+    equal(minify(input, {}), input);
+    equal(minify(input, { collapseWhitespace: true }), output);
+    output = '<div class="bar">...</div>';
+    equal(minify(input, { collapseWhitespace: true, removeIgnored: true }), output);
+    
   });
 
 })(typeof exports === 'undefined' ? window : exports);