<input type="checkbox" id="remove-comments" checked>
<label for="remove-comments">Remove comments</label>
<span class="quiet short" style="margin-left:1.5em;float:left;clear:both;">
- Conditional comments are left intact.
+ Conditional comments are left intact, but their inner (insignificant) whitespace is removed.
</span>
</li>
<li>
Currently, only:
<code></html></code>,
<code></head></code>,
- <code></body></code>,
+ <code></body></code>,
+ <code></option></code>
<code></thead></code>,
<code></tbody></code>,
<code></tfoot></code>,
return attrValue;
}
+ function cleanConditionalComment(comment) {
+ return comment
+ .replace(/^(\[[^\]]+\]>)\s*/, '$1')
+ .replace(/\s*(<!\[endif\])$/, '$1');
+ }
+
function removeCDATASections(text) {
return text
// "/* <![CDATA[ */" or "// <![CDATA["
buffer.push(text);
},
comment: function( text ) {
- if (options.removeComments && !isConditionalComment(text)) {
- text = '';
+ if (options.removeComments) {
+ if (isConditionalComment(text)) {
+ text = '<!--' + cleanConditionalComment(text) + '-->';
+ }
+ else {
+ text = '';
+ }
}
else {
text = '<!--' + text + '-->';
});
test('conditional comments', function(){
- input = '<!--[if IE 6]> test <![endif]-->';
+ input = '<!--[if IE 6]>test<![endif]-->';
equals(minify(input, { removeComments: true }), input);
- input = '<!--[if lt IE 5.5]> test <![endif]-->';
+ input = '<!--[if lt IE 5.5]>test<![endif]-->';
equals(minify(input, { removeComments: true }), input);
- input = '<!--[if (gt IE 5)&(lt IE 7)]> test <![endif]-->';
+ input = '<!--[if (gt IE 5)&(lt IE 7)]>test<![endif]-->';
equals(minify(input, { removeComments: true }), input);
});
+ test('collapsing space in conditional comments', function(){
+ input = '<!--[if IE 7]>\n\n \t\n \t\t ' +
+ '<link rel="stylesheet" href="/css/ie7-fixes.css" type="text/css" />\n\t' +
+ '<![endif]-->';
+ output = '<!--[if IE 7]>'+
+ '<link rel="stylesheet" href="/css/ie7-fixes.css" type="text/css" />'+
+ '<![endif]-->'
+
+ equals(minify(input, { removeComments: true }), output);
+
+
+ input = '<!--[if lte IE 6]>\n \n \n\n\n\t' +
+ '<p title=" sigificant whitespace ">blah blah</p>' +
+ '<![endif]-->';
+ output = '<!--[if lte IE 6]>' +
+ '<p title=" sigificant whitespace ">blah blah</p>' +
+ '<![endif]-->';
+
+ equals(minify(input, { removeComments: true }), output);
+ });
+
test('remove comments from scripts', function(){
input = '<script><!--alert(1)--><\/script>';
output = '<script><\/script>';