From 7ddc8ebbc086eb7c86a4306f95fe4e609f5bc4a8 Mon Sep 17 00:00:00 2001 From: deepsweet Date: Wed, 13 Feb 2013 17:22:15 +0200 Subject: [PATCH] plugins/removeRasterImages: remove raster images references in (disabled by default) (close #98) --- .svgo.yml | 4 ++++ plugins/removeRasterImages.js | 23 +++++++++++++++++++ test/plugins/removeRasterImages.01.orig.svg | 7 ++++++ test/plugins/removeRasterImages.01.should.svg | 5 ++++ test/plugins/removeRasterImages.02.orig.svg | 7 ++++++ test/plugins/removeRasterImages.02.should.svg | 5 ++++ 6 files changed, 51 insertions(+) create mode 100644 plugins/removeRasterImages.js create mode 100644 test/plugins/removeRasterImages.01.orig.svg create mode 100644 test/plugins/removeRasterImages.01.should.svg create mode 100644 test/plugins/removeRasterImages.02.orig.svg create mode 100644 test/plugins/removeRasterImages.02.should.svg diff --git a/.svgo.yml b/.svgo.yml index 9cccbb2e..9a138406 100644 --- a/.svgo.yml +++ b/.svgo.yml @@ -32,6 +32,10 @@ plugins: active: true type: perItem + - name: removeRasterImages + active: false + type: perItem + - name: cleanupNumericValues active: true type: perItem diff --git a/plugins/removeRasterImages.js b/plugins/removeRasterImages.js new file mode 100644 index 00000000..b730b3a1 --- /dev/null +++ b/plugins/removeRasterImages.js @@ -0,0 +1,23 @@ +'use strict'; + +/** + * Remove raster images references in . + * + * @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; + } + +}; diff --git a/test/plugins/removeRasterImages.01.orig.svg b/test/plugins/removeRasterImages.01.orig.svg new file mode 100644 index 00000000..a16c6a9a --- /dev/null +++ b/test/plugins/removeRasterImages.01.orig.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/plugins/removeRasterImages.01.should.svg b/test/plugins/removeRasterImages.01.should.svg new file mode 100644 index 00000000..1bc122a8 --- /dev/null +++ b/test/plugins/removeRasterImages.01.should.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/test/plugins/removeRasterImages.02.orig.svg b/test/plugins/removeRasterImages.02.orig.svg new file mode 100644 index 00000000..b896b5af --- /dev/null +++ b/test/plugins/removeRasterImages.02.orig.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/plugins/removeRasterImages.02.should.svg b/test/plugins/removeRasterImages.02.should.svg new file mode 100644 index 00000000..c6fc3f15 --- /dev/null +++ b/test/plugins/removeRasterImages.02.should.svg @@ -0,0 +1,5 @@ + + + + +