Skip to content

Commit

Permalink
classes are also checked inside of strings in expression
Browse files Browse the repository at this point in the history
  • Loading branch information
uros-5 committed Jan 3, 2024
1 parent fc6e457 commit c7fb867
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "css-knife"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
authors = ["uros-5"]
license = "MIT"
Expand Down
16 changes: 14 additions & 2 deletions src/visit_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ pub fn check_html(
Settings {
element_content_handlers: vec![element!("[class]", |el| {
let classes = el.get_attribute("class").unwrap();
let mut in_expr = false;
let classes = classes.split(' ');
let classes = classes
.into_iter()
.map(|c| {
if let Some(class) = msv.get(c) {
return class;
if c.ends_with("{{") {
in_expr = true;
} else if c.ends_with("}}") {
in_expr = false
}
let single = c.contains('\'');
let double = c.contains('"');
if in_expr && !single && !double {
return c.to_string();
}
let c2 = c.replace(['\"', '\''], "");
if let Some(class) = msv.get(&c2) {
return c.replace(&c2, &class);
}
c.to_string()
})
Expand Down

0 comments on commit c7fb867

Please sign in to comment.