From 7f0ba02af8d1277ac21a5bc3a817d0f7d2788b32 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Sun, 18 Apr 2021 00:31:30 +0200 Subject: [PATCH] fix: only mutate IDs in the output SVG, not the input (#122) Fixes #85 --- src/svg.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/svg.ts b/src/svg.ts index 3655e52f..45005c54 100644 --- a/src/svg.ts +++ b/src/svg.ts @@ -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) { @@ -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 })