mail page rest
This commit is contained in:
parent
850ad73244
commit
02668624c0
@ -95,6 +95,7 @@ export function cleanHtml(html: string): string {
|
|||||||
|
|
||||||
// Clean up any remaining HTML issues
|
// Clean up any remaining HTML issues
|
||||||
html = html
|
html = html
|
||||||
|
// Remove style and script tags
|
||||||
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
||||||
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
||||||
.replace(/<meta[^>]*>/gi, '')
|
.replace(/<meta[^>]*>/gi, '')
|
||||||
@ -106,11 +107,49 @@ export function cleanHtml(html: string): string {
|
|||||||
.replace(/<\/body>/gi, '')
|
.replace(/<\/body>/gi, '')
|
||||||
.replace(/<html[^>]*>/gi, '')
|
.replace(/<html[^>]*>/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(/<br\s*\/?>/gi, '\n')
|
||||||
.replace(/<div[^>]*>/gi, '\n')
|
.replace(/<div[^>]*>/gi, '\n')
|
||||||
.replace(/<\/div>/gi, '')
|
.replace(/<\/div>/gi, '\n')
|
||||||
.replace(/<p[^>]*>/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(/ /g, ' ')
|
.replace(/ /g, ' ')
|
||||||
.replace(/‌/g, '')
|
.replace(/‌/g, '')
|
||||||
.replace(/»/g, '»')
|
.replace(/»/g, '»')
|
||||||
@ -119,6 +158,7 @@ export function cleanHtml(html: string): string {
|
|||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
.replace(/"/g, '"')
|
.replace(/"/g, '"')
|
||||||
|
// Clean up whitespace
|
||||||
.replace(/^\s+$/gm, '')
|
.replace(/^\s+$/gm, '')
|
||||||
.replace(/\n{3,}/g, '\n\n')
|
.replace(/\n{3,}/g, '\n\n')
|
||||||
.trim();
|
.trim();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user