How to Extract Slot Text in Svelte 5? #15503
-
I'm building a component that converts Markdown into HTML. However, I noticed that when I use How can I extract the plain text from it? For example, given the following usage: <Markdown>
#markdown
</Markdown> I want to retrieve just the "#markdown" string. What’s the best way to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There is no way to retrieve the text without rendering the snippet first. 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
`} /> |
Beta Was this translation helpful? Give feedback.
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.:
There are also tagged template literal utilities that can clean up indentation: