| `quoteCharacter` | Type of quote to use for attribute values (' or ") | |
| `removeAttributeQuotes` | [Remove quotes around attributes when possible](http://perfectionkills.com/experimenting-with-html-minifier/#remove_attribute_quotes) | `false` |
| `removeComments` | [Strip HTML comments](http://perfectionkills.com/experimenting-with-html-minifier/#remove_comments) | `false` |
-| `removeEmptyAttributes` | [Remove all attributes with whitespace-only values](http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes) | `false` |
+| `removeEmptyAttributes` | [Remove all attributes with whitespace-only values](http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes) | `false` (could be true, Function(attrName, tag)) |
| `removeEmptyElements` | [Remove all elements with empty contents](http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_elements) | `false` |
| `removeOptionalTags` | [Remove optional tags](http://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags) | `false` |
| `removeRedundantAttributes` | [Remove attributes when value matches default.](http://perfectionkills.com/experimenting-with-html-minifier/#remove_redundant_attributes) | `false` |
'^(?:class|id|style|title|lang|dir|on(?:focus|blur|change|click|dblclick|mouse(' +
'?:down|up|over|move|out)|key(?:press|down|up)))$');
-function canDeleteEmptyAttribute(tag, attrName, attrValue) {
+function canDeleteEmptyAttribute(tag, attrName, attrValue, options) {
var isValueEmpty = !attrValue || /^\s*$/.test(attrValue);
- if (isValueEmpty) {
- return tag === 'input' && attrName === 'value' || reEmptyAttribute.test(attrName);
+ if (!isValueEmpty) {
+ return false;
}
- return false;
+ if (typeof options.removeEmptyAttributes === 'function') {
+ return options.removeEmptyAttributes(attrName, tag);
+ }
+ return tag === 'input' && attrName === 'value' || reEmptyAttribute.test(attrName);
}
function hasAttrName(name, attrs) {
attrValue = cleanAttributeValue(tag, attrName, attrValue, options, attrs);
if (options.removeEmptyAttributes &&
- canDeleteEmptyAttribute(tag, attrName, attrValue)) {
+ canDeleteEmptyAttribute(tag, attrName, attrValue, options)) {
return;
}
// remove recognized attrs with unspecified values
input = '<div data-foo class id style title lang dir onfocus onblur onchange onclick ondblclick onmousedown onmouseup onmouseover onmousemove onmouseout onkeypress onkeydown onkeyup></div>';
assert.equal(minify(input, { removeEmptyAttributes: true }), '<div data-foo></div>');
+
+ // additional remove attributes
+ input = '<img src="" alt="">';
+ assert.equal(minify(input, { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }), '<img alt="">');
});
QUnit.test('cleaning class/style attributes', function(assert) {