Using the python library feedparser
, which includes SVG sanitization, I wrote this function which annoyingly wraps svg in a single RSS item in order to parse it.
import feedparser
def sanitize_svg(svg):
feed = """- """ + svg + """
"""
parsed = feedparser.parse(feed)
return parsed.entries[0].description.encode('utf-8')
Although made for whitelisting elements with security in mind, it also reduces the svg size a fair bit.