From 70e672448a7df62fcfef8516dc6dd52d161fcfa1 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Thu, 11 Mar 2010 12:06:41 -0500 Subject: [PATCH] Minifier now removes insignificant whitespace in conditional comments. --- index.html | 5 +++-- src/htmlminifier.js | 15 +++++++++++++-- tests/index.html | 27 ++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 76f8fe8..f6c7c86 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,7 @@ - Conditional comments are left intact. + Conditional comments are left intact, but their inner (insignificant) whitespace is removed.
  • @@ -98,7 +98,8 @@ Currently, only: </html>, </head>, - </body>, + </body>, + </option> </thead>, </tbody>, </tfoot>, diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 2092add..dcf730d 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -95,6 +95,12 @@ return attrValue; } + function cleanConditionalComment(comment) { + return comment + .replace(/^(\[[^\]]+\]>)\s*/, '$1') + .replace(/\s*('; + } + else { + text = ''; + } } else { text = ''; diff --git a/tests/index.html b/tests/index.html index b329e2f..1a195f7 100644 --- a/tests/index.html +++ b/tests/index.html @@ -104,16 +104,37 @@ }); test('conditional comments', function(){ - input = ''; + input = ''; equals(minify(input, { removeComments: true }), input); - input = ''; + input = ''; equals(minify(input, { removeComments: true }), input); - input = ''; + input = ''; equals(minify(input, { removeComments: true }), input); }); + test('collapsing space in conditional comments', function(){ + input = ''; + output = '' + + equals(minify(input, { removeComments: true }), output); + + + input = ''; + output = ''; + + equals(minify(input, { removeComments: true }), output); + }); + test('remove comments from scripts', function(){ input = '