32 lines
No EOL
826 B
JavaScript
32 lines
No EOL
826 B
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports["default"] = collapseAttributeWhitespace;
|
|
exports.attributesWithLists = void 0;
|
|
var attributesWithLists = new Set(['class', 'rel', 'ping']);
|
|
/** Collapse whitespaces inside list-like attributes (e.g. class, rel) */
|
|
|
|
exports.attributesWithLists = attributesWithLists;
|
|
|
|
function collapseAttributeWhitespace(tree) {
|
|
tree.walk(function (node) {
|
|
if (!node.attrs) {
|
|
return node;
|
|
}
|
|
|
|
Object.keys(node.attrs).forEach(function (attrName) {
|
|
var attrNameLower = attrName.toLowerCase();
|
|
|
|
if (!attributesWithLists.has(attrNameLower)) {
|
|
return;
|
|
}
|
|
|
|
var attrValue = node.attrs[attrName].replace(/\s+/g, ' ').trim();
|
|
node.attrs[attrName] = attrValue;
|
|
});
|
|
return node;
|
|
});
|
|
return tree;
|
|
} |