Skip to content

Commit 839adda

Browse files
authored
Rollup merge of #69095 - GuillaumeGomez:minified-theme-check, r=Dylan-DPC
Minified theme check Fixes #69071. r? @kinnison
2 parents e86019c + 109260f commit 839adda

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/librustdoc/theme.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,23 @@ fn get_previous_positions(events: &[Events], mut pos: usize) -> Vec<usize> {
179179
}
180180

181181
fn build_rule(v: &[u8], positions: &[usize]) -> String {
182-
positions
183-
.chunks(2)
184-
.map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
185-
.collect::<String>()
186-
.trim()
187-
.replace("\n", " ")
188-
.replace("/", "")
189-
.replace("\t", " ")
190-
.replace("{", "")
191-
.replace("}", "")
192-
.split(' ')
193-
.filter(|s| s.len() > 0)
194-
.collect::<Vec<&str>>()
195-
.join(" ")
182+
minifier::css::minify(
183+
&positions
184+
.chunks(2)
185+
.map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
186+
.collect::<String>()
187+
.trim()
188+
.replace("\n", " ")
189+
.replace("/", "")
190+
.replace("\t", " ")
191+
.replace("{", "")
192+
.replace("}", "")
193+
.split(' ')
194+
.filter(|s| s.len() > 0)
195+
.collect::<Vec<&str>>()
196+
.join(" "),
197+
)
198+
.unwrap_or_else(|_| String::new())
196199
}
197200

198201
fn inner(v: &[u8], events: &[Events], pos: &mut usize) -> FxHashSet<CssPath> {

src/librustdoc/theme/tests.rs

+13
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,16 @@ fn check_invalid_css() {
102102
let events = load_css_events(b"*");
103103
assert_eq!(events.len(), 0);
104104
}
105+
106+
#[test]
107+
fn test_with_minification() {
108+
let text = include_str!("../html/static/themes/dark.css");
109+
let minified = minifier::css::minify(&text).expect("CSS minification failed");
110+
111+
let against = load_css_paths(text.as_bytes());
112+
let other = load_css_paths(minified.as_bytes());
113+
114+
let mut ret = Vec::new();
115+
get_differences(&against, &other, &mut ret);
116+
assert!(ret.is_empty());
117+
}

0 commit comments

Comments
 (0)