Remove empty defs, metadata, g elements
This commit is contained in:
parent
6cb18b63ed
commit
18d6566520
1 changed files with 17 additions and 0 deletions
17
scour.py
17
scour.py
|
|
@ -300,6 +300,23 @@ while bContinueLooping:
|
||||||
|
|
||||||
numStylePropsFixed = repairStyle(doc.documentElement)
|
numStylePropsFixed = repairStyle(doc.documentElement)
|
||||||
|
|
||||||
|
# remove empty defs, metadata, g
|
||||||
|
# NOTE: these elements will be removed even if they have (invalid) text nodes
|
||||||
|
elemsToRemove = []
|
||||||
|
for tag in ['defs', 'metadata', 'g'] :
|
||||||
|
for elem in doc.documentElement.getElementsByTagNameNS(NS['SVG'], tag) :
|
||||||
|
removeElem = not elem.hasChildNodes()
|
||||||
|
if removeElem == False :
|
||||||
|
for child in elem.childNodes :
|
||||||
|
print child.nodeType,
|
||||||
|
if child.nodeType in [1, 4, 8] :
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
removeElem = True
|
||||||
|
if removeElem :
|
||||||
|
elem.parentNode.removeChild(elem)
|
||||||
|
numElemsRemoved += 1
|
||||||
|
|
||||||
# output the document
|
# output the document
|
||||||
doc.documentElement.writexml(output)
|
doc.documentElement.writexml(output)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue