Skip to content

Commit

Permalink
fix: only mutate IDs in the output SVG, not the input (#122)
Browse files Browse the repository at this point in the history
Fixes #85
  • Loading branch information
felixfbecker authored Apr 17, 2021
1 parent b6c4cb6 commit 7f0ba02
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ export function handleSvgElement(element: SVGElement, context: SvgTraversalConte
)
break
}

// Make all IDs unique
for (const descendant of element.querySelectorAll('[id]')) {
descendant.id = context.idPrefix + descendant.id
}
} else {
// Clone element
if (isSVGAnchorElement(element) && !context.options.keepLinks) {
Expand Down Expand Up @@ -155,6 +150,11 @@ export function handleSvgElement(element: SVGElement, context: SvgTraversalConte
}
}

// Make sure all IDs are unique
if (elementToAppend.id) {
elementToAppend.id = context.idPrefix + elementToAppend.id
}

context.currentSvgParent.append(elementToAppend)
for (const child of element.childNodes) {
handleSvgNode(child, { ...context, currentSvgParent: elementToAppend })
Expand Down

0 comments on commit 7f0ba02

Please sign in to comment.