if (isDeprecatedElement(tag)) {
this.log.push(
'<li>Found <span class="deprecated-element">deprecated</span> <strong><code><' +
- tag + '></code></strong> element</li>');
+ tag + '></code></strong> element</li>'
+ );
}
else if (isPresentationalElement(tag)) {
this.log.push(
'<li>Found <span class="presentational-element">presentational</span> <strong><code><' +
- tag + '></code></strong> element</li>');
+ tag + '></code></strong> element</li>'
+ );
}
else {
this.checkRepeatingElement(tag);
if (isEventAttribute(attrName)) {
this.log.push(
'<li>Found <span class="event-attribute">event attribute</span> (<strong>',
- attrName, '</strong>) on <strong><code><' + tag + '></code></strong> element</li>');
+ attrName, '</strong>) on <strong><code><' + tag + '></code></strong> element</li>'
+ );
}
else if (isDeprecatedAttribute(tag, attrName)) {
this.log.push(
'<li>Found <span class="deprecated-attribute">deprecated</span> <strong>' +
- attrName + '</strong> attribute on <strong><code><', tag, '></code></strong> element</li>');
+ attrName + '</strong> attribute on <strong><code><', tag, '></code></strong> element</li>'
+ );
}
else if (isStyleAttribute(attrName)) {
this.log.push(
- '<li>Found <span class="style-attribute">style attribute</span> on <strong><code><', tag, '></code></strong> element</li>');
+ '<li>Found <span class="style-attribute">style attribute</span> on <strong><code><', tag, '></code></strong> element</li>'
+ );
}
else if (isInaccessibleAttribute(attrName, attrValue)) {
this.log.push(
- '<li>Found <span class="inaccessible-attribute">inaccessible attribute</span> '+
- '(on <strong><code><', tag, '></code></strong> element)</li>');
+ '<li>Found <span class="inaccessible-attribute">inaccessible attribute</span> ' +
+ '(on <strong><code><', tag, '></code></strong> element)</li>'
+ );
}
};
if ( match ) {
html = html.substring( match[0].length );
match[0].replace( endTag, parseEndTag );
- prevTag = '/'+match[1];
+ prevTag = '/' + match[1];
chars = false;
}
// Start tag:
- } else if ( html.indexOf('<') === 0 ) {
+ }
+ else if ( html.indexOf('<') === 0 ) {
match = html.match( startTag );
if ( match ) {
tagMatch = html.match( startTag );
if (tagMatch) {
nextTag = tagMatch[1];
- } else {
+ }
+ else {
tagMatch = html.match( endTag );
if (tagMatch) {
- nextTag = '/'+tagMatch[1];
- } else {
+ nextTag = '/' + tagMatch[1];
+ }
+ else {
nextTag = '';
}
}
}
- } else {
+ }
+ else {
stackedTag = stack.last().toLowerCase();
reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)<\/' + stackedTag + '[^>]*>', 'i'));
if ( !unary ) {
stack.push( tagName );
- } else {
+ }
+ else {
unarySlash = tag.match( endingSlash );
}
// If no tag name is provided, clean shop
if ( !tagName ) {
pos = 0;
- } else { // Find the closest opened tag of the same type
+ }
+ else { // Find the closest opened tag of the same type
for ( pos = stack.length - 1; pos >= 0; pos-- ) {
if ( stack[ pos ] === tagName ) {
break;
if ( !doc ) {
if ( typeof DOMDocument !== 'undefined' ) {
doc = new DOMDocument();
- } else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) {
+ }
+ else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) {
doc = document.implementation.createDocument('', '', null);
- } else if ( typeof ActiveX !== 'undefined' ) {
+ }
+ else if ( typeof ActiveX !== 'undefined' ) {
doc = new ActiveXObject('Msxml.DOMDocument');
}
- } else {
+ }
+ else {
doc = doc.ownerDocument ||
doc.getOwnerDocument && doc.getOwnerDocument() ||
doc;
if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) {
one[ structure[ tagName ] ].appendChild( elem );
- } else if ( curParentNode && curParentNode.appendChild ) {
+ }
+ else if ( curParentNode && curParentNode.appendChild ) {
curParentNode.appendChild( elem );
}
equal(minify('<p foo-bar=baz>xxx</p>'), '<p foo-bar="baz">xxx</p>');
equal(minify('<p foo:bar=baz>xxx</p>'), '<p foo:bar="baz">xxx</p>');
- input = '<div><div><div><div><div><div><div><div><div><div>'+
- 'i\'m 10 levels deep'+
+ input = '<div><div><div><div><div><div><div><div><div><div>' +
+ 'i\'m 10 levels deep' +
'</div></div></div></div></div></div></div></div></div></div>';
equal(minify(input), input);
equal(minify('<a href="#"><p>Click me</p></a>'), '<a href="#"><p>Click me</p></a>');
equal(minify('<span><button>Hit me</button></span>'), '<span><button>Hit me</button></span>');
equal(minify('<object type="image/svg+xml" data="image.svg"><div>[fallback image]</div></object>'),
- '<object type="image/svg+xml" data="image.svg"><div>[fallback image]</div></object>');
+ '<object type="image/svg+xml" data="image.svg"><div>[fallback image]</div></object>'
+ );
equal(minify('<ng-include src="x"></ng-include>'), '<ng-include src="x"></ng-include>');
equal(minify('<ng:include src="x"></ng:include>'), '<ng:include src="x"></ng:include>');
equal(minify('<ng-include src="\'views/partial-notification.html\'"></ng-include><div ng-view></div>'),
- '<ng-include src="\'views/partial-notification.html\'"></ng-include><div ng-view=""></div>');
+ '<ng-include src="\'views/partial-notification.html\'"></ng-include><div ng-view=""></div>'
+ );
// https://github.com/kangax/html-minifier/issues/41
equal(minify('<some-tag-1></some-tag-1><some-tag-2></some-tag-2>'),
- '<some-tag-1></some-tag-1><some-tag-2></some-tag-2>');
+ '<some-tag-1></some-tag-1><some-tag-2></some-tag-2>'
+ );
// https://github.com/kangax/html-minifier/issues/40
equal(minify('[\']["]'), '[\']["]');
equal(minify(' <p>blah</p>\n\n\n '), '<p>blah</p>');
// tags from collapseWhitespaceSmart()
['a', 'b', 'big', 'button', 'code', 'em', 'font', 'i', 'kbd', 'mark', 'q', 's', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u'].forEach(function(el){
- equal(minify('<p>foo <'+el+'>baz</'+el+'> bar</p>', {collapseWhitespace: true}), '<p>foo <'+el+'>baz</'+el+'> bar</p>');
- equal(minify('<p>foo<'+el+'>baz</'+el+'>bar</p>', {collapseWhitespace: true}), '<p>foo<'+el+'>baz</'+el+'>bar</p>');
- equal(minify('<p>foo <'+el+'>baz</'+el+'>bar</p>', {collapseWhitespace: true}), '<p>foo <'+el+'>baz</'+el+'>bar</p>');
- equal(minify('<p>foo<'+el+'>baz</'+el+'> bar</p>', {collapseWhitespace: true}), '<p>foo<'+el+'>baz</'+el+'> bar</p>');
- equal(minify('<p>foo <'+el+'> baz </'+el+'> bar</p>', {collapseWhitespace: true}), '<p>foo <'+el+'>baz</'+el+'> bar</p>');
- equal(minify('<p>foo<'+el+'> baz </'+el+'>bar</p>', {collapseWhitespace: true}), '<p>foo<'+el+'>baz</'+el+'>bar</p>');
- equal(minify('<p>foo <'+el+'> baz </'+el+'>bar</p>', {collapseWhitespace: true}), '<p>foo <'+el+'>baz</'+el+'>bar</p>');
- equal(minify('<p>foo<'+el+'> baz </'+el+'> bar</p>', {collapseWhitespace: true}), '<p>foo<'+el+'>baz</'+el+'> bar</p>');
+ equal(minify('<p>foo <' + el + '>baz</' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '> bar</p>');
+ equal(minify('<p>foo<' + el + '>baz</' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '>bar</p>');
+ equal(minify('<p>foo <' + el + '>baz</' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '>bar</p>');
+ equal(minify('<p>foo<' + el + '>baz</' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '> bar</p>');
+ equal(minify('<p>foo <' + el + '> baz </' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '> bar</p>');
+ equal(minify('<p>foo<' + el + '> baz </' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '>bar</p>');
+ equal(minify('<p>foo <' + el + '> baz </' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '>bar</p>');
+ equal(minify('<p>foo<' + el + '> baz </' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '> bar</p>');
});
- equal(minify('<p>foo <img> bar</p>', {collapseWhitespace: true}), '<p>foo <img> bar</p>');
- equal(minify('<p>foo<img>bar</p>', {collapseWhitespace: true}), '<p>foo<img>bar</p>');
- equal(minify('<p>foo <img>bar</p>', {collapseWhitespace: true}), '<p>foo <img>bar</p>');
- equal(minify('<p>foo<img> bar</p>', {collapseWhitespace: true}), '<p>foo<img> bar</p>');
+ equal(minify('<p>foo <img> bar</p>', { collapseWhitespace: true }), '<p>foo <img> bar</p>');
+ equal(minify('<p>foo<img>bar</p>', { collapseWhitespace: true }), '<p>foo<img>bar</p>');
+ equal(minify('<p>foo <img>bar</p>', { collapseWhitespace: true }), '<p>foo <img>bar</p>');
+ equal(minify('<p>foo<img> bar</p>', { collapseWhitespace: true }), '<p>foo<img> bar</p>');
});
test('doctype normalization', 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" />'+
+ output = '<!--[if IE 7]>' +
+ '<link rel="stylesheet" href="/css/ie7-fixes.css" type="text/css" />' +
'<![endif]-->';
equal(minify(input, { removeComments: true }), output);
input = '<p id="" class="" STYLE=" " title="\n" lang="" dir="">x</p>';
equal(minify(input, { removeEmptyAttributes: true }), '<p>x</p>');
- input = '<p onclick="" ondblclick=" " onmousedown="" ONMOUSEUP="" onmouseover=" " onmousemove="" onmouseout="" '+
+ input = '<p onclick="" ondblclick=" " onmousedown="" ONMOUSEUP="" onmouseover=" " onmousemove="" onmouseout="" ' +
'onkeypress=\n\n "\n " onkeydown=\n"" onkeyup\n="">x</p>';
equal(minify(input, { removeEmptyAttributes: true }), '<p>x</p>');
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>'+
+ 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>bar'+
- '<tfoot><tr><th>baz<th>qux'+
- '<tbody><tr><td>boo<td>moo'+
+ output = '<table>' +
+ '<thead><tr><th>foo<th>bar' +
+ '<tfoot><tr><th>baz<th>qux' +
+ '<tbody><tr><td>boo<td>moo' +
'</table>';
equal(minify(input, { removeOptionalTags: true }), output);
// example from htmldog.com
input = '<select name="catsndogs">' +
- '<optgroup label="Cats">'+
- '<option>Tiger</option><option>Leopard</option><option>Lynx</option>'+
+ '<optgroup label="Cats">' +
+ '<option>Tiger</option><option>Leopard</option><option>Lynx</option>' +
'</optgroup>' +
- '<optgroup label="Dogs">'+
- '<option>Grey Wolf</option><option>Red Fox</option><option>Fennec</option>'+
+ '<optgroup label="Dogs">' +
+ '<option>Grey Wolf</option><option>Red Fox</option><option>Fennec</option>' +
'</optgroup>' +
'</select>';
output = '<select name="catsndogs">' +
- '<optgroup label="Cats">'+
- '<option>Tiger<option>Leopard<option>Lynx'+
+ '<optgroup label="Cats">' +
+ '<option>Tiger<option>Leopard<option>Lynx' +
'</optgroup>' +
- '<optgroup label="Dogs">'+
- '<option>Grey Wolf<option>Red Fox<option>Fennec'+
+ '<optgroup label="Dogs">' +
+ '<option>Grey Wolf<option>Red Fox<option>Fennec' +
'</optgroup>' +
'</select>';
test('source', function() {
- input = '<audio controls="controls">'+
- '<source src="foo.wav">'+
- '<source src="far.wav">'+
- '<source src="foobar.wav">'+
+ input = '<audio controls="controls">' +
+ '<source src="foo.wav">' +
+ '<source src="far.wav">' +
+ '<source src="foobar.wav">' +
'</audio>';
- output = '<audio controls="controls">'+
- '<source src="foo.wav">'+
- '<source src="far.wav">'+
- '<source src="foobar.wav">'+
+ output = '<audio controls="controls">' +
+ '<source src="foo.wav">' +
+ '<source src="far.wav">' +
+ '<source src="foobar.wav">' +
'</audio>';
equal(minify(input, { removeOptionalTags: true }), output);