Skip to content

Commit

Permalink
Minify CSS rules to be able to handle minified theme files as well
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 12, 2020
1 parent 320ada6 commit c8e567d
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/librustdoc/theme.rs
Expand Up @@ -179,20 +179,23 @@ fn get_previous_positions(events: &[Events], mut pos: usize) -> Vec<usize> {
}

fn build_rule(v: &[u8], positions: &[usize]) -> String {
positions
.chunks(2)
.map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
.collect::<String>()
.trim()
.replace("\n", " ")
.replace("/", "")
.replace("\t", " ")
.replace("{", "")
.replace("}", "")
.split(' ')
.filter(|s| s.len() > 0)
.collect::<Vec<&str>>()
.join(" ")
minifier::css::minify(
&positions
.chunks(2)
.map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
.collect::<String>()
.trim()
.replace("\n", " ")
.replace("/", "")
.replace("\t", " ")
.replace("{", "")
.replace("}", "")
.split(' ')
.filter(|s| s.len() > 0)
.collect::<Vec<&str>>()
.join(" "),
)
.unwrap_or_else(|_| String::new())
}

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

0 comments on commit c8e567d

Please sign in to comment.