From aec2019e073136069d18f53d2d744f2954b23228 Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Sun, 5 Apr 2009 11:44:47 -0500 Subject: [PATCH] Minor improvements, use in-testing for referencing props --- scour.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scour.py b/scour.py index 1e846b9..8cf8dde 100755 --- a/scour.py +++ b/scour.py @@ -121,8 +121,9 @@ def findReferencedElements(node,ids={}): # now get all style properties and the fill, stroke, filter attributes styles = string.split(node.getAttribute('style'),';') # TODO: can i reuse this list below in the if/or check? - for attr in ['fill', 'stroke', 'filter', 'clip-path', 'mask', - 'marker-start', 'marker-end', 'marker-mid']: + referencingProps = ['fill', 'stroke', 'filter', 'clip-path', 'mask', 'marker-start', + 'marker-end', 'marker-mid'] + for attr in referencingProps: styles.append( string.join([attr,node.getAttribute(attr)],':') ) for style in styles: @@ -130,9 +131,7 @@ def findReferencedElements(node,ids={}): if(len(propval) == 2): prop = propval[0].strip() val = propval[1].strip() - if( (prop=='fill' or prop=='stroke' or prop=='filter' or prop=='clip-path' - or prop=='mask' or prop=='marker-start' or prop=='marker-end' or prop=='marker-mid') - and val != '' and val[0:5] == 'url(#' ): + if( prop in referencingProps and val != '' and val[0:5] == 'url(#' ): id = val[5:val.find(')')] if( ids.has_key(id) ): ids[id] += 1 @@ -158,7 +157,8 @@ def removeUnreferencedIDs(referencedIDs, identifiedElements): if( referencedIDs.has_key(id) == False ): node.removeAttribute('id') # now remove the element from our list of elements with ids - del identifiedElements[id] + # not necessary if we're calculating the array again every time +# del identifiedElements[id] numIDsRemoved += 1 num += 1 return num