import DOMPurify from 'dompurify'; /** * Sanitize untrusted HTML from APIs before rendering with dangerouslySetInnerHTML. */ export function sanitizeHtml(html: string): string { if (!html) { return ''; } return DOMPurify.sanitize(html, { USE_PROFILES: { html: true } }); } /** * Convert HTML snippets (e.g. WooCommerce price markup) to plain text for safe text nodes. */ export function htmlToPlainText(html: string): string { if (!html) { return ''; } const sanitized = DOMPurify.sanitize(html, { ALLOWED_TAGS: [] }); const el = document.createElement('div'); el.innerHTML = sanitized; return (el.textContent || '').replace(/\u00A0/g, ' ').trim(); }