From: Stephen Sawchuk Date: Tue, 14 May 2013 03:09:09 +0000 (-0400) Subject: HTML5 as an option. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=30510e0147f015f747513ec79d29713e655f580f;p=html-minifier.git HTML5 as an option. --- diff --git a/dist/all.js b/dist/all.js index 40cbd21..aa7f3ad 100644 --- a/dist/all.js +++ b/dist/all.js @@ -160,6 +160,10 @@ 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 ); } @@ -651,6 +655,8 @@ } HTMLParser(value, { + html5: typeof options.html5 !== 'undefined' ? options.html5 : true, + start: function( tag, attrs ) { tag = tag.toLowerCase(); currentTag = tag; diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 7f8cfd4..457e3a3 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -313,6 +313,8 @@ } HTMLParser(value, { + html5: typeof options.html5 !== 'undefined' ? options.html5 : true, + start: function( tag, attrs ) { tag = tag.toLowerCase(); currentTag = tag; diff --git a/src/htmlparser.js b/src/htmlparser.js index d64c07e..cbcd7f6 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -160,6 +160,10 @@ 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 ); } diff --git a/tests/minifier.js b/tests/minifier.js index ca843f2..c950245 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -584,4 +584,31 @@ equal(minify(input, { removeOptionalTags: true }), output); }); + test('custom components', function(){ + input = 'Oh, my.'; + output = 'Oh, my.'; + + equal(minify(input), output); + }); + + test('HTML4: anchor with block elements', function(){ + input = '
Well, look at me! I\'m a div!
'; + output = '
Well, look at me! I\'m a div!
'; + + equal(minify(input, { html5: false }), output); + }); + + test('HTML5: anchor with block elements', function(){ + input = '
Well, look at me! I\'m a div!
'; + output = '
Well, look at me! I\'m a div!
'; + + equal(minify(input, { html5: true }), output); + }); + + test('HTML5: enabled by default', function(){ + input = '
Well, look at me! I\'m a div!
'; + + equal(minify(input, { html5: true }), minify(input)); + }); + })(typeof exports === 'undefined' ? window : exports);