pngwn / MDsveX

A markdown preprocessor for Svelte.
https://mdsvex.pngwn.io
MIT License
2.36k stars 102 forks source link

Use of Svelte syntax in markdown ? #607

Closed LBF38 closed 3 months ago

LBF38 commented 3 months ago

Would it be possible to have support for Svelte templating and logic blocks inside markdown ?

For example, one may want to integrate some components like this :

---
categories:
    - category 1
    - category 2
    - category 3
---

<script>
// imports for components
</script>

# Header 1

Some random paragraph

{#each categories as category}
    <Badge>category<Badge/>
{/each}

***
Final thoughts on the article...

<OtherComponent />
pngwn commented 3 months ago

This should already be possible. You may need to add some white space in certain places to satisfy the markdown parser but all Svelte syntax is supported in mdsvex today (but not typescript).

LBF38 commented 3 months ago

The Svelte syntax is supported as you said, but there are limitations on using the metadata directly inside the markdown component. It might need more docs about this.

Thanks for the lib, btw !