Usage Examples
Explore practical examples of how to use @humanspeak/svelte-markdown in real-world scenarios.
Getting Started
Customization
Quick Reference
| Use Case | Usage | Notes |
|---|---|---|
| Blog posts | <SvelteMarkdown source={post.body} /> | Full block rendering |
| Inline labels | <SvelteMarkdown source={label} isInline /> | No wrapping <p> tags |
| Sanitized content | <SvelteMarkdown {source} renderers={{ html: allowHtmlOnly([...]) }} /> | Restrict HTML tags |
| Custom styling | <SvelteMarkdown {source} renderers={{ heading: MyHeading }} /> | Override specific renderers |
| Token inspection | <SvelteMarkdown {source} parsed={handleTokens} /> | Access AST tokens |
Best Practices
Filter untrusted HTML
Use allowHtmlOnly/excludeHtmlOnly for user content
Leverage token caching
Repeated renders are 50-200x faster automatically
Use custom renderers
Override specific elements for custom styling
Use isInline for labels
Avoid block-level wrapping for inline content
Inspect tokens when debugging
Use the parsed callback to see the AST