Also shorten unused IDs when --shorten-ids is specified
This commit is contained in:
parent
df142a2f22
commit
3299f8f6e0
1 changed files with 52 additions and 46 deletions
|
|
@ -663,6 +663,9 @@ def shortenIDs(doc, prefix, unprotectedElements=None):
|
||||||
idList.sort(reverse=True)
|
idList.sort(reverse=True)
|
||||||
idList = [rid for count, rid in idList]
|
idList = [rid for count, rid in idList]
|
||||||
|
|
||||||
|
# Add unreferenced IDs to end of idList in arbitrary order
|
||||||
|
idList.extend([rid for rid in unprotectedElements if not rid in idList])
|
||||||
|
|
||||||
curIdNum = 1
|
curIdNum = 1
|
||||||
|
|
||||||
for rid in idList:
|
for rid in idList:
|
||||||
|
|
@ -712,8 +715,11 @@ def renameID(doc, idFrom, idTo, identifiedElements, referencedIDs):
|
||||||
definingNode.setAttribute("id", idTo)
|
definingNode.setAttribute("id", idTo)
|
||||||
del identifiedElements[idFrom]
|
del identifiedElements[idFrom]
|
||||||
identifiedElements[idTo] = definingNode
|
identifiedElements[idTo] = definingNode
|
||||||
|
num += len(idFrom) - len(idTo)
|
||||||
|
|
||||||
referringNodes = referencedIDs[idFrom]
|
# Update references to renamed node
|
||||||
|
referringNodes = referencedIDs.get(idFrom)
|
||||||
|
if referringNodes is not None:
|
||||||
|
|
||||||
# Look for the idFrom ID name in each of the referencing elements,
|
# Look for the idFrom ID name in each of the referencing elements,
|
||||||
# exactly like findReferencedElements would.
|
# exactly like findReferencedElements would.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue