1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-27 07:02:06 +03:00
Files
svgo/plugins/removeRasterImages.js
Abe Fehr 437c09b006 Add support for image/jpeg mimetype (#1742)
In practice, this plugin does not work to remove embedded jpg images.

On further inspection, it's because the plugin is looking for
image/jpg, which I'm not even sure is a valid mimetype. Inkscape uses
image/jpeg as the mimetype for embedded JPG images.

Co-authored-by: Seth Falco <seth@falco.fun>
2023-09-24 13:32:13 +01:00

32 lines
746 B
JavaScript

'use strict';
const { detachNodeFromParent } = require('../lib/xast.js');
exports.name = 'removeRasterImages';
exports.description = 'removes raster images (disabled by default)';
/**
* Remove raster images references in <image>.
*
* @see https://bugs.webkit.org/show_bug.cgi?id=63548
*
* @author Kir Belevich
*
* @type {import('./plugins-types').Plugin<'removeRasterImages'>}
*/
exports.fn = () => {
return {
element: {
enter: (node, parentNode) => {
if (
node.name === 'image' &&
node.attributes['xlink:href'] != null &&
/(\.|image\/)(jpe?g|png|gif)/.test(node.attributes['xlink:href'])
) {
detachNodeFromParent(node, parentNode);
}
},
},
};
};