Added isIgnoredComment()
authorMicky Hulse <mickyhulse@gmail.com>
Thu, 15 Aug 2013 05:06:01 +0000 (22:06 -0700)
committerMicky Hulse <mickyhulse@gmail.com>
Thu, 15 Aug 2013 05:06:01 +0000 (22:06 -0700)
Patch for issue #70.

dist/all.js
src/htmlminifier.js

index 4268f53..c702659 100644 (file)
 
   function collapseWhitespaceSmart(str, prevTag, nextTag) {
     // array of tags that will maintain a single space outside of them
-    var tags = ['a', 'b', 'big', 'button', 'code', 'em', 'font', 'i', 'kbd', 'mark', 'q', 's', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'tt', 'u'];
+    var tags = ['a', 'abbr', 'acronym', 'b', 'big', 'button', 'code', 'del', 'dfn', 'em', 'font', 'i', 'ins', 'kbd', 'mark', 'q', 's', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'tt', 'u', 'var'];
 
     if (prevTag && prevTag !== 'img' && (prevTag.substr(0,1) !== '/'
       || ( prevTag.substr(0,1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) {
     return ((/\[if[^\]]+\]/).test(text) || (/\s*(<!\[endif\])$/).test(text));
   }
 
+  function isIgnoredComment(text) {
+    return (/^!/).test(text);
+  }
+
   function isEventAttribute(attrName) {
     return (/^on[a-z]+/).test(attrName);
   }
         if (options.removeComments) {
           if (isConditionalComment(text)) {
             text = '<!--' + cleanConditionalComment(text) + '-->';
+          } else if (isIgnoredComment(text)) {
+            text = '<!--' + text + '-->';
           }
           else {
             text = '';
index b4bced9..bf38f30 100644 (file)
     return ((/\[if[^\]]+\]/).test(text) || (/\s*(<!\[endif\])$/).test(text));
   }
 
+  function isIgnoredComment(text) {
+    return (/^!/).test(text);
+  }
+
   function isEventAttribute(attrName) {
     return (/^on[a-z]+/).test(attrName);
   }
         if (options.removeComments) {
           if (isConditionalComment(text)) {
             text = '<!--' + cleanConditionalComment(text) + '-->';
+          } else if (isIgnoredComment(text)) {
+            text = '<!--' + text + '-->';
           }
           else {
             text = '';