gws.lib.style.parser¶
CSS style parser.
Source code: gws.lib.style.parser
Module Contents¶
- class gws.lib.style.parser.Options(*args, **kwargs)¶
Bases:
gws.DataStyle parser options.
- gws.lib.style.parser.parse_dict(d: dict, opts: Options) dict¶
Parse a dict of CSS properties into style values.
Property names are normalized: dashes become underscores and a leading
__(from--) is removed.Nonevalues are skipped. The result contains defaults for all values not given.- Parameters:
d – A dict of CSS property names and values.
opts – Parser options.
- Returns:
A dict of style values.
- Raises:
gws.Error – If a property or value is invalid and
opts.strictis set.
- gws.lib.style.parser.parse_text(text: str, opts: Options) dict¶
Parse CSS text into style values.
- Parameters:
text – CSS declarations like
'a: b; c: d; ...', without a selector and braces.opts – Parser options.
- Returns:
A dict of style values.
- Raises:
gws.Error – If a property or value is invalid and
opts.strictis set.