A Markdown component previously limited to Astro can be generalized to React, Vue and Svelte with a single helper. The mechanism is the Markdown utility built for Splendid Labz, and it addresses a whitespace problem common to most Markdown libraries.
The indentation problem
Markdown content is usually written with natural indentation:
<div>
<div>
<!-- prettier-ignore -->
<Markdown>
This is a paragraph
This is a second paragraph
</Markdown>
</div>
</div>
Most libraries ignore that leading whitespace and wrap the output in <pre> and <code> tags, because Markdown treats indentation beyond four spaces as a code block:
<div>
<div>
<pre><code> This is a paragraph
This is a second paragraph
</code></pre>
</div>
</div>
The workaround is to strip all indentation and produce flat markup, which is harder to read and maintain:
<div>
<div>
<!-- prettier-ignore -->
<Markdown>
This is a paragraph
This is a second paragraph
</Markdown>
</div>
</div>
The utility resolves the whitespace issue and emits the correct HTML regardless of how the source is indented:
<div>
<div>
<p>This is a paragraph</p>
<p>This is a second paragraph</p>
</div>
</div>
Passing Markdown into the component
The utility takes Markdown text as input. When inline is true, the returned output omits paragraph tags. The Astro implementation looks like this:
---
import { markdown } from '@splendidlabz/utils'
const { inline = false, content } = Astro.props
const slotContent = await Astro.slots.render('default')
// Process content
const html = markdown(content || slotContent, { inline })
---
<Fragment set:html={html} />
Usage:
<Markdown>
<!-- Your content here -->
</Markdown>
Svelte: props instead of slots
Svelte cannot read dynamic content from slots, so Markdown has to arrive through a prop. The component:
<script>
import { markdown } from '@splendidlabz/utils'
const { content, inline = false } = $props()
const html = markdown(content, { inline })
</script>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html html}
Usage:
<Markdown content=`
### This is a header
This is a paragraph
`/>
The same pattern carries over to React and Vue without much effort. The utility itself is part of Splendid Utils, alongside the author's layout and component libraries for Astro and Svelte.



