Skip to content

Commit 3af4c30

Browse files
authored
Merge pull request #19 from ProspectiveCo/fix-svg-whitespace
Fix svg whitespace issue
2 parents a417333 + b2a9643 commit 3af4c30

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/ast/token/space.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,30 @@ impl NeedsWhitespaceStringExt for str {
3131
fn needs_pre_ws(&self) -> bool {
3232
self.chars()
3333
.next()
34-
.map(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_' || x == '%' || x == '+')
34+
.map(|x| {
35+
x.is_ascii_alphanumeric()
36+
|| x == '-'
37+
|| x == '_'
38+
|| x == '%'
39+
|| x == '+'
40+
|| x == '"'
41+
|| x == '\''
42+
})
3543
.unwrap_or_default()
3644
}
3745

3846
fn needs_post_ws(&self) -> bool {
3947
self.chars()
4048
.last()
41-
.map(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_' || x == '%' || x == '+')
49+
.map(|x| {
50+
x.is_ascii_alphanumeric()
51+
|| x == '"'
52+
|| x == '\''
53+
|| x == '-'
54+
|| x == '_'
55+
|| x == '%'
56+
|| x == '+'
57+
})
4258
.unwrap_or_default()
4359
}
4460
}
@@ -57,18 +73,6 @@ pub fn trim_whitespace(s: &str, f: &mut std::fmt::Formatter<'_>) {
5773
});
5874
}
5975

60-
// pub fn trim_whitespace(s: &str, f: &mut std::fmt::Formatter<'_>) {
61-
// let mut flag = false;
62-
// s.split_whitespace().for_each(|w| {
63-
// if flag {
64-
// write!(f, " ").unwrap();
65-
// }
66-
67-
// flag = flag || !w.is_empty();
68-
// write!(f, "{}", w).unwrap();
69-
// });
70-
// }
71-
7276
fn parse_comment<'a, E>(input: &'a str) -> IResult<&'a str, (), E>
7377
where
7478
E: ParseError<&'a str>,

tests/at_ruleset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn test_import() {
112112
)
113113
.map(|x| x.flatten_tree().as_css_string())
114114
.as_deref(),
115-
Ok("@import\"test\";div{color:green;}")
115+
Ok("@import \"test\";div{color:green;}")
116116
)
117117
}
118118

tests/minify.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@ fn test_minify_percent_followed_by_plus() {
3535
Ok("div{width:calc(100% + 28px);}")
3636
)
3737
}
38+
39+
#[test]
40+
fn test_minify_svg() {
41+
assert_matches!(
42+
parse(r#"div { background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><path d='M100 0 L0 100 ' stroke='black' stroke-width='1'/><path d='M0 0 L100 100 ' stroke='black' stroke-width='1'/></svg>") #8b868045; }"#)
43+
.map(|x| x.as_css_string())
44+
.as_deref(),
45+
Ok("div{background:url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><path d='M100 0 L0 100 ' stroke='black' stroke-width='1'/><path d='M0 0 L100 100 ' stroke='black' stroke-width='1'/></svg>\")#8b868045;}")
46+
)
47+
}

0 commit comments

Comments
 (0)