From 30510e0147f015f747513ec79d29713e655f580f Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Mon, 13 May 2013 23:09:09 -0400 Subject: [PATCH] HTML5 as an option. --- dist/all.js | 6 ++++++ src/htmlminifier.js | 2 ++ src/htmlparser.js | 4 ++++ tests/minifier.js | 27 +++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) 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); -- 2.34.1