Created
January 5, 2018 01:19
-
-
Save jbn/2afd54b0135c2a65ac906ec4c9d58a70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml.etree import fromstring, tostring | |
def hatch_safe_svg(data): | |
# rsvg-convert doesn't resolve <pattern> fills from #fragment | |
# URIs if they occur downfile from the usage. This makes sure | |
# definitions come first. | |
doc = fromstring(data) | |
defs = [el for el in doc.getchildren() | |
if el.tag == "{http://www.w3.org/2000/svg}defs"] | |
for defn in defs: | |
doc.remove(defn) | |
doc.insert(0, defn) | |
return tostring(doc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment