g_tag_is_unmergeable: consider <g> tags with ids unmergeable

If someone gave it an ID and we have not stripped it, then it is
probably important and can alter the output somehow if we fiddle merge
it into another node (or discard the <g> node with an ID).

Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
Niels Thykier 2020-05-17 20:18:11 +00:00
parent eb582fe44c
commit 7e917c9ca0
No known key found for this signature in database
GPG key ID: A65B78DBE67C7AAC

View file

@ -1017,8 +1017,12 @@ def removeDescriptiveElements(doc, options):
def g_tag_is_unmergeable(node):
"""Check if a <g> tag can be merged or not
<g> tags with a title or descriptions should generally be left alone.
Generally, there are two types of <g> tags that should be left alone:
* <g> tags with a title or descriptions
* <g> tags that has an ID
"""
if node.getAttribute('id') != '':
return True
return any(True for n in node.childNodes if n.nodeType == Node.ELEMENT_NODE
and n.nodeName in ('title', 'desc') and n.namespaceURI == NS['SVG'])