From a2b0e737670a46955097a5b02fe3daa35c3f231b Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 6 Mar 2021 13:18:53 +0300 Subject: [PATCH] Preserve conditional processing attributes --- plugins/removeEmptyAttrs.js | 26 ++++++++++++++------------ test/plugins/removeEmptyAttrs.02.svg | 18 ++++++++++++++++++ test/regression.js | 4 ++-- 3 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 test/plugins/removeEmptyAttrs.02.svg diff --git a/plugins/removeEmptyAttrs.js b/plugins/removeEmptyAttrs.js index ae73e6c96..daad5c513 100644 --- a/plugins/removeEmptyAttrs.js +++ b/plugins/removeEmptyAttrs.js @@ -1,5 +1,7 @@ 'use strict'; +const { attrsGroups } = require('./_collections.js'); + exports.type = 'perItem'; exports.active = true; @@ -14,16 +16,16 @@ exports.description = 'removes empty attributes'; * * @author Kir Belevich */ -exports.fn = function(item) { - - if (item.elem) { - - item.eachAttr(function(attr) { - if (attr.value === '') { - item.removeAttr(attr.name); - } - }); - - } - +exports.fn = function (item) { + if (item.elem) { + item.eachAttr(function (attr) { + if ( + attr.value === '' && + // empty conditional processing attributes prevents elements from rendering + attrsGroups.conditionalProcessing.includes(attr.name) === false + ) { + item.removeAttr(attr.name); + } + }); + } }; diff --git a/test/plugins/removeEmptyAttrs.02.svg b/test/plugins/removeEmptyAttrs.02.svg new file mode 100644 index 000000000..336c4a4f5 --- /dev/null +++ b/test/plugins/removeEmptyAttrs.02.svg @@ -0,0 +1,18 @@ +Empty conditional processing attributes should be preserved +to hide elements + +=== + + + + + + + +@@@ + + + + + + diff --git a/test/regression.js b/test/regression.js index 8cc5c49ee..61ea0f29f 100644 --- a/test/regression.js +++ b/test/regression.js @@ -107,15 +107,15 @@ const runTests = async ({ svgFiles }) => { name === 'styling-css-10-f' || // rect is converted to path which matches wrong styles name === 'styling-css-08-f' || - // other cases which require complex changes + // external image name === 'struct-image-02-b' || + // complex selectors are messed becase of converting shapes to paths name === 'struct-use-10-f' || name === 'struct-use-11-f' || name === 'styling-css-01-b' || name === 'styling-css-03-b' || name === 'styling-css-04-f' || // mismatched draft cases - name === 'struct-cond-overview-03-f' || name === 'struct-use-07-b' ) { console.info(`${name} is skipped`);