mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
Preserve conditional processing attributes
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { attrsGroups } = require('./_collections.js');
|
||||||
|
|
||||||
exports.type = 'perItem';
|
exports.type = 'perItem';
|
||||||
|
|
||||||
exports.active = true;
|
exports.active = true;
|
||||||
@ -14,16 +16,16 @@ exports.description = 'removes empty attributes';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*/
|
*/
|
||||||
exports.fn = function(item) {
|
exports.fn = function (item) {
|
||||||
|
if (item.elem) {
|
||||||
if (item.elem) {
|
item.eachAttr(function (attr) {
|
||||||
|
if (
|
||||||
item.eachAttr(function(attr) {
|
attr.value === '' &&
|
||||||
if (attr.value === '') {
|
// empty conditional processing attributes prevents elements from rendering
|
||||||
item.removeAttr(attr.name);
|
attrsGroups.conditionalProcessing.includes(attr.name) === false
|
||||||
}
|
) {
|
||||||
});
|
item.removeAttr(attr.name);
|
||||||
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
18
test/plugins/removeEmptyAttrs.02.svg
Normal file
18
test/plugins/removeEmptyAttrs.02.svg
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
Empty conditional processing attributes should be preserved
|
||||||
|
to hide elements
|
||||||
|
|
||||||
|
===
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g requiredFeatures=""/>
|
||||||
|
<g requiredExtensions=""/>
|
||||||
|
<g systemLanguage=""/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
@@@
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g requiredFeatures=""/>
|
||||||
|
<g requiredExtensions=""/>
|
||||||
|
<g systemLanguage=""/>
|
||||||
|
</svg>
|
@ -107,15 +107,15 @@ const runTests = async ({ svgFiles }) => {
|
|||||||
name === 'styling-css-10-f' ||
|
name === 'styling-css-10-f' ||
|
||||||
// rect is converted to path which matches wrong styles
|
// rect is converted to path which matches wrong styles
|
||||||
name === 'styling-css-08-f' ||
|
name === 'styling-css-08-f' ||
|
||||||
// other cases which require complex changes
|
// external image
|
||||||
name === 'struct-image-02-b' ||
|
name === 'struct-image-02-b' ||
|
||||||
|
// complex selectors are messed becase of converting shapes to paths
|
||||||
name === 'struct-use-10-f' ||
|
name === 'struct-use-10-f' ||
|
||||||
name === 'struct-use-11-f' ||
|
name === 'struct-use-11-f' ||
|
||||||
name === 'styling-css-01-b' ||
|
name === 'styling-css-01-b' ||
|
||||||
name === 'styling-css-03-b' ||
|
name === 'styling-css-03-b' ||
|
||||||
name === 'styling-css-04-f' ||
|
name === 'styling-css-04-f' ||
|
||||||
// mismatched draft cases
|
// mismatched draft cases
|
||||||
name === 'struct-cond-overview-03-f' ||
|
|
||||||
name === 'struct-use-07-b'
|
name === 'struct-use-07-b'
|
||||||
) {
|
) {
|
||||||
console.info(`${name} is skipped`);
|
console.info(`${name} is skipped`);
|
||||||
|
Reference in New Issue
Block a user