import { escapeHtml, sanitizeUrl } from "./security"; export function markdownToHtml(markdown: string): string { let html = markdown .replace(/^### (.*$)/gim, "
$2')
.replace(/`(.+?)`/g, "$1")
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, text, url) => {
const safeUrl = sanitizeUrl(url);
const safeText = escapeHtml(text);
return safeUrl ? `${safeText}` : safeText;
})
.replace(/^\s*[-*]\s+(.*)$/gim, "")
.replace(/\n/g, "
");
html = html.replace(/(
${html}
`; }