diff --git a/webapp/src/routes/note/[id].svelte b/webapp/src/routes/note/[id].svelte
index 166b0d8..420b1fa 100644
--- a/webapp/src/routes/note/[id].svelte
+++ b/webapp/src/routes/note/[id].svelte
@@ -29,7 +29,8 @@
let plaintext: string;
let timeString: string;
let decryptFailed = false;
- let downloadUrl: string;
+ // let downloadUrl: string;
+ let downloadRef: HTMLAnchorElement;
onMount(() => {
if (browser) {
@@ -46,18 +47,22 @@
timeString = msToString(diff_ms);
}
- $: if (plaintext) {
- downloadUrl = getDownloadUrl(plaintext);
- }
+ // $: if (plaintext) {
+ // downloadUrl = downloadMd(plaintext);
+ // }
// https://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link
- function getDownloadUrl(text: string): string {
+ function downloadMd() {
+ if (plaintext === undefined) return;
// Make sure the browser reads the data as UTF-8
// https://stackoverflow.com/questions/6672834/specifying-blob-encoding-in-google-chrome
const BOM = new Uint8Array([0xef, 0xbb, 0xbf]);
- const blob = new Blob([BOM, text], { type: 'text/plain' });
+ const blob = new Blob([BOM, plaintext], { type: 'text/plain' });
const url = window.URL.createObjectURL(blob);
console.log(url);
+ downloadRef.href = url;
+ downloadRef.click();
+ window.URL.revokeObjectURL(blob);
return url;
}
@@ -86,10 +91,11 @@