1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-28 09:22:00 +03:00

Refactor basic plugins with visitor api (#1518)

- cleanupAttrs
- convertEllipseToCircle
- removeDesc
- removeDoctype
- removeEmptyText
- removeMetadata
- removeRasterImages
- removeScriptElement
- removeStyleElement
- removeTitle
- removeXMLProcInst
This commit is contained in:
Bogdan Chadkin
2021-08-12 14:57:36 +03:00
committed by GitHub
parent 35b7356ff0
commit f00bd727b0
11 changed files with 191 additions and 175 deletions

View File

@ -1,9 +1,9 @@
'use strict';
exports.type = 'perItem';
const { detachNodeFromParent } = require('../lib/xast.js');
exports.type = 'visitor';
exports.active = false;
exports.description = 'removes raster images (disabled by default)';
/**
@ -11,18 +11,20 @@ exports.description = 'removes raster images (disabled by default)';
*
* @see https://bugs.webkit.org/show_bug.cgi?id=63548
*
* @param {Object} item current iteration item
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.fn = function (item) {
if (
item.type === 'element' &&
item.name === 'image' &&
item.attributes['xlink:href'] != null &&
/(\.|image\/)(jpg|png|gif)/.test(item.attributes['xlink:href'])
) {
return false;
}
exports.fn = () => {
return {
element: {
enter: (node, parentNode) => {
if (
node.name === 'image' &&
node.attributes['xlink:href'] != null &&
/(\.|image\/)(jpg|png|gif)/.test(node.attributes['xlink:href'])
) {
detachNodeFromParent(node, parentNode);
}
},
},
};
};