Skip to content

How to Extract Slot Text in Svelte 5? #15503

Answered by brunnerh
ryan-minato asked this question in Q&A
Discussion options

You must be logged in to vote

There is no way to retrieve the text without rendering the snippet first.
If you have dynamic Markdown, I would recommend using a regular string property.
There are also preprocessing tools that turn Markdown anywhere in the component into HTML, e.g. MDsveX.

You could also use a template string literal in a property, which is less pretty, e.g.:

<Markdown content={`
Markdown here
`} />

There are also tagged template literal utilities that can clean up indentation:

<Markdown content={unindent`
    Markdown here
`} />

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ryan-minato
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants