mattjennings / mdsvexamples

Render your Svelte code blocks in MDSveX
31 stars 2 forks source link

How to display the "contents" of an imported component? #21

Closed henrikvilhelmberglund closed 1 year ago

henrikvilhelmberglund commented 1 year ago

I'm writing components and trying to display the code for the contents of these components. It's possible to for example write a component

I would like it to act as if I copy pasted the code from $lib/Button.svelte into the svelte example.

Is this possible somehow?

mattjennings commented 1 year ago

@henrikvilhelmberglund No - that's not something this library supports, because (if I'm understanding you right) you can do that by just using Vite features:

<script>
import Button from '$lib/Button.svelte'
import ButtonSrc from '$lib/Button.svelte?raw'
</script>

<!-- you would want to bring in a code highlighting library here, i.e prism -->
<pre><code>{ButtonSrc}</code></pre>

<Button>Button</Button>

Here are the Vite docs on using ?raw

henrikvilhelmberglund commented 1 year ago

My bad, but didn't really know where to post it.

Anyway, thanks for the help, it works perfectly!