#Using/rendering markdown in frontmatter?
7 messages · Page 1 of 1 (latest)
You can do that using a markdown processing library like marked
import { marked } from 'marked';
// This is the html result of the markdown
const renderedMarkdown = marked.parse("Super _interesting_ [post](https://myblog.com/this_post) ");
// turns the html to plain text
// the regex is just good enough and could fail in
// some cases I didn't think of
// use https://www.npmjs.com/package/html-to-text for a more
// battle tested plain text conversion
const plainText = renderedMarkdown.replace(/<\/?[^>]+(>|$)/g, "");
thanks!
how would i show the html result of the markdown in an Astro component?
using a Fragment?
Exactly! That and the set:html directive
Docs for reference
https://docs.astro.build/en/reference/directives-reference/#sethtml