From d47751818846157e955f6993e2f086b2fd0e1790 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Mon, 29 Aug 2016 02:13:09 +0200 Subject: [PATCH] Only attempt to group elements that the content model allows to be children of a when `--create-groups` is specified. (before it could happen that e.g. `tspan` elements were grouped, which is invalid, see issues #96 and #97) --- scour/scour.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scour/scour.py b/scour/scour.py index 5452b7d..abde59b 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -1032,7 +1032,24 @@ def createGroupsForCommonAttributes(elem): while curChild >= 0: childNode = elem.childNodes.item(curChild) - if childNode.nodeType == 1 and childNode.getAttribute(curAttr) != '': + if childNode.nodeType == 1 and childNode.getAttribute(curAttr) != '' and \ + childNode.nodeName in [ + # only attempt to group elements that the content model allows to be children of a + + # SVG 1.1 (see https://www.w3.org/TR/SVG/struct.html#GElement) + 'animate', 'animateColor', 'animateMotion', 'animateTransform', 'set', # animation elements + 'desc', 'metadata', 'title', # descriptive elements + 'circle', 'ellipse', 'line', 'path', 'polygon', 'polyline', 'rect', # shape elements + 'defs', 'g', 'svg', 'symbol', 'use', # structural elements + 'linearGradient', 'radialGradient', # gradient elements + 'a', 'altGlyphDef', 'clipPath', 'color-profile', 'cursor', 'filter', + 'font', 'font-face', 'foreignObject', 'image', 'marker', 'mask', + 'pattern', 'script', 'style', 'switch', 'text', 'view', + + # SVG 1.2 (see https://www.w3.org/TR/SVGTiny12/elementTable.html) + 'animation', 'audio', 'discard', 'handler', 'listener', + 'prefetch', 'solidColor', 'textArea', 'video' + ]: # We're in a possible run! Track the value and run length. value = childNode.getAttribute(curAttr) runStart, runEnd = curChild, curChild