diff --git a/plugins/removeElementsByAttr.js b/plugins/removeElementsByAttr.js index c726f708..c2d099bf 100644 --- a/plugins/removeElementsByAttr.js +++ b/plugins/removeElementsByAttr.js @@ -7,8 +7,8 @@ exports.active = false; exports.description = 'removes arbitrary elements by ID or className (disabled by default)'; exports.params = { - id: [], - class: [] + id: [], + class: [] }; /** @@ -51,30 +51,28 @@ exports.params = { * @author Eli Dupuis (@elidupuis) */ exports.fn = function(item, params) { - var elemId, elemClass; - - // wrap params in an array if not already - ['id', 'class'].forEach(function(key) { - if (!Array.isArray(params[key])) { - params[key] = [ params[key] ]; - } - }); - - // abort if current item is no an element - if (!item.isElem()) { - return; + // wrap params in an array if not already + ['id', 'class'].forEach(function(key) { + if (!Array.isArray(params[key])) { + params[key] = [ params[key] ]; } + }); - // remove element if it's `id` matches configured `id` params - elemId = item.attr('id'); - if (elemId) { - return params.id.indexOf(elemId.value) === -1; - } + // abort if current item is no an element + if (!item.isElem()) { + return; + } - // remove element if it's `class` contains any of the configured `class` params - elemClass = item.attr('class'); - if (elemClass) { - var hasClassRegex = new RegExp(params.class.join('|')); - return !hasClassRegex.test(elemClass.value); - } + // remove element if it's `id` matches configured `id` params + const elemId = item.attr('id'); + if (elemId && params.id.length !== 0) { + return params.id.includes(elemId.value) === false; + } + + // remove element if it's `class` contains any of the configured `class` params + const elemClass = item.attr('class'); + if (elemClass && params.class.length !== 0) { + const classList = elemClass.value.split(' '); + return params.class.some(item => classList.includes(item)) === false; + } }; diff --git a/test/plugins/removeElementsByAttr.07.svg b/test/plugins/removeElementsByAttr.07.svg new file mode 100644 index 00000000..bb745556 --- /dev/null +++ b/test/plugins/removeElementsByAttr.07.svg @@ -0,0 +1,9 @@ + + + + +@@@ + + + +