Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown Does not Work in Slots #606

Open
RIGIK93 opened this issue Jun 26, 2024 · 2 comments
Open

Markdown Does not Work in Slots #606

RIGIK93 opened this issue Jun 26, 2024 · 2 comments

Comments

@RIGIK93
Copy link

RIGIK93 commented Jun 26, 2024

Hi, need assistance on how to get the markdown working in Svelte via the <slot/> tag. As you can see from the image bellow, markdown is not parsed inside of the Note component.

image

The Note component uses slots in order to pass the text into the component,

// Note.svelte
<script lang="ts">
    export let title: string = "Note";
</script>

<div class="bg-base-200 rounded-xl px-6 py-5 not-prose my-[1.25rem]">
    <h2 class="inline-flex gap-1 font-bold text-lg">
        <svg
            xmlns="http://www.w3.org/2000/svg"
            fill="none"
            viewBox="0 0 24 24"
            class="stroke-info h-6 w-6 shrink-0"
        >
            <path
                stroke-linecap="round"
                stroke-linejoin="round"
                stroke-width="2"
                d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
            ></path>
        </svg>
        {title
    </h2>
    <p class="mt-1 mx-1">
        <slot />
    </p>
</div>
// +test.md
<script>
    import Note from "$lib/components/callouts/Note.svelte"
</script>

> This is a note for **comparison** $meow$

<Note>
    Fugiat $a$ dolore **labore** ad est dolore non ea id ad tempor in. Cupidatat esse ad aliquip fugiat sit nisi consequat incididunt non ea elit. In amet exercitation excepteur ut laborum est ullamco. Minim anim ipsum cillum occaecat fugiat minim esse labore aliqua pariatur do irure. Eu eu esse aute veniam est est ex mollit.
</Note>
@github-project-automation github-project-automation bot moved this to Triage + Refine in mdsvex Jun 26, 2024
@RIGIK93
Copy link
Author

RIGIK93 commented Jun 27, 2024

Seems to be related to #601

@PeppeL-G
Copy link

I'm no markdown expert, but my understanding is that markdown isn't parsed in HTML blocks. The following markdown code:

<h1>
`code`
</h1>

Will be compiled to:

<h1>`code`</h1>

So, there's nothing special about you passing slot content in your example; when markdown sees an HTML block, it doesn't parse markdown within that block. But you can separate the HTML blocks like this:

<h1>

`code`

</h1>

And it will be compiled to:

<h1><p><code>code</code></p></h1>

Maybe this will be good enough in your case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage + Refine
Development

No branches or pull requests

2 participants