diff --git a/plugins/removeEmptyAttrs.js b/plugins/removeEmptyAttrs.js index 55586832e..5d9870a29 100644 --- a/plugins/removeEmptyAttrs.js +++ b/plugins/removeEmptyAttrs.js @@ -2,32 +2,32 @@ const { attrsGroups } = require('./_collections.js'); +exports.type = 'visitor'; exports.name = 'removeEmptyAttrs'; - -exports.type = 'perItem'; - exports.active = true; - exports.description = 'removes empty attributes'; /** * Remove attributes with empty values. * - * @param {Object} item current iteration item - * @return {Boolean} if false, item will be filtered out - * * @author Kir Belevich + * + * @type {import('../lib/types').Plugin} */ -exports.fn = function (item) { - if (item.type === 'element') { - for (const [name, value] of Object.entries(item.attributes)) { - if ( - value === '' && - // empty conditional processing attributes prevents elements from rendering - attrsGroups.conditionalProcessing.includes(name) === false - ) { - delete item.attributes[name]; - } - } - } +exports.fn = () => { + return { + element: { + enter: (node) => { + for (const [name, value] of Object.entries(node.attributes)) { + if ( + value === '' && + // empty conditional processing attributes prevents elements from rendering + attrsGroups.conditionalProcessing.includes(name) === false + ) { + delete node.attributes[name]; + } + } + }, + }, + }; }; diff --git a/test/plugins/removeEmptyAttrs.01.svg b/test/plugins/removeEmptyAttrs.01.svg index 39564efcc..75ef26f30 100644 --- a/test/plugins/removeEmptyAttrs.01.svg +++ b/test/plugins/removeEmptyAttrs.01.svg @@ -1,3 +1,7 @@ +Removes empty attributes + +=== + diff --git a/tsconfig.json b/tsconfig.json index 0a3748689..f7dbe1cca 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,6 @@ "plugins/moveGroupAttrsToElems.js", "plugins/plugins.js", "plugins/removeDimensions.js", - "plugins/removeEmptyAttrs.js", "plugins/removeNonInheritableGroupAttrs.js", "plugins/removeXMLNS.js", "plugins/inlineStyles.js",