mirror of
https://github.com/svg/svgo.git
synced 2025-07-28 09:22:00 +03:00
plugins/removeRasterImages: remove raster images references in <image> (disabled by default) (close #98)
This commit is contained in:
@ -32,6 +32,10 @@ plugins:
|
||||
active: true
|
||||
type: perItem
|
||||
|
||||
- name: removeRasterImages
|
||||
active: false
|
||||
type: perItem
|
||||
|
||||
- name: cleanupNumericValues
|
||||
active: true
|
||||
type: perItem
|
||||
|
23
plugins/removeRasterImages.js
Normal file
23
plugins/removeRasterImages.js
Normal file
@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Remove raster images references in <image>.
|
||||
*
|
||||
* @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.removeRasterImages = function(item) {
|
||||
|
||||
if (
|
||||
item.isElem('image') &&
|
||||
item.hasAttr('xlink:href') &&
|
||||
/(\.|image\/)(jpg|png)/.test(item.attr('xlink:href').value)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
7
test/plugins/removeRasterImages.01.orig.svg
Normal file
7
test/plugins/removeRasterImages.01.orig.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g>
|
||||
<image xlink:href="raster.jpg" width="100" height="100"/>
|
||||
<image xlink:href="raster.png" width="100" height="100"/>
|
||||
<image xlink:href="raster.svg" width="100" height="100"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 306 B |
5
test/plugins/removeRasterImages.01.should.svg
Normal file
5
test/plugins/removeRasterImages.01.should.svg
Normal file
@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g>
|
||||
<image xlink:href="raster.svg" width="100" height="100"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 174 B |
7
test/plugins/removeRasterImages.02.orig.svg
Normal file
7
test/plugins/removeRasterImages.02.orig.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g>
|
||||
<image xlink:href="data:image/jpg;base64,..." width="100" height="100"/>
|
||||
<image xlink:href="data:image/png;base64,..." width="100" height="100"/>
|
||||
<image xlink:href="data:image/svg+xml;base64,..." width="100" height="100"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 355 B |
5
test/plugins/removeRasterImages.02.should.svg
Normal file
5
test/plugins/removeRasterImages.02.should.svg
Normal file
@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g>
|
||||
<image xlink:href="data:image/svg+xml;base64,..." width="100" height="100"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 193 B |
Reference in New Issue
Block a user