import DOMPurify from 'isomorphic-dompurify'; /** * Sanitizes chapter HTML content with extended allowed tags. * More permissive than the description sanitizer to support * formatted novel content including headings, lists, and images. */ export function sanitizeChapterHtml(html: string): string { return DOMPurify.sanitize(html, { ALLOWED_TAGS: [ // Basic formatting 'b', 'i', 'em', 'strong', 'u', 's', 'strike', 'del', 'ins', // Structure 'p', 'br', 'hr', 'div', 'span', // Headings 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', // Lists 'ul', 'ol', 'li', // Quotes 'blockquote', 'q', 'cite', // Preformatted 'pre', 'code', // Ruby (for Asian language annotations) 'ruby', 'rt', 'rp', // Images 'img', // Tables 'table', 'thead', 'tbody', 'tr', 'th', 'td' ], ALLOWED_ATTR: [ // Image attributes 'src', 'alt', 'title', 'width', 'height', // Table attributes 'colspan', 'rowspan', // Generic styling (limited) 'class' ], ALLOW_DATA_ATTR: false }); }