Skip to content

Commit

Permalink
Downloading SVG makes links non functional #319
Browse files Browse the repository at this point in the history
  • Loading branch information
Farcasut authored Dec 13, 2024
1 parent 24d23c9 commit 8e75128
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,32 @@ define('diagram-link-editor', [
// Do nothing.
}

// Override the Graph.updateSvgLinks method to ensure that the links are preserved in the final SVG.
// We need to directly modify the original method because drawio does not provide a parameter to override the default
// behavior or a smaller method that only performs the replacement.
Graph.prototype.updateSvgLinks = function (node, target, removeCustom) {
var links = node.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (links[i].getAttribute('target') == null) {
var href = links[i].getAttribute('href');
if (href == null) {
href = links[i].getAttribute('xlink:href');
}

if (href != null) {
if (target != null && /^https?:\/\//.test(href)) {
// If the href starts with http or https, set the target attribute.
links[i].setAttribute('target', target);
} else if (this.isCustomLink(href)) {
// Handle custom links
let absoluteLink = $('<a/>').attr('href', diagramLinkHandler.getURLFromCustomLink(href)).prop('href');
links[i].setAttribute('href', absoluteLink);
}
}
}
}
};

// Overwrite Graph.getSvg in order to replace XWiki custom links with absolute URLs.
// Also fix the text fallback for viewers with no support for foreignObjects.
var originalGraphGetSVG = Graph.prototype.getSvg;
Expand Down

0 comments on commit 8e75128

Please sign in to comment.