import { Marked } from 'marked';
import DOMPurify from 'dompurify';
const marked = new Marked({ gfm: true, breaks: true });
DOMPurify.addHook('afterSanitizeAttributes', (node) => {
if (node.tagName === 'A') {
node.setAttribute('target', '_blank');
node.setAttribute('rel', 'noopener noreferrer');
}
});
export function renderMarkdown(text) {
const html = marked.parse(text ?? '');
return DOMPurify.sanitize(html, {
FORBID_TAGS: ['style', 'form', 'input', 'button', 'textarea', 'select', 'iframe', 'img'],
FORBID_ATTR: ['style'],
});
}