Premailex v0.1.3 Premailex.CSSParser View Source
Module that handles CSS parsing with naive Regular Expression.
Link to this section Summary
Functions
Merges CSS rules
Parses a CSS string into a map
Parses a CSS rules string into a map
Transforms CSS map or list into string
Link to this section Functions
Merges CSS rules.
Examples
iex> "p {background-color: #fff !important; color: #000;} p {background-color: #000;}" |> Premailex.CSSParser.parse() |> Premailex.CSSParser.merge()
[%{directive: "background-color", value: "#fff !important", important?: true, specificity: 1},
%{directive: "color", value: "#000", important?: false, specificity: 1}]
Parses a CSS string into a map.
Examples
iex> Premailex.CSSParser.parse("body { background-color: #fff !important; color: red; }")
[%{rules: [%{directive: "background-color", value: "#fff !important", important?: true},
%{directive: "color", value: "red", important?: false}],
selector: "body",
specificity: 1}]
Parses a CSS rules string into a map.
Examples
iex> Premailex.CSSParser.parse_rules("background-color: #fff; color: red;")
[%{directive: "background-color", value: "#fff", important?: false},
%{directive: "color", value: "red", important?: false}]
Transforms CSS map or list into string.
Examples
iex> Premailex.CSSParser.to_string([%{directive: "background-color", value: "#fff"}, %{directive: "color", value: "#000"}])
"background-color:#fff;color:#000;"
iex> Premailex.CSSParser.to_string(%{directive: "background-color", value: "#fff"})
"background-color:#fff;"