From 640e986ef5b2e04c5ce4b61d21337f017a51d1c2 Mon Sep 17 00:00:00 2001 From: Sam Denty Date: Mon, 26 Dec 2022 17:46:30 +0000 Subject: [PATCH] 0.4.10: remove fill none from svg --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/utils.rs | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 973ded2..37e6576 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1638,7 +1638,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "site_icons" -version = "0.4.9" +version = "0.4.10" dependencies = [ "byteorder", "clap", diff --git a/Cargo.toml b/Cargo.toml index 0e5b27c..54bec83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "site_icons" -version = "0.4.9" +version = "0.4.10" authors = ["Sam Denty "] edition = "2018" license = "GPL-3.0" diff --git a/src/utils.rs b/src/utils.rs index be2e2f3..583af85 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,5 @@ use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; +use std::borrow::Cow; const DATA_URI: &AsciiSet = &CONTROLS .add(b'\r') @@ -28,7 +29,19 @@ pub fn encode_svg(svg: &str) -> String { }; // use single quotes instead of double to avoid encoding. - let encoded = regex!("\"").replace_all(&encoded, "'"); + let mut encoded = regex!("\"").replace_all(&encoded, "'"); + + // remove a fill=none attribute + if let Some(captures) = regex!("^[^>]+fill='?(none)'?").captures(&encoded) { + let index = captures.get(1).unwrap(); + let mut result = String::new(); + for (i, c) in encoded.chars().enumerate() { + if i < index.start() || i >= index.end() { + result.push(c); + } + } + encoded = Cow::from(result); + } // remove whitespace let encoded = regex!(r">\s{1,}<").replace_all(&encoded, "><");