Nodes
You can use Svelte components in your markdown files, you can define Svelte Component for each node.
Create a Svelte file and export Svelte components with the same name as the node from the module script.
<script module>
export { default as Heading } from './Heading.svelte';
</script>
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
markdoc({
nodes: join(
dirname(fileURLToPath(import.meta.url)),
'./src/lib/Nodes.svelte',
),
});
<script>
let { level, children } = $props();
</script>
<svelte:element this={`h${level}`}>{@render children?.()}</svelte:element>
You can find a list of available nodes here.
Custom attributes
Declare additional node attributes through the Markdoc config option. They
will be passed to the corresponding Svelte component alongside the built-in
attributes.
markdoc({
nodes: './src/lib/Nodes.svelte',
config: {
nodes: {
fence: {
attributes: {
highlight: { type: String },
},
},
},
},
});
Node attributes use Markdoc annotation syntax.
```js {% highlight="{1-2,4}" %}
console.log('highlight me');
```
The Fence component can then receive highlight through $props().