Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions svelte-commonmark/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Editor, rootCtx, defaultValueCtx } from '@milkdown/kit/core'
import { commonmark } from '@milkdown/kit/preset/commonmark'
import { nord } from '@milkdown/theme-nord'
import type { Attachment } from "svelte/attachments";

const markdown =
`# Milkdown Svelte Commonmark
Expand All @@ -10,18 +11,27 @@ const markdown =

This is a demo for using Milkdown with **Svelte**.`

function editor(dom) {
Editor.make()
.config((ctx) => {
ctx.set(rootCtx, dom)
ctx.set(defaultValueCtx, markdown)
})
.config(nord)
.use(commonmark)
.create();
}
const editor = (content: string): Attachment => {
return (dom) => {
const makeEditor = Editor.make()
.config((ctx) => {
ctx.set(rootCtx, dom);
ctx.set(defaultValueCtx, content);
})
.config(nord)
.use(commonmark)
.create();

return () => {
makeEditor.then((editor) => {
editor.destroy();
});
};
};
};

</script>

<main>
<div use:editor />
<div {@attach editor(markdown)} />
</main>