10 lines
369 B
TypeScript
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 } });
|
|
} |