html = (string) $html; } public function disableInvisibleNodeRemoval() { $this->disableInvisibleNode = true; return $this; } public function emogrify() { if (!class_exists('\FluentEmogrifier\Vendor\TijsVerkoyen\CssToInlineStyles\CssToInlineStyles')) { require_once __DIR__ . '/scoped-vendor/autoload.php'; } return $this->handleTijsVerkoyen(); } private function handleTijsVerkoyen() { $css = ''; $html = $this->html; if (preg_match_all('/]*>(.*?)<\/style>/si', $html, $matches)) { $css = implode("\n", $matches[1]); $html = preg_replace('/]*>.*?<\/style>/si', '', $html); } // Preserve @media queries — TijsVerkoyen strips them during CSS processing // but email clients like Apple Mail and Gmail support them for responsive layouts. // Regex handles both spaced (@media screen) and minified (@media(max-width:600px)) forms. $mediaBlocks = ''; if (preg_match_all('/@media\s*[^{]*\{(?:[^{}]*\{[^{}]*\})*[^{}]*\}/s', $css, $mediaMatches)) { $mediaBlocks = implode("\n", $mediaMatches[0]); } $inliner = new \FluentEmogrifier\Vendor\TijsVerkoyen\CssToInlineStyles\CssToInlineStyles(); $result = $inliner->convert($html, $css); // Re-inject @media blocks for responsive email support if ($mediaBlocks) { $styleTag = ''; if (stripos($result, '') !== false) { $result = str_ireplace('', $styleTag . '', $result); } elseif (stripos($result, '