Automattic\WooCommerce\Vendor\Pelago\Emogrifier
CssInliner::removeImportantAnnotationFromNodeInlineStyle
Removes the "!important" annotations out of the inline style declarations, eventually by rearranging declarations. Rearranging needed when !important shorthand properties are followed by some of their not !important expanded-version properties. For example "font: 12px serif !important; font-size: 13px;" must be reordered to "font-size: 13px; font: 12px serif;" in order to remain correct.
Method of the class: CssInliner{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->removeImportantAnnotationFromNodeInlineStyle( $node ): void;
- $node(DOMElement) (required)
- .
CssInliner::removeImportantAnnotationFromNodeInlineStyle() CssInliner::removeImportantAnnotationFromNodeInlineStyle code WC 10.4.3
private function removeImportantAnnotationFromNodeInlineStyle(\DOMElement $node): void
{
$style = $node->getAttribute('style');
$inlineStyleDeclarations = (new DeclarationBlockParser())->parse((bool) $style ? $style : '');
/** @var array<string, string> $regularStyleDeclarations */
$regularStyleDeclarations = [];
/** @var array<string, string> $importantStyleDeclarations */
$importantStyleDeclarations = [];
foreach ($inlineStyleDeclarations as $property => $value) {
if ($this->attributeValueIsImportant($value)) {
$importantStyleDeclarations[$property]
= (new Preg())->throwExceptions($this->debug)->replace('/\\s*+!\\s*+important$/i', '', $value);
} else {
$regularStyleDeclarations[$property] = $value;
}
}
$inlineStyleDeclarationsInNewOrder = \array_merge($regularStyleDeclarations, $importantStyleDeclarations);
$node->setAttribute(
'style',
$this->generateStyleStringFromSingleDeclarationsArray($inlineStyleDeclarationsInNewOrder)
);
}