Skip to content

Commit

Permalink
Merge pull request #70 from ileler/master
Browse files Browse the repository at this point in the history
Fix the problem that the use of br tag causes image export failure
  • Loading branch information
sidharthv96 authored Dec 20, 2020
2 parents e540ac2 + 19e64ac commit e477abb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/Links.svelte
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
onMount(async () => {});
const fixBrTag = (svg) => svg.replaceAll('<br>', '<br/>');
export const onDownloadPNG = (event) => {
var canvas = document.createElement('canvas');
const canvas = document.createElement('canvas');
const container = document.getElementById('container');
const svg = document.querySelector('#container svg');
const box = svg.getBoundingClientRect();
Expand All @@ -28,7 +30,7 @@
context.fillStyle = 'white';
context.fillRect(0, 0, canvas.width, canvas.height);
var image = new Image();
const image = new Image();
image.onload = function () {
context.drawImage(image, 0, 0, canvas.width, canvas.height);
Expand All @@ -40,9 +42,9 @@
a.click();
};
console.warn('SVG', container.innerHTML);
console.warn('SVG', fixBrTag(container.innerHTML));
image.src = `data:image/svg+xml;base64,${Base64.encode(
container.innerHTML
fixBrTag(container.innerHTML)
)}`;
event.stopPropagation();
event.preventDefault();
Expand All @@ -54,7 +56,7 @@
console.log('event', event.target);
const container = document.getElementById('container');
event.target.href = `data:image/svg+xml;base64,${Base64.encode(
container.innerHTML
fixBrTag(container.innerHTML)
)}`;
event.target.download = `mermaid-diagram-${moment().format(
'YYYYMMDDHHmmss'
Expand Down

0 comments on commit e477abb

Please sign in to comment.