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.Data

Style parser options.

imageDirs: list[str]

Directories from which icons can be loaded in the untrusted mode.

strict: bool

Raise an error on invalid properties and values, instead of logging and skipping them.

trusted: bool

The style comes from a trusted source (the configuration). Only trusted styles can load icons from URLs and arbitrary files.

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. None values 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.strict is 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.strict is set.