How can I use a "writable store" to create a "blob"?
I am new to Svelte. I am trying to code a simple markdown editor for visually impaired users. The content of the "textarea" is stored in a "writable store" for further use:
- speech-synthesis
- markdown-preview
- the content of an existing text file is stored in it
- save text to file
But saving the text content via download to a file does not work.
<script>
let blob = new Bob([$textStore], type:"text/plain");
let url = URL.createObjectURL(blob);
</script>
<button>
<a href={url} download="untitled.md" id="link">Download
</a>
</button>
An empty file is saved or it has the content "[object Object]", when I use curley brackets:
let blob = new Blob ([{$textStore}], {type: 'text/plain'});
File for testing:
// TextStore.js
import { writable } from "svelte/store";
export const textStore = writable('');
<!-- EditorTest.svelte -->
<script>
import { textStore } from "./TextStore.js";
let blob = new Blob ([{$textStore}], {type: 'text/plain'});
let url = URL.createObjectURL(blob);
</script>
<h1>Blob-Test</h1>
<textarea bind:value={$textStore} cols="20" rows="5"></textarea>
<hr>
<pre>{$textStore}</pre>
<br>
<button>
<a href={url} download="untitled.md" id="link">Save</a>
</button>
Can someone help, thanks a lot already.