/** * Replace conditional placeholders used by Internet Explorer. * * @param string $contents * @param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer * * @return string */ protected function setConditionalCommentsPlaceholder($contents, PlaceholderContainer $placeholderContainer) { return preg_replace_callback('/ ( <! # Match the start of a comment (-{2})? # IE can understand comments without dashes \\[ # Match the start ("[" is a metachar => escape it) (?:(?!\\]>).)* # Match everything except "]>" \\]> # Match end ) ( (?: (?!<!\\[endif\\]-{2}?>) .)* ) # Match everything except end of conditional comment ( <!\\[endif\\] (?:\\2|(?=>)) # Use a trick to ensure that when dashes are captured they are... # matched at the end! Else make sure that the next char is a ">"! > # Match the endif with the captured dashes ) /xis', function ($match) use($placeholderContainer) { if (!empty(preg_replace('/\\s*/', '', $match[3]))) { return $placeholderContainer->addPlaceholder($match[1]) . $match[3] . $placeholderContainer->addPlaceholder($match[4]); } else { return ''; } }, $contents); }
/** * Add placeholder for blade specific control structures. * * @param string $contents * @param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer * * @return string */ protected function setBladeControlStructuresPlaceholder($contents, PlaceholderContainer $placeholderContainer) { return preg_replace_callback('/@\\w*(\\s*\\(.*\\))?/', function ($match) use($placeholderContainer) { return $placeholderContainer->addPlaceholder($match[0]); }, $contents); }
/** * @param string $contents * @param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer * * @return string */ protected function replaceElements($contents, PlaceholderContainer $placeholderContainer) { $htmlTags = implode('|', $this->htmlPlaceholderTags); $pattern = '/ ( <(' . $htmlTags . ') (?: [^"\'>]*|"[^"]*"|\'[^\']*\' )* > ) ((?:(?!<\\/\\2>).)+) (<\\/\\2>)/xis'; return preg_replace_callback($pattern, function ($match) use($placeholderContainer) { return $match[1] . $placeholderContainer->addPlaceholder($match[3]) . $match[4]; }, $contents); }