Files
2026-09-16 21:34:09 +02:00

10 lines
369 B
TypeScript

import { marked } from "marked";
import DOMPurify from "dompurify";
marked.setOptions({ gfm: true, breaks: true });
export function markdownToHtml(source: string): string {
const rawHtml = marked.parse(source, { async: false }) as string;
if (typeof window === "undefined") return rawHtml;
return DOMPurify.sanitize(rawHtml, { USE_PROFILES: { html: true } });
}