Php library which determines which css is used from html snippets. It is used in jandc/critical-css to automatically and dynamically determine critical css on a per page basis.
composer require jandc/css-from-html-extractor
use CSSFromHTMLExtractor\Twig\Extension as ExtractorExtension;
$extension = new ExtractorExtension()
$extension->addBaseRules('path/to/css');
/** @var Twig_Environment $twig */
$twig->addExtension($extension);
{% fold %}
<div class="my-class">
...
</div>
{% endfold %}
$extension = $twigEnvironment->getExtension(ExtractorExtension::class);
$extension->buildCriticalCssFromSnippets();
$cssFromHTMLExtractor = new CssFromHTMLExtractor();
$cssFromHTMLExtractor->addBaseRules('path/to/css');
$cssFromHTMLExtractor->addHtmlToStore($rawHtml);
$extractedCss = $cssFromHTMLExtractor->buildExtractedRuleSet();