Skip to content

Commit

Permalink
Add TR to the list of optional end tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
kangax committed Mar 4, 2010
1 parent 21aa0ec commit 515f57c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 9 additions & 1 deletion index.html
Expand Up @@ -100,7 +100,15 @@ <h1>HTML Minifier <span style="font-size:0.6em">(ver. 0.3)</span></h1>
Remove optional tags
<br>
<span class="quiet short">
Currently, only <code>&lt;/html></code>, <code>&lt;/head></code>, and <code>&lt;/body></code>
Currently, only:
<code>&lt;/html></code>,
<code>&lt;/head></code>,
<code>&lt;/body></code>,
<code>&lt;/thead></code>,
<code>&lt;/tbody></code>,
<code>&lt;/tfoot></code>,
and
<code>&lt;/tr></code>
</span>
</label>
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/htmlminifier.js
Expand Up @@ -126,7 +126,7 @@
}

function isOptionalTag(tag) {
return (/^(?:html|t?body|t?head|tfoot)$/).test(tag);
return (/^(?:html|t?body|t?head|tfoot|tr)$/).test(tag);
}

function canCollapseWhitespace(tag) {
Expand Down
19 changes: 16 additions & 3 deletions tests/index.html
Expand Up @@ -353,9 +353,22 @@ <h2 id="qunit-userAgent"></h2>
output = '<html><head><title>hello</title><body><p>foo<span>bar</span></p>';
equals(minify(input, { removeOptionalTags: true }), output);
equals(minify(input), input);

input = '<table><thead><tr></tr></thead><tfoot><tr></tr></tfoot><tbody><tr></tr></tbody></table>';
output = '<table><thead><tr></tr><tfoot><tr></tr><tbody><tr></tr></table>';
});

test('removing optional tags in tables', function(){

input = '<table>'+
'<thead><tr><th>foo</th><th>bar</th></tr></thead>'+
'<tfoot><tr><th>baz</th><th>qux</th></tr></tfoot>'+
'<tbody><tr><td>boo</td><td>moo</td></tr></tbody>'+
'</table>';

output = '<table>'+
'<thead><tr><th>foo</th><th>bar</th>'+
'<tfoot><tr><th>baz</th><th>qux</th>'+
'<tbody><tr><td>boo</td><td>moo</td>'+
'</table>';

equals(minify(input, { removeOptionalTags: true }), output);
equals(minify(input), input);
});
Expand Down

0 comments on commit 515f57c

Please sign in to comment.