Created
November 9, 2024 04:00
-
-
Save tsibley/fb78fb8c6c6db1a9dea7473c606f5868 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
import xml.etree.ElementTree as ET | |
from sys import argv, stdin, stdout | |
layer = argv[1] | |
doc = ET.parse(stdin) | |
root = doc.getroot() | |
for g in root.findall(".//{http://www.w3.org/2000/svg}g[@id]"): | |
id = g.get("id") | |
if id and id.startswith("layer-") and id not in {"layer-base", f"layer-{layer}"}: | |
root.remove(g) | |
doc.write(stdout, encoding = "unicode", xml_declaration = True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
doesn't preserve formatting, namespace names, etc. so less helpful than the alternative yq + jq approach.