Class CssParser

java.lang.Object
dev.jcputney.mjml.css.CssParser

public final class CssParser extends Object
Parses CSS text into a list of CssRule objects.

Handles:

  • Regular rules (selector { declarations })
  • Comments (/* ... */)
  • @-rules (@media, @font-face, @keyframes) which are preserved but not parsed as rules

At-rules that should not be inlined are collected separately so they can be placed back into <style> blocks in the output.

  • Method Details

    • parse

      public static CssParser.ParseResult parse(String css)
      Parses CSS text into rules and preserved at-rules.
      Parameters:
      css - the CSS text to parse
      Returns:
      parse result with rules and preserved at-rules
    • parseRules

      public static List<CssRule> parseRules(String css)
      Parses CSS text and returns only the inlineable rules (convenience method).
      Parameters:
      css - the CSS text to parse
      Returns:
      the list of parsed CSS rules suitable for inlining