| @@ -35,9 +35,21 @@ | ||
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | 37 | public function run( $css ) |
| 38 | 38 | { |
| 39 | + // hide calc() if filter says yes (as YUI CSS compressor PHP port has problems retaining spaces around + and - operators). | |
| 40 | + // regex see tests at https://regex101.com/r/ofGQG9/1 | |
| 41 | + if ( apply_filters( 'autoptimize_filter_css_hide_calc', true ) ) { | |
| 42 | + $css = autoptimizeBase::replace_contents_with_marker_if_exists( 'CALC', 'calc(', '#(calc|min|max|clamp)\([^;}]*\)#m', $css ); | |
| 43 | + } | |
| 44 | + | |
| 45 | + // minify. | |
| 39 | 46 | $result = $this->minifier->run( $css ); |
| 47 | + | |
| 48 | + // restore calc() if filter says yes. | |
| 49 | + if ( apply_filters( 'autoptimize_filter_css_hide_calc', true ) ) { | |
| 50 | + $result = autoptimizeBase::restore_marked_content( 'CALC', $result ); | |
| 51 | + } | |
| 40 | 52 | |
| 41 | 53 | return $result; |
| 42 | 54 | } |
| 43 | 55 | |