Class StyleAttribute
java.lang.Object
dev.jcputney.mjml.css.StyleAttribute
Parses, merges, and serializes CSS inline style attributes. Handles specificity-aware merging
where higher specificity or later source order wins, and
!important declarations take
precedence.-
Method Summary
Modifier and TypeMethodDescriptionstatic List<CssDeclaration> merge(List<CssDeclaration> existing, List<CssDeclaration> incoming, CssSpecificity incomingSpec) Merges new declarations into existing inline style declarations.static List<CssDeclaration> Parses an inline style string into a list of declarations.static Stringserialize(List<CssDeclaration> declarations) Serializes a list of declarations back to an inline style string.
-
Method Details
-
parse
Parses an inline style string into a list of declarations. Example: "color: red; font-size: 14px" -> [CssDeclaration("color","red",false), ...]- Parameters:
style- the inline CSS style string to parse, ornull- Returns:
- a list of parsed
CssDeclarationinstances (empty if input is null or blank)
-
serialize
Serializes a list of declarations back to an inline style string.- Parameters:
declarations- the list of CSS declarations to serialize- Returns:
- the serialized inline style string, or an empty string if declarations is null or empty
-
merge
public static List<CssDeclaration> merge(List<CssDeclaration> existing, List<CssDeclaration> incoming, CssSpecificity incomingSpec) Merges new declarations into existing inline style declarations. Rules:- If existing has !important and new doesn't, existing wins
- If new has !important, new wins
- If neither or both have !important, new wins (later source order)
- Parameters:
existing- the current inline style declarationsincoming- the new declarations to mergeincomingSpec- specificity of the incoming rule (unused if inline=true)- Returns:
- merged declarations list
-