Warning: This class has been deprecated. Will be removed for version 4.0.0. Please use the CssInliner class instead.
Emogrifier
This class provides functions for converting CSS styles into inline style attributes in your HTML code.
Description Description
For more information, please see the README.md file.
Source Source
File: vendor/pelago/emogrifier/src/Emogrifier.php
Methods Methods
- __construct
- addAllowedMediaType — Marks a media query type to keep.
- addContentTypeMetaTag — Adds a Content-Type meta tag for the charset.
- addExcludedSelector — Adds a selector to exclude nodes from emogrification.
- addStyleElementToDocument — Adds a style element with $css to $this->domDocument.
- addUnprocessableHtmlTag — Marks a tag for removal.
- assertExistenceOfHtml — Checks that some HTML has been set, and throws an exception otherwise.
- attributeValueIsImportant — Checks whether $attributeValue is marked as !important.
- clearAllCaches — Clears all caches.
- copyInlinableCssToStyleAttribute — Copies $cssRule into the style attribute of $node.
- copyUninlinableCssToStyleNode — Applies $cssRules to $this->domDocument, limited to the rules that actually apply to the document, by placing them as CSS in a `` element.
- createRawDomDocument — Creates a DOMDocument instance from the given HTML and stores it in $this->domDocument.
- createUnifiedDomDocument — Creates a DOM document from the given HTML and stores it in $this->domDocument.
- disableInlineStyleAttributesParsing — Disables the parsing of inline styles.
- disableStyleBlocksParsing — Disables the parsing of blocks.
- emogrify — Applies $this->css to the given HTML and returns the HTML with the CSS applied.
- emogrifyBodyContent — Applies $this->css to the given HTML and returns only the HTML content within the tag.
- ensureDocumentType — Makes sure that the passed HTML has a document type.
- ensureExistenceOfBodyElement — Checks that $this->domDocument has a BODY element and adds it if it is missing.
- ensurePhpUnrecognizedSelfClosingTagsAreXml — Makes sure that any self-closing tags not recognized as such by PHP's DOMDocument implementation have a self-closing slash.
- existsMatchForCssSelector — Checks whether there is at least one matching element for $cssSelector.
- existsMatchForSelectorInCssRule — Checks whether there is at least one matching element for the CSS selector contained in the `selector` element of the provided CSS rule.
- 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.)
- fillStyleAttributesWithMergedStyles — Merges styles from styles attributes and style nodes and applies them to the attribute nodes
- generateStyleStringFromDeclarationsArrays — This method merges old or existing name/value array with new name/value array and then generates a string of the combined style suitable for placing inline.
- generateStyleStringFromSingleDeclarationsArray — Generates a CSS style string suitable to be used inline from the $styleDeclarations property => value array.
- getAllNodesWithStyleAttribute — Returns a list with all DOM nodes that have a style attribute.
- getBodyElement — Returns the BODY element.
- getCssFromAllStyleNodes — Returns CSS content.
- getCssRuleMatches — Parses a string of CSS into the media query, selectors and declarations for each ruleset in order.
- getCssSelectorPrecedence
- getDomDocument — Provides access to the internal DOMDocument representation of the HTML in its current state.
- getHeadElement — Returns the HEAD element.
- getNodesToExclude — Find the nodes that are not to be emogrified.
- handleXpathQueryWarnings — Handles invalid xPath expression warnings, generated during the process() method, during querying \DOMDocument and trigger an \InvalidArgumentException with an invalid selector or \RuntimeException, depending on the source of the warning.
- matchClassAttributes
- matchClassAttributesInline
- matchIdAttributes
- normalizeStyleAttributes — Normalizes the value of the "style" attribute and saves it.
- normalizeStyleAttributesOfAllNodes — Parses the document and normalizes all existing CSS attributes.
- parseCssDeclarationsBlock — Parses a CSS declaration block into property name/value pairs.
- parseCssRules — Extracts and parses the individual rules from a CSS string.
- parseNth
- prepareHtmlForDomConversion — Returns the HTML with added document type, Content-Type meta tag, and self-closing slashes, if needed, ensuring that the HTML will be good for creating a DOM document from it.
- process — Applies $this->css to $this->domDocument.
- purgeVisitedNodes — Purges the visited nodes.
- removeAllowedMediaType — Drops a media query type from the allowed list.
- removeCssComments — Removes comments from the supplied CSS.
- removeExcludedSelector — No longer excludes the nodes matching this selector from emogrification.
- removeImportantAnnotationFromAllInlineStyles — Searches for all nodes with a style attribute and removes the "!important" annotations out of the inline style declarations, eventually by rearranging declarations.
- removeImportantAnnotationFromNodeInlineStyle — Removes the "!important" annotations out of the inline style declarations, eventually by rearranging declarations.
- removeSelfClosingTagsClosingTags — Eliminates any invalid closing tags for void elements from the given HTML.
- removeUnmatchablePseudoComponents — Removes pseudo-elements and dynamic pseudo-classes from a CSS selector, replacing them with "*" if necessary.
- removeUnprocessableHtmlTag — Drops a tag from the removal list.
- removeUnprocessableTags — Removes empty unprocessable tags from the DOM document.
- render — Renders the normalized and processed HTML.
- renderBodyContent — Renders the content of the BODY element of the normalized and processed HTML.
- replaceUnmatchableNotComponent — Helps `removeUnmatchablePseudoComponents()` replace or remove a selector `:not(.
- setCss — Sets the CSS to merge with the HTML.
- setDebug — Sets the debug mode.
- setHtml — Sets the HTML to process.
- sortBySelectorPrecedence
- splitCssAndMediaQuery — Splits input CSS code into an array of parts for different media queries, in order.
- translateCssToXpath — Maps a CSS selector to an XPath query string.
- translateCssToXpathPass — Flexibly translates the CSS selector $trimmedLowercaseSelector to an xPath selector.
- translateCssToXpathPassInline — Flexibly translates the CSS selector $trimmedLowercaseSelector to an xPath selector for inline usage.
- translateCssToXpathPassWithMatchClassAttributesCallback — Flexibly translates the CSS selector $trimmedLowercaseSelector to an xPath selector while using $matchClassAttributesCallback as to match the class attributes.
- translateNthChild
- translateNthOfType