Created
January 13, 2023 15:23
-
-
Save Crenshinibon/1a792a35964a489cfe1f62ab41948c99 to your computer and use it in GitHub Desktop.
svelte quill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import Quill from 'quill'; | |
import 'quill/dist/quill.core.css' | |
import 'quill/dist/quill.snow.css' | |
import { onMount } from 'svelte'; | |
let editor; | |
export let toolbarOptions = [ | |
[{ header: 1 }, { header: 2 }, "blockquote", "link"], | |
["bold", "italic", "underline", "strike"], | |
[{ list: "ordered" }, { list: "ordered" }], | |
[{ align: [] }], | |
["clean"] | |
]; | |
let quill | |
let contents = "" | |
onMount(async () => { | |
quill = new Quill(editor, { | |
modules: { | |
toolbar: toolbarOptions | |
}, | |
theme: "snow", | |
placeholder: "Write your story..." | |
}); | |
quill.on('text-change', (d, od, s) => { | |
contents = quill.root.innerHTML | |
}) | |
}); | |
</script> | |
<div class="editor-wrapper"> | |
<div bind:this={editor} /> | |
</div> | |
<br> | |
<h1>Contents Formatted</h1> | |
{#if quill} | |
<div> | |
{@html contents} | |
</div> | |
{/if} | |
<br> | |
<h1>Contents Raw</h1> | |
{#if quill} | |
<div> | |
{contents} | |
</div> | |
{/if} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment