Automattic\WooCommerce\Vendor\Pelago\Emogrifier

CssInliner::inlineCsspublicWC 1.0

Inlines the given CSS into the existing HTML.

Method of the class: CssInliner{}

No Hooks.

Returns

$this.

Usage

$CssInliner = new CssInliner();
$CssInliner->inlineCss( $css ): self;
$css(string)
the CSS to inline, must be UTF-8-encoded.
Default: ''

CssInliner::inlineCss() code WC 10.4.3

public function inlineCss(string $css = ''): self
{
    $this->clearAllCaches();
    $this->purgeVisitedNodes();

    $this->normalizeStyleAttributesOfAllNodes();

    $combinedCss = $css;
    // grab any existing style blocks from the HTML and append them to the existing CSS
    // (these blocks should be appended so as to have precedence over conflicting styles in the existing CSS)
    if ($this->isStyleBlocksParsingEnabled) {
        $combinedCss .= $this->getCssFromAllStyleNodes();
    }
    $parsedCss = new CssDocument($combinedCss, $this->debug);

    $excludedNodes = $this->getNodesToExclude();
    $cssRules = $this->collateCssRules($parsedCss);
    foreach ($cssRules['inlinable'] as $cssRule) {
        foreach ($this->querySelectorAll($cssRule['selector']) as $node) {
            if (\in_array($node, $excludedNodes, true)) {
                continue;
            }
            $this->copyInlinableCssToStyleAttribute($this->ensureNodeIsElement($node), $cssRule);
        }
    }

    if ($this->isInlineStyleAttributesParsingEnabled) {
        $this->fillStyleAttributesWithMergedStyles();
    }

    $this->removeImportantAnnotationFromAllInlineStyles();

    $this->determineMatchingUninlinableCssRules($cssRules['uninlinable']);
    $this->copyUninlinableCssToStyleNode($parsedCss);

    return $this;
}