Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix entities in SVG download #1130

Merged
merged 7 commits into from
Jun 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions curator/static/js/study-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down