skip section navigation

Markdown

Markdown renders a string at runtime. use it for an article description, a message body or another piece of content your app receives as text. it isn’t a Svelte component compiler.

## This weekend Read the **balcony garden** guide, then make a list: - herbs for the kitchen - a pot with drainage - somewhere sunny

usage

svelte
<script>
	import { Markdown } from '@ciabi/loafkit-ui';
	const source = `## This weekend

Read the **balcony garden** guide, then make a list:

- herbs for the kitchen
- a pot with drainage
- somewhere sunny`;
</script>

<Markdown {source} />

what gets rendered

the source is parsed with Marked; top-level fenced code tokens use Codeblock, while other tokens are converted to HTML and sanitized with DOMPurify before rendering. an empty source produces no article content.

Svelte imports, bindings and event handlers written inside the source string remain content rather than live components. use normal Svelte markup or a component snippet when you need interaction.

content is still your responsibility

sanitization removes unsafe HTML according to the sanitizer’s behavior. it doesn’t make every link appropriate for your app or validate what the text claims. apply your own content and URL rules at the boundary where you accept data.

Markdown supplies .loaf-paragraph-text reading styles. it doesn’t accept a class or style prop, so wrap it when the surrounding layout needs a width or gap. ChatMessage already uses Markdown for its text prop.

edit text and see the result

## garden notes try **mint** in its own pot.
svelte
<script lang="ts">
import { Markdown, Input, Field, FieldLabel } from '@ciabi/loafkit-ui';
let draftMarkdown = $state(`## garden notes

try **mint** in its own pot.`);
</script>

<Field><FieldLabel htmlFor="markdown-draft">reading note</FieldLabel>
	<Input id="markdown-draft" multiline bind:value={draftMarkdown} />
</Field>
<Markdown source={draftMarkdown} />

API reference

Markdown

Component
source

the Markdown string to parse, sanitize and render.