From c1d5f0f7a93a6f1c947baa5860ddd40f8d1bb701 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Tue, 23 Feb 2021 22:36:47 +0300 Subject: [PATCH] Keep empty when filter attributes is specified --- plugins/removeEmptyContainers.js | 13 +++++++++---- test/plugins/removeEmptyContainers.04.svg | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 test/plugins/removeEmptyContainers.04.svg diff --git a/plugins/removeEmptyContainers.js b/plugins/removeEmptyContainers.js index 356a5835b..6ef1aac33 100644 --- a/plugins/removeEmptyContainers.js +++ b/plugins/removeEmptyContainers.js @@ -25,8 +25,13 @@ var container = require('./_collections').elemsGroups.container; * @author Kir Belevich */ exports.fn = function(item) { - - return !(item.isElem(container) && !item.isElem('svg') && item.isEmpty() && - (!item.isElem('pattern') || !item.hasAttrLocal('href'))); - + return ( + item.isElem(container) === false || + item.isEmpty() === false || + item.isElem('svg') || + (item.isElem('pattern') && item.hasAttrLocal('href')) || + // The 'g' may not have content, but the filter may cause a rectangle + // to be created and filled with pattern. + (item.isElem('g') && item.hasAttr('filter')) + ); }; diff --git a/test/plugins/removeEmptyContainers.04.svg b/test/plugins/removeEmptyContainers.04.svg new file mode 100644 index 000000000..fa1698cdd --- /dev/null +++ b/test/plugins/removeEmptyContainers.04.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + +@@@ + + + + + + + + + + +