@mbostock
Building a better computational medium. Founder @observablehq. Creator @d3. Former @nytgraphics. Pronounced BOSS-tock.
Published
4 forks
125 Likes
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Changed
serialize = { const xmlns = "http://www.w3.org/2000/xmlns/"; const xlinkns = "http://www.w3.org/1999/xlink"; const svgns = "http://www.w3.org/2000/svg"; return function serialize(svg) { svg = svg.cloneNode(true);
+
const fragment = window.location.href + "#"; const walker = document.createTreeWalker(svg, NodeFilter.SHOW_ELEMENT, null, false); while (walker.nextNode()) { for (const attr of walker.currentNode.attributes) { if (attr.value.includes(fragment)) { attr.value = attr.value.replace(fragment, "#"); } } }
svg.setAttributeNS(xmlns, "xmlns", svgns); svg.setAttributeNS(xmlns, "xmlns:xlink", xlinkns); const serializer = new window.XMLSerializer; const string = serializer.serializeToString(svg); return new Blob([string], {type: "image/svg+xml"}); }; }
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell