From 7e917c9ca051adf8cfedb8b0e307aef5e5dfc634 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 17 May 2020 20:18:11 +0000 Subject: [PATCH] g_tag_is_unmergeable: consider 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 node with an ID). Signed-off-by: Niels Thykier --- scour/scour.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scour/scour.py b/scour/scour.py index 76f710d..8f0d532 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -1017,8 +1017,12 @@ def removeDescriptiveElements(doc, options): def g_tag_is_unmergeable(node): """Check if a tag can be merged or not - tags with a title or descriptions should generally be left alone. + Generally, there are two types of tags that should be left alone: + * tags with a title or descriptions + * 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'])