// Detects if HTML contains custom patterns that indicate it was written in the HTML editor // rather than the visual editor. Custom HTML should render as-is without prose wrapper. export const detectCustomHtmlPatterns = (html: string): boolean => { if (!html || html.trim() === '') return false; const hasInlineStyles = /<[^>]+style\s*=\s*["'][^"']*["']/i.test(html); const classMatches = html.matchAll(/class\s*=\s*["']([^"']*)["']/gi); let hasCustomClasses = false; for (const match of classMatches) { const classValue = match[1]; if (!classValue) continue; const classes = classValue.split(/\s+/).filter(c => c.length > 0); const allowedPrefixes = [ 'prose', 'variable-', 'email-image', 'ProseMirror', 'resizable-image', 'selected', 'resize-handle', ]; const hasDisallowedClass = classes.some(cls => !allowedPrefixes.some(prefix => cls.startsWith(prefix))); if (hasDisallowedClass) { hasCustomClasses = true; break; } } const hasCustomAttributes = /<[^>]+(?:data-|aria-|role=|id=)/i.test(html); const hasComplexTables = /