diff --git a/src/lib/components/common/RichTextInput/Collaboration.ts b/src/lib/components/common/RichTextInput/Collaboration.ts index 087545d52..dc2de6b70 100644 --- a/src/lib/components/common/RichTextInput/Collaboration.ts +++ b/src/lib/components/common/RichTextInput/Collaboration.ts @@ -131,9 +131,17 @@ export class SocketIOCollaborationProvider { const isEmptyEditor = !this.editor?.getText().trim(); if (isEmptyEditor && this.editor) { if (this.initialContent && (data?.sessions ?? ['']).length === 1) { - const editorYdoc = prosemirrorJSONToYDoc(this.editor.schema, this.initialContent); - if (editorYdoc) { - Y.applyUpdate(this.doc, Y.encodeStateAsUpdate(editorYdoc)); + // Check if initialContent is HTML (string) or JSON (object) + if (typeof this.initialContent === 'string') { + // HTML content - let the editor parse it, then sync to Yjs + this.editor.commands.setContent(this.initialContent); + // The Yjs plugin will automatically sync the content + } else { + // JSON content - use the existing approach + const editorYdoc = prosemirrorJSONToYDoc(this.editor.schema, this.initialContent); + if (editorYdoc) { + Y.applyUpdate(this.doc, Y.encodeStateAsUpdate(editorYdoc)); + } } } } else { diff --git a/src/lib/components/notes/NoteEditor.svelte b/src/lib/components/notes/NoteEditor.svelte index 37620f75e..390a39f8a 100644 --- a/src/lib/components/notes/NoteEditor.svelte +++ b/src/lib/components/notes/NoteEditor.svelte @@ -145,6 +145,9 @@ let inputElement = null; + // Computed HTML for editor: fall back to markdown if HTML is missing + $: editorHtml = note?.data?.content?.html || (note?.data?.content?.md ? marked.parse(note.data.content.md) : ''); + const init = async () => { loading = true; const res = await getNoteById(localStorage.token, id).catch((error) => { @@ -154,7 +157,7 @@ messages = []; - if (res) { + if (res) { note = res; files = res.data.files || []; @@ -1154,7 +1157,7 @@ Provide the enhanced notes in markdown format. Use markdown syntax for headings, className="input-prose-sm px-0.5 h-[calc(100%-2rem)]" json={true} bind:value={note.data.content.json} - html={note.data?.content?.html} + html={editorHtml} documentId={`note:${note.id}`} collaboration={true} socket={$socket}