| 226 | register_namespace("", "http://www.w3.org/2000/svg") |
| 227 | |
| 228 | def svg_split(f): |
| 229 | x = ElementTree(file=f) |
| 230 | svg = x.getroot() |
| 231 | resources = [] |
| 232 | for child in svg: |
| 233 | if child.tag == "{http://www.w3.org/2000/svg}g": |
| 234 | root = Element(svg.tag, svg.attrib) |
| 235 | n = ElementTree(root) |
| 236 | for r in resources + [child]: |
| 237 | root.append(r) |
| 238 | b = BytesIO() |
| 239 | n.write(b, xml_declaration=True, encoding="utf-8", method="xml") |
| 240 | yield b.getvalue() |
| 241 | else: |
| 242 | resources.append(child) |
| 243 | |
| 244 | if output_format == "svg": |
| 245 | return svg_bytes |