Skip to content

Commit

Permalink
Preserve conditional processing attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Mar 6, 2021
1 parent d3e3726 commit a2b0e73
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
26 changes: 14 additions & 12 deletions plugins/removeEmptyAttrs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { attrsGroups } = require('./_collections.js');

exports.type = 'perItem';

exports.active = true;
Expand All @@ -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);
}
});
}
};
18 changes: 18 additions & 0 deletions test/plugins/removeEmptyAttrs.02.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down

0 comments on commit a2b0e73

Please sign in to comment.