From 388d307cdd1059684e5cccf32574cf9c340cb1ac Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Tue, 9 Mar 2010 21:04:15 -0500 Subject: [PATCH] =?utf8?q?Add=20README.md;=20Add=20=20to=20tags?= =?utf8?q?=20allowed=20for=20deletion=20(thanks=20Jakub=20Vr=C3=A1na).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ src/htmlminifier.js | 4 ++-- tests/index.html | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d0b7e98 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +[HTMLMinifier](http://kangax.github.com/html-minifier/) is a Javascript-based HTML minifier (duh), with lint-like capabilities. + +See [corresponding blog post](http://perfectionkills.com/experimenting-with-html-minifier/) for all the gory details of [how it works](http://perfectionkills.com/experimenting-with-html-minifier/#how_it_works), [description of each option](http://perfectionkills.com/experimenting-with-html-minifier/#options), [testing results](http://perfectionkills.com/experimenting-with-html-minifier/#field_testing) and [conclusions](http://perfectionkills.com/experimenting-with-html-minifier/#cost_and_benefits). \ No newline at end of file diff --git a/src/htmlminifier.js b/src/htmlminifier.js index bc3db26..dd7a9c9 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -117,7 +117,7 @@ } function isOptionalTag(tag) { - return (/^(?:html|t?body|t?head|tfoot|tr)$/).test(tag); + return (/^(?:html|t?body|t?head|tfoot|tr|option)$/).test(tag); } var reEmptyAttribute = new RegExp( @@ -208,7 +208,6 @@ buffer.push('>'); }, end: function( tag ) { - var isElementEmpty = currentChars === '' && tag === currentTag; if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag))) { // remove last "element" from buffer, return @@ -217,6 +216,7 @@ } else if (options.removeOptionalTags && isOptionalTag(tag)) { // noop, leave start tag in buffer + return; } else { // push end tag to buffer diff --git a/tests/index.html b/tests/index.html index c0f8e37..817283e 100644 --- a/tests/index.html +++ b/tests/index.html @@ -390,6 +390,12 @@ equals(minify(input), input); }); + test('removing optional tags in options', function(){ + input = ''; + output = ''; + equals(minify(input, { removeOptionalTags: true }), output); + }); + })(this); -- 2.34.1