flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
31
BACK_BACK/node_modules/htmlnano/lib/modules/removeEmptyAttributes.js
generated
vendored
Executable file
31
BACK_BACK/node_modules/htmlnano/lib/modules/removeEmptyAttributes.js
generated
vendored
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = removeEmptyAttributes;
|
||||
// Source: https://www.w3.org/TR/html4/sgml/dtd.html#events (Generic Attributes)
|
||||
const safeToRemoveAttrs = new Set(['id', 'class', 'style', 'title', 'lang', 'dir', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove', 'onmouseout', 'onkeypress', 'onkeydown', 'onkeyup']);
|
||||
/** Removes empty attributes */
|
||||
|
||||
function removeEmptyAttributes(tree) {
|
||||
tree.walk(node => {
|
||||
if (!node.attrs) {
|
||||
return node;
|
||||
}
|
||||
|
||||
Object.entries(node.attrs).forEach(([attrName, attrValue]) => {
|
||||
const attrNameLower = attrName.toLowerCase();
|
||||
|
||||
if (!safeToRemoveAttrs.has(attrNameLower)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attrValue === '' || (attrValue || '').match(/^\s+$/)) {
|
||||
delete node.attrs[attrName];
|
||||
}
|
||||
});
|
||||
return node;
|
||||
});
|
||||
return tree;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue