Minor improvements, use in-testing for referencing props
This commit is contained in:
parent
7864455c13
commit
aec2019e07
1 changed files with 6 additions and 6 deletions
12
scour.py
12
scour.py
|
|
@ -121,8 +121,9 @@ def findReferencedElements(node,ids={}):
|
||||||
# now get all style properties and the fill, stroke, filter attributes
|
# now get all style properties and the fill, stroke, filter attributes
|
||||||
styles = string.split(node.getAttribute('style'),';')
|
styles = string.split(node.getAttribute('style'),';')
|
||||||
# TODO: can i reuse this list below in the if/or check?
|
# TODO: can i reuse this list below in the if/or check?
|
||||||
for attr in ['fill', 'stroke', 'filter', 'clip-path', 'mask',
|
referencingProps = ['fill', 'stroke', 'filter', 'clip-path', 'mask', 'marker-start',
|
||||||
'marker-start', 'marker-end', 'marker-mid']:
|
'marker-end', 'marker-mid']
|
||||||
|
for attr in referencingProps:
|
||||||
styles.append( string.join([attr,node.getAttribute(attr)],':') )
|
styles.append( string.join([attr,node.getAttribute(attr)],':') )
|
||||||
|
|
||||||
for style in styles:
|
for style in styles:
|
||||||
|
|
@ -130,9 +131,7 @@ def findReferencedElements(node,ids={}):
|
||||||
if(len(propval) == 2):
|
if(len(propval) == 2):
|
||||||
prop = propval[0].strip()
|
prop = propval[0].strip()
|
||||||
val = propval[1].strip()
|
val = propval[1].strip()
|
||||||
if( (prop=='fill' or prop=='stroke' or prop=='filter' or prop=='clip-path'
|
if( prop in referencingProps and val != '' and val[0:5] == 'url(#' ):
|
||||||
or prop=='mask' or prop=='marker-start' or prop=='marker-end' or prop=='marker-mid')
|
|
||||||
and val != '' and val[0:5] == 'url(#' ):
|
|
||||||
id = val[5:val.find(')')]
|
id = val[5:val.find(')')]
|
||||||
if( ids.has_key(id) ):
|
if( ids.has_key(id) ):
|
||||||
ids[id] += 1
|
ids[id] += 1
|
||||||
|
|
@ -158,7 +157,8 @@ def removeUnreferencedIDs(referencedIDs, identifiedElements):
|
||||||
if( referencedIDs.has_key(id) == False ):
|
if( referencedIDs.has_key(id) == False ):
|
||||||
node.removeAttribute('id')
|
node.removeAttribute('id')
|
||||||
# now remove the element from our list of elements with ids
|
# 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
|
numIDsRemoved += 1
|
||||||
num += 1
|
num += 1
|
||||||
return num
|
return num
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue