gws.lib.svg.element¶
SVG element construction and sanitizing.
Source code: gws.lib.svg.element
Module Contents¶
- gws.lib.svg.element.fragment_to_element(fragment: list[gws.XmlElement], atts: dict = None) gws.XmlElement¶
Wrap an SVG fragment in an
<svg>element.Elements are sorted by their
z-indexattribute, so that labels come after geometries.- Parameters:
fragment – SVG elements.
atts – Attributes of the
<svg>element.
- Returns:
The
<svg>element.
- gws.lib.svg.element.fragment_to_image(fragment: list[gws.XmlElement], size: gws.Size, mime_type=gws.lib.mime.PNG) gws.lib.image.Image¶
Render an SVG fragment as a raster image.
- Parameters:
fragment – SVG elements.
size – Image size in pixels.
mime_type – Image mime type.
- Returns:
The image.
- gws.lib.svg.element.normalize_element(el: gws.XmlElement) gws.XmlElement¶
Remove unsafe content from an SVG element and normalize tag and attribute names.
Only allowed tags and attributes are kept. Attribute values must match a pattern for that attribute, and values that look like URLs (
data:,http:,javascript:etc.) are removed. Text content is kept only for text tags. The element itself is turned into an<svg>element.- Parameters:
el – An SVG element.
- Returns:
A new, normalized
<svg>element.
- gws.lib.svg.element.normalize_fragment(fragment: list[gws.XmlElement]) list[gws.XmlElement]¶
Remove unsafe content from an SVG fragment and normalize tag and attribute names.
Elements with tags that are not allowed are removed, together with their children.
- Parameters:
fragment – SVG elements.
- Returns:
A list of normalized elements.