import { remark } from "remark"; import remarkParse from "remark-parse"; import rehypeRaw from "rehype-raw"; import rehypeStringify from "rehype-stringify"; import remarkRehype from "remark-rehype"; /** * Identical to renderMarkdown() in portfolio/data/content.ts, so the preview * renders exactly what the live post page will. allowDangerousHtml is * intentional: posts embed raw HTML blocks (e.g.
). */ export async function renderMarkdown(source: string): Promise { const re = await remark() .use(remarkParse) .use(remarkRehype, { allowDangerousHtml: true }) .use(rehypeRaw) .use(rehypeStringify) .process(source); return re?.toString() ?? ""; }