0

I have a blog written in Astro and I write my posts in markdown. I'm having troubles using remark and remark-html to pass my md tags (such as ##) when I render the post.

async function remarkContent(content) {
    const file = await remark()
        .use(remarkHtml)
        .process(content);
    return content;
}

I have tried this function and then pass it to an Html fragment but it does not work

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34

1 Answers1

0

Astro has built-in support for Markdown files and remark, so if your content is in your project folder, you can either place Markdown files in your src/pages/ and have them automatically transformed into pages or place your files elsewhere, src/content/ for example, and import them for rendering.

If your content is stored remotely and you are fetching it, you may still need to do something like your example function.

I think the main issue with your example code is that it returns content. It should return the transformed file instead:

async function remarkContent(content) {
    const file = await remark()
        .use(remarkHtml)
        .process(content);
    return String(file);
}

You could then use this in an Astro comment using the set:html directive:

<Fragment set:html={remarkContent(mdString)} />
swithinbank
  • 1,127
  • 1
  • 6
  • 15