Skip to content

Instantly share code, notes, and snippets.

@anthrotype
Created June 10, 2020 17:26
Show Gist options
  • Save anthrotype/3ba06b0905888d747ee0e5260863bb68 to your computer and use it in GitHub Desktop.
Save anthrotype/3ba06b0905888d747ee0e5260863bb68 to your computer and use it in GitHub Desktop.
strip unused <symbol> elements in noto-emoji svgs
import sys
import glob
from lxml import etree
svg_directory = sys.argv[1]
noid_files = set()
id_files = set()
for filename in glob.glob(f"{svg_directory}/*.svg"):
tree = etree.parse(filename)
svg = tree.getroot()
for symbol in svg.xpath(
".//svg:symbol", namespaces={"svg": "http://www.w3.org/2000/svg"}
):
if "id" not in symbol.attrib:
symbol.getparent().remove(symbol)
noid_files.add(filename)
with open(filename, "wb") as fp:
fp.write(etree.tostring(tree))
else:
id_files.add(filename)
print(f"Files containing <symbol> without 'id' attribute: {len(noid_files)}")
print(noid_files)
print()
print(f"Files containing <symbol> with 'id' attribute: {len(id_files)}")
print(id_files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment