svelte-markdown icon indicating copy to clipboard operation
svelte-markdown copied to clipboard

Markdown not displaying as HTML

Open JBStepan opened this issue 1 year ago • 1 comments

I'm trying to display HTML from Markdown, but it never displays HTML it displays the raw Markdown text

My code:

<script lang="ts">
    import type { PageData } from './$types';
    import SvelteMarkdown from 'svelte-markdown'
    
    export let data: PageData;

    const source = `
    # Hello World
    This is a paragraph
    `
</script>

<svelte:head>
    <title>Post: {data.post.title}</title>
</svelte:head>

<article>
    <h1>{data.post.title}</h1>
    <SvelteMarkdown {source}></SvelteMarkdown>
</article>

image

What it displays

JBStepan avatar Sep 13 '23 18:09 JBStepan

This is because of the indents in source. It actually does render the HTML, but it's wrapped in <code> tags because that's what it's parsed into (a code block).

If you change:

    const source = `
    # Hello World
    This is a paragraph
    `

to

    const source = `
# Hello World
This is a paragraph
    `

It will parse as intended.

ajaypillay avatar Dec 29 '23 06:12 ajaypillay