mail page rest

This commit is contained in:
alma 2025-04-21 16:00:27 +02:00
parent 850ad73244
commit 02668624c0

View File

@ -95,6 +95,7 @@ export function cleanHtml(html: string): string {
// Clean up any remaining HTML issues
html = html
// Remove style and script tags
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
.replace(/<meta[^>]*>/gi, '')
@ -106,11 +107,49 @@ export function cleanHtml(html: string): string {
.replace(/<\/body>/gi, '')
.replace(/<html[^>]*>/gi, '')
.replace(/<\/html>/gi, '')
// Handle tables
.replace(/<table[^>]*>/gi, '\n')
.replace(/<\/table>/gi, '\n')
.replace(/<tr[^>]*>/gi, '\n')
.replace(/<\/tr>/gi, '\n')
.replace(/<td[^>]*>/gi, ' ')
.replace(/<\/td>/gi, ' ')
.replace(/<th[^>]*>/gi, ' ')
.replace(/<\/th>/gi, ' ')
.replace(/<tbody[^>]*>/gi, '')
.replace(/<\/tbody>/gi, '')
.replace(/<thead[^>]*>/gi, '')
.replace(/<\/thead>/gi, '')
.replace(/<tfoot[^>]*>/gi, '')
.replace(/<\/tfoot>/gi, '')
// Handle other structural elements
.replace(/<br\s*\/?>/gi, '\n')
.replace(/<div[^>]*>/gi, '\n')
.replace(/<\/div>/gi, '')
.replace(/<\/div>/gi, '\n')
.replace(/<p[^>]*>/gi, '\n')
.replace(/<\/p>/gi, '')
.replace(/<\/p>/gi, '\n')
.replace(/<h[1-6][^>]*>/gi, '\n')
.replace(/<\/h[1-6]>/gi, '\n')
.replace(/<ul[^>]*>/gi, '\n')
.replace(/<\/ul>/gi, '\n')
.replace(/<ol[^>]*>/gi, '\n')
.replace(/<\/ol>/gi, '\n')
.replace(/<li[^>]*>/gi, '\n• ')
.replace(/<\/li>/gi, '\n')
.replace(/<blockquote[^>]*>/gi, '\n> ')
.replace(/<\/blockquote>/gi, '\n')
// Handle inline elements
.replace(/<span[^>]*>/gi, '')
.replace(/<\/span>/gi, '')
.replace(/<strong[^>]*>/gi, '**')
.replace(/<\/strong>/gi, '**')
.replace(/<b[^>]*>/gi, '**')
.replace(/<\/b>/gi, '**')
.replace(/<em[^>]*>/gi, '*')
.replace(/<\/em>/gi, '*')
.replace(/<i[^>]*>/gi, '*')
.replace(/<\/i>/gi, '*')
// Handle HTML entities
.replace(/&nbsp;/g, ' ')
.replace(/&zwnj;/g, '')
.replace(/&raquo;/g, '»')
@ -119,6 +158,7 @@ export function cleanHtml(html: string): string {
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&')
.replace(/&quot;/g, '"')
// Clean up whitespace
.replace(/^\s+$/gm, '')
.replace(/\n{3,}/g, '\n\n')
.trim();