Components
Docvia supports embedding interactive components directly in Markdown using the directive syntax. Components are registered in your config and hydrated on the client.
Directive syntax
Block directive:
:::counter{initial=42 hydrate="client:load"}
:::
Inline directive:
Check the :badge{text="new"} feature.
Registration
Register components in docvia.config.ts:
export default defineConfig({
components: {
counter: {
path: "./src/lib/components/Counter.svelte",
hydrate: true,
defaultProps: { initial: 0 },
},
},
});
Or use the array form, where globs register every match and names come from
file names (ButtonDemo.svelte becomes button-demo):
export default defineConfig({
components: [
"./src/lib/docs/*.svelte",
{ name: "counter", path: "./src/lib/components/Counter", hydrate: true },
],
});
Paths resolve from the project root, the extension may be omitted, and a missing
file fails the build with a CONFIG_ERROR.
Hydration modes
| Mode | When | Use case |
|---|---|---|
hydrate: false | Never | Static content only |
hydrate: true | Immediate | Interactive on first paint |
client:idle | On idle | After main thread is free |
client:visible | On intersection | When scrolled into view |
Live example
Here is an interactive counter embedded via directive:
42
Count
The counter is server-rendered then hydrated client-side.
Creating components
Components are standard Svelte 5 components:
<script lang="ts">
let { initial = 0 } = $props();
let count = $state(initial);
</script>
<div class="counter-card">
<div class="counter-value">{count}</div>
<div class="counter-controls">
<button class="btn" onclick={() => count--}>-</button>
<button class="btn" onclick={() => count = initial}>Reset</button>
<button class="btn btn-primary" onclick={() => count++}>+</button>
</div>
</div>