From c52d8815a916f7bc65e8b7c24b02af9315056264 Mon Sep 17 00:00:00 2001 From: KitAmbraid <128903658+KitAmbraid@users.noreply.github.com> Date: Tue, 30 Jun 2026 07:10:46 +0200 Subject: [PATCH] refactor: use attachment syntax in svelte example --- svelte-commonmark/src/App.svelte | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/svelte-commonmark/src/App.svelte b/svelte-commonmark/src/App.svelte index 449f938e..d5e3dc4a 100644 --- a/svelte-commonmark/src/App.svelte +++ b/svelte-commonmark/src/App.svelte @@ -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 @@ -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(); + }); + }; + }; + }; +
-
+