0.4.10: remove fill none from svg
This commit is contained in:
parent
1980cb955a
commit
640e986ef5
3 changed files with 16 additions and 3 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1638,7 +1638,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "site_icons"
|
name = "site_icons"
|
||||||
version = "0.4.9"
|
version = "0.4.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "site_icons"
|
name = "site_icons"
|
||||||
version = "0.4.9"
|
version = "0.4.10"
|
||||||
authors = ["Sam Denty <sam@samdenty.com>"]
|
authors = ["Sam Denty <sam@samdenty.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
15
src/utils.rs
15
src/utils.rs
|
@ -1,4 +1,5 @@
|
||||||
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
|
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
const DATA_URI: &AsciiSet = &CONTROLS
|
const DATA_URI: &AsciiSet = &CONTROLS
|
||||||
.add(b'\r')
|
.add(b'\r')
|
||||||
|
@ -28,7 +29,19 @@ pub fn encode_svg(svg: &str) -> String {
|
||||||
};
|
};
|
||||||
|
|
||||||
// use single quotes instead of double to avoid encoding.
|
// 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
|
// remove whitespace
|
||||||
let encoded = regex!(r">\s{1,}<").replace_all(&encoded, "><");
|
let encoded = regex!(r">\s{1,}<").replace_all(&encoded, "><");
|
||||||
|
|
Reference in a new issue