Skip to content

Commit

Permalink
fix (custom css): support nested css (#3199)
Browse files Browse the repository at this point in the history
* fix: Ignore invalid CSS that affects the CSS of subsequent blocks

* fix: revert change

* fix: close any open curly braces
  • Loading branch information
Arukuen authored Jun 24, 2024
1 parent 89baa41 commit 100f6fe
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/css-optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,17 @@ public static function generate_css( $styles ) {
// Optimize selectors by combining similar ones.
$selector_arr = self::combine_selectors( $selector_arr );

$css .= implode( ',', $selector_arr ) . $style_rules;
$combined_css = implode( ',', $selector_arr ) . $style_rules;

// Prevent invalid CSS in affecting the rest of the CSS
// by closing any open curly braces.
$open_curly_brace = substr_count( $combined_css , '{' );
$close_curly_brace = substr_count( $combined_css , '}' );
if ( $open_curly_brace > $close_curly_brace ) {
$combined_css .= str_repeat( '}', $open_curly_brace - $close_curly_brace );
}

$css .= $combined_css;
}

if ( ! empty( $media_query ) ) {
Expand Down

0 comments on commit 100f6fe

Please sign in to comment.