Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access contents of editor #105

Open
Plunzi opened this issue Jan 26, 2025 · 2 comments
Open

Access contents of editor #105

Plunzi opened this issue Jan 26, 2025 · 2 comments

Comments

@Plunzi
Copy link

Plunzi commented Jan 26, 2025

Hello dear svelte-lexical team.
I am trying to access the content of the editor so I can grab the HTML and send out an email.
Sadly I couldn't find any documentation for that.

Thanks for your time

@Plunzi
Copy link
Author

Plunzi commented Jan 26, 2025

I found this syntax at someone else's issue.
The question now is. How can I get the html content inside?

<script lang="ts">
    imports ...

    let composerComponent = $state();

    onMount(() => {
        const editor = composerComponent.getEditor();

        editor.registerUpdateListener(({editorState}) => {
        console.log(JSON.stringify(editorState));

            const newEditor = composerComponent.getEditor();

            console.log(newEditor);
            
        });
    });

    $effect(() => {
        console.log($inspect(composerComponent));
    });

	const initialConfig = {...};
</script>

<Composer {initialConfig} bind:this={composerComponent}>
	<div class="editor-shell">
		<ToolbarRichText />
		<div class="editor-container">
			<div class="editor-scroller">
				<div class="editor">
					<ContentEditable />
				</div>
			</div>
			<RichTextPlugin />
			<HistoryPlugin />
			<ListPlugin />
			<CheckListPlugin />
			<HorizontalRulePlugin />
			<ImagePlugin />
		</div>
	</div>
</Composer>

@amr3k
Copy link

amr3k commented Feb 8, 2025

I believe this is what you're looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants