diff --git a/curator/static/js/study-editor.js b/curator/static/js/study-editor.js index 62bbf0f4f..8755a808f 100644 --- a/curator/static/js/study-editor.js +++ b/curator/static/js/study-editor.js @@ -10493,8 +10493,31 @@ function updateSaveTreeViewLink() { $treeSVG.prepend( $treeStylesheet[0].outerHTML ); } - // encode the current SVG - var base64src = b64EncodeUnicode( $treeSVG[0].outerHTML ); + // Serialize the main SVG node (converting HTML entities to Unicode); first, we + // create a temporary XML document + var serializer = new XMLSerializer(); + var tempXMLDoc = document.implementation.createDocument( + null, // desired namespace, or null + "svg", // name of top-level element + null // desired doctype, or null + ) + // replace its boring top-level element with our SVG + // (cloned from the original, else it disappears!) + var htmlNode = $treeSVG.clone()[0]; + tempXMLDoc.documentElement.replaceWith(htmlNode); + var xmlNode = tempXMLDoc.documentElement; + var svgString = serializer.serializeToString(xmlNode); + + /* Alternate implmentation (fails in Safari) + var serializer = new XMLSerializer(); + var node = $treeSVG[0]; + var svgString = serializer.serializeToString(node); + // Safari may still fail to convert HTML entities :-/ + svgString = svgString.replace(/ /gi,' '); + */ + + // encode it for safe use in a data URI + var base64src = b64EncodeUnicode(svgString); var $saveLink = $('#save-tree-view'); $saveLink.attr('href', 'data:image/svg+xml;base64,\n'+ base64src);