HTML5 as an option.
authorStephen Sawchuk <sawchuk@gmail.com>
Tue, 14 May 2013 03:09:09 +0000 (23:09 -0400)
committerStephen Sawchuk <sawchuk@gmail.com>
Tue, 14 May 2013 03:14:11 +0000 (23:14 -0400)
dist/all.js
src/htmlminifier.js
src/htmlparser.js
tests/minifier.js

index 40cbd21..aa7f3ad 100644 (file)
 
     function parseStartTag( tag, tagName, rest, unary ) {
 
+      while ( !handler.html5 && stack.last() && inline[ stack.last() ]) {
+        parseEndTag( "", stack.last() );
+      }
+
       if ( closeSelf[ tagName ] && stack.last() == tagName ) {
         parseEndTag( "", tagName );
       }
     }
 
     HTMLParser(value, {
+      html5: typeof options.html5 !== 'undefined' ? options.html5 : true,
+
       start: function( tag, attrs ) {
         tag = tag.toLowerCase();
         currentTag = tag;
index 7f8cfd4..457e3a3 100644 (file)
     }
 
     HTMLParser(value, {
+      html5: typeof options.html5 !== 'undefined' ? options.html5 : true,
+
       start: function( tag, attrs ) {
         tag = tag.toLowerCase();
         currentTag = tag;
index d64c07e..cbcd7f6 100644 (file)
 
     function parseStartTag( tag, tagName, rest, unary ) {
 
+      while ( !handler.html5 && stack.last() && inline[ stack.last() ]) {
+        parseEndTag( "", stack.last() );
+      }
+
       if ( closeSelf[ tagName ] && stack.last() == tagName ) {
         parseEndTag( "", tagName );
       }
index ca843f2..c950245 100644 (file)
     equal(minify(input, { removeOptionalTags: true }), output);
   });
 
+ test('custom components', function(){
+    input = '<custom-component>Oh, my.</custom-component>';
+    output = '<custom-component>Oh, my.</custom-component>';
+
+    equal(minify(input), output);
+  });
+
+  test('HTML4: anchor with block elements', function(){
+    input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
+    output = '<a href="#"></a><div>Well, look at me! I\'m a div!</div>';
+
+    equal(minify(input, { html5: false }), output);
+  });
+
+  test('HTML5: anchor with block elements', function(){
+    input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
+    output = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
+
+    equal(minify(input, { html5: true }), output);
+  });
+
+  test('HTML5: enabled by default', function(){
+    input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
+
+    equal(minify(input, { html5: true }), minify(input));
+  });
+
 })(typeof exports === 'undefined' ? window : exports);