Don't remove unreferenced defs if --keep-unreferenced-defs is specified (#62)

* Don't remove unreferenced defs if `--keep-unreferenced-defs` is specified
(fixes #18)

* Add unittests for previous commit
This commit is contained in:
Eduard Braun 2016-08-14 18:52:55 +02:00 committed by GitHub
parent 3299f8f6e0
commit fe2884c3e8
3 changed files with 51 additions and 1 deletions

View file

@ -623,7 +623,9 @@ def removeUnreferencedElements(doc, keepDefs):
for id in identifiedElements:
if not id in referencedIDs:
goner = identifiedElements[id]
if goner != None and goner.parentNode != None and goner.nodeName in removeTags:
if (goner != None and goner.nodeName in removeTags
and goner.parentNode != None
and goner.parentNode.tagName != 'defs'):
goner.parentNode.removeChild(goner)
num += 1
numElemsRemoved += 1