Racket
svg/svg resolves a full CSS cascade for both paint properties
(fill, stroke, opacity, ...) and SVG2’s "geometry properties"
(cx, r, x, width, d, ...) — inline style="",
<style> stylesheet rules (matched by type/class/id/universal/attribute
selectors, descendant and child combinators, with real CSS specificity and
!important), and plain presentation attributes, in that priority order.
That whole mechanism is internal (it depends on parsing machinery from the
parsers/css package and on rendering-time context — the current
element’s ancestor chain — that only exists during an active render),
except for one small, standalone piece exported because it’s independently
useful: parsing an inline style="" attribute’s own text into a lookup
table.
Parses an inline
style="..." attribute’s value —
a semicolon-separated
list of
property: value declarations —
into a hash from (lowercased,
trimmed) property name to
(cons value important?), tracking a
trailing
!important on any declaration the same way a
<style>
stylesheet rule’s own declarations are tracked internally (so an inline
!important can be recognized as outranking even a stylesheet’s own
!important rule, which is how the full cascade orders them). A
malformed declaration (missing a colon, empty) is skipped rather than
raising.
Example:
| > (parse-style-attr "fill: red; stroke: blue !important") |
'#hash(("fill" . ("red" . #f)) ("stroke" . ("blue" . #t))) |