• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / CssInliner::extractImportAndCharsetRules() – Extracts `@import` and `@charset` rules from the supplied CSS. These rules must not be preceded by any other rules, or they will be ignored. (From the CSS 2.1 specification: "CSS 2.1 user agents must ignore any ‘@import’ rule that occurs inside a block or after any non-ignored statement other than an @charset or an @import rule." Note also that `@charset` is case sensitive whereas `@import` is not.)

You appear to be a bot. Output may be restricted

Description

Extracts @import and @charset rules from the supplied CSS. These rules must not be preceded by any other rules, or they will be ignored. (From the CSS 2.1 specification: "CSS 2.1 user agents must ignore any '@import' rule that occurs inside a block or after any non-ignored statement other than an @charset or an @import rule." Note also that @charset is case sensitive whereas @import is not.)

Usage

$string[] = CssInliner::extractImportAndCharsetRules( $css );

Parameters

$css
( string ) required – CSS with comments removed

Returns

string[] The first element is the CSS with the valid @import and @charset rules removed. The second element contains a concatenation of the valid @import rules, each followed by whatever whitespace followed it in the original CSS (so that either unminified or minified formatting is preserved); if there were no @import rules, it will be an empty string. The (valid) @charset rules are discarded.

Source

File name: woocommerce/vendor/pelago/emogrifier/src/Emogrifier/CssInliner.php
Lines:

1 to 23 of 23
    private function extractImportAndCharsetRules($css)
    {
        $possiblyModifiedCss = $css;
        $importRules = '';

        while (
            \preg_match(
                '/^\\s*+(@((?i)import(?-i)|charset)\\s[^;]++;\\s*+)/',
                $possiblyModifiedCss,
                $matches
            )
        ) {
            list($fullMatch, $atRuleAndFollowingWhitespace, $atRuleName) = $matches;

            if (\strtolower($atRuleName) === 'import') {
                $importRules .= $atRuleAndFollowingWhitespace;
            }

            $possiblyModifiedCss = \substr($possiblyModifiedCss, \strlen($fullMatch));
        }

        return [$possiblyModifiedCss, $importRules];
    }
 

 View on GitHub View on Trac

Published: 6th April 2020 | Last updated: 6th April 2020

Primary Sidebar

Information

Function name: CssInliner::extractImportAndCharsetRules
Class ref: CssInliner
Plugin ref: WooCommerce
Version: 5.1.0
Sourcefile: vendor/pelago/emogrifier/src/Emogrifier/CssInliner.php
File ref: vendor/pelago/emogrifier/src/Emogrifier/CssInliner.php
Deprecated?: No
API Letters: C,E

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites