Skip to content

Instantly share code, notes, and snippets.

@aquaductape
Last active December 21, 2022 01:15
Show Gist options
  • Save aquaductape/73a641649b8004e107a067648ac2c6e9 to your computer and use it in GitHub Desktop.
Save aquaductape/73a641649b8004e107a067648ac2c6e9 to your computer and use it in GitHub Desktop.
function namespaceSVGId(svg, namespace) {
svg = svg.replace(/id="(.*?)"/g, (_, p1) => {
return `id="${namespace}-${p1}"`;
});
svg = svg.replace(/xlink:href="#(.*?)"/g, (_, p1) => {
return `xlink:href="#${namespace}-${p1}"`;
});
svg = svg.replace(/mask="url\(#(.*?)\)"/g, (_, p1) => {
return `mask="url(#${namespace}-${p1})"`;
});
svg = svg.replace(/fill="url\(#(.*?)\)"/g, (_, p1) => {
return `fill="url(#${namespace}-${p1})"`;
});
svg = svg.replace(/filter="url\(#(.*?)\)"/g, (_, p1) => {
return `filter="url(#${namespace}-${p1})"`;
});
return svg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment