Skip to content

Commit

Permalink
Correctly handle @use rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Darklg committed Sep 20, 2024
1 parent 5630143 commit 672cffd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions css/clean-code.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@charset "UTF-8";

@use "sass:math";

/* This comment should not be removed */

$custom-br: 3px;
Expand All @@ -16,8 +18,6 @@ $custom-br: 3px;
content: '•';
}

@use "sass:math";

a {
margin-left: -0.4px;
border: 1px solid red;
Expand Down
2 changes: 1 addition & 1 deletion css/dirty-code.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ background-clip: border;/* This comment should stay contiguous to background-cli
/* This comment should be removed */}
@charset "UTF-8";

@use "sass:math";a{border:1px solid red;-webkit-box-shadow: inset 0 0 0 1px #000;-moz-box-shadow: inset 0 0 0 1px #000;
@use 'sass: math';a{border:1px solid red;-webkit-box-shadow: inset 0 0 0 1px #000;-moz-box-shadow: inset 0 0 0 1px #000;
/* This comment should be removed */
box-shadow: inset 0 0 0 1px #000;margin-left:-0.4px}
.box{/* This comment should be removed */margin-top: 10px;margin-left: 20px;
Expand Down
13 changes: 13 additions & 0 deletions inc/classes/csslisible.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,19 @@ private function small_clean( $css ) {
// Simplification des codes couleurs hexadécimaux
$css = $this->identify_and_short_hex_color_values( $css );

// Extract all @use
preg_match_all('/\@use([^;]+)\;\\n+/ui', $css, $matches);
// Append all @use at the beginning
if (isset($matches[0][0])) {
foreach ($matches[0] as $match) {
$match = trim($match);
$new_match = str_replace("'", '"', $match);
$new_match = str_replace(": ", ':', $new_match);
$css = str_replace($match, '', $css);
$css = $new_match . $this->get_interlignage() . $css;
}
}

// Keep only one @charset
preg_match_all('/\@charset(.*)\;\\n+/ui', $css, $matches);
if(isset($matches[0][0]))
Expand Down

0 comments on commit 672cffd

Please sign in to comment.