Mess around with SVG styling, style, replace=False)

Add to or replace the CSS style in an SVG file.

  • svgfile (str) – Path to an SVG file or an SVG string.
  • newstyle (str) – CSS string, or path to CSS file.
  • replace (bool) – If true, replace the existing CSS with newstyle (default: False), properties)

Build a class string for an element using the properties. Class names take the form CLASS_PROPERTY. If a given class isn’t found in properties, the class name is added (e.g. CLASS).

  • classes (Sequence) – Column names to include in the class list
  • properties (dict) – A single feature’s properties.

(list) class names, style=None)

Inline the CSS rules in an SVG. This is a very rough operation, and full css precedence rules won’t be respected. Ignores sibling operators (~, +), pseudo-selectors (e.g. :first-child), and attribute selectors (e.g. .foo[name=bar]). Works best with rules like:

  • .class
  • tag
  • tag.class
  • #layer .class
  • #layer tag
  • svg (string) – An SVG document.
  • css (string) – CSS to use, instead of the CSS in the <defs> element of the SVG.

Fetch a CSS string.

Parameters:style (str) – Either a CSS string or the path of a css file.

Make input safe of use in an svg ID or class field. Replaces blocks of whitespace with an underscore (_), deleted periods, number signs and double-quotes (.#"). If the first character isn’t an ascii letter, dash (-) or underscore (_), an underscore is added to the beginning.

Parameters:string (mixed) – Input to sanitize

Utilities for manipulating the DOM and applying styles to same

svgis.dom.apply_rule(doc, rule)

Apply a tinycss Rule to an ElementTree.Element (only tested on documents created by SVGIS).

  • doc (ElementTree.Element) – The svg document to scan.
  • rule (tinycss rule) – Rule to apply.

Wrap text in CDATA section.


Apply the SVG namespace to a tag, e.g. g to {}g.