Skip to content

Vizel API / svelte/src / createVizelMarkdown

Function: createVizelMarkdown()

ts
function createVizelMarkdown(getEditor, options?): CreateVizelMarkdownResult;

Defined in: packages/svelte/src/runes/createVizelMarkdown.svelte.ts:78

Svelte 5 rune for bidirectional Markdown synchronization with the editor.

Parameters

ParameterTypeDescription
getEditor() => Editor | null | undefinedFunction to get the editor instance
optionsCreateVizelMarkdownOptionsSync options

Returns

CreateVizelMarkdownResult

Markdown state and control functions

Examples

svelte
<script lang="ts">
import { createVizelEditor, createVizelMarkdown, VizelEditor } from '@vizel/svelte';

const editorState = createVizelEditor();
const markdownState = createVizelMarkdown(() => editorState.current, {
  debounceMs: 300,
});
</script>

<VizelEditor editor={editorState.current} />
<textarea
  value={markdownState.current}
  oninput={(e) => markdownState.setMarkdown(e.currentTarget.value)}
/>
{#if markdownState.isPending}
  <span>Syncing...</span>
{/if}
svelte
<script lang="ts">
// With initial markdown value
const markdownState = createVizelMarkdown(() => editorState.current, {
  initialValue: "# Hello World",
  transformDiagrams: true,
});
</script>

Released under the MIT License.