mail page fix design
This commit is contained in:
parent
ccff673a49
commit
47ec859fe2
@ -231,11 +231,10 @@ export default function ComposeEmail({
|
|||||||
className="w-full h-full mt-1 bg-white border border-gray-300 rounded-md p-2 text-gray-900 overflow-y-auto prose max-w-none"
|
className="w-full h-full mt-1 bg-white border border-gray-300 rounded-md p-2 text-gray-900 overflow-y-auto prose max-w-none"
|
||||||
style={{
|
style={{
|
||||||
minHeight: '200px',
|
minHeight: '200px',
|
||||||
direction: 'ltr',
|
direction: 'inherit' as const,
|
||||||
textAlign: 'left',
|
textAlign: 'start',
|
||||||
unicodeBidi: 'bidi-override'
|
unicodeBidi: 'plaintext'
|
||||||
}}
|
}}
|
||||||
dir="ltr"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -86,6 +86,10 @@ export function convertCharset(text: string, charset: string): string {
|
|||||||
export function cleanHtml(html: string): string {
|
export function cleanHtml(html: string): string {
|
||||||
if (!html) return '';
|
if (!html) return '';
|
||||||
|
|
||||||
|
// Detect text direction from the content
|
||||||
|
const hasRtlChars = /[\u0591-\u07FF\u200F\u202B\u202E\uFB1D-\uFDFD\uFE70-\uFEFC]/.test(html);
|
||||||
|
const defaultDir = hasRtlChars ? 'rtl' : 'ltr';
|
||||||
|
|
||||||
// Remove or fix malformed URLs
|
// Remove or fix malformed URLs
|
||||||
html = html.replace(/=3D"(http[^"]+)"/g, (match, url) => {
|
html = html.replace(/=3D"(http[^"]+)"/g, (match, url) => {
|
||||||
try {
|
try {
|
||||||
@ -100,7 +104,7 @@ export function cleanHtml(html: string): string {
|
|||||||
return String.fromCharCode(parseInt(p1, 16));
|
return String.fromCharCode(parseInt(p1, 16));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clean up any remaining HTML issues
|
// Clean up any remaining HTML issues while preserving direction
|
||||||
html = html
|
html = html
|
||||||
// Remove style and script tags
|
// Remove style and script tags
|
||||||
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
||||||
@ -110,7 +114,11 @@ export function cleanHtml(html: string): string {
|
|||||||
.replace(/<base[^>]*>/gi, '')
|
.replace(/<base[^>]*>/gi, '')
|
||||||
.replace(/<title[^>]*>[\s\S]*?<\/title>/gi, '')
|
.replace(/<title[^>]*>[\s\S]*?<\/title>/gi, '')
|
||||||
.replace(/<head[^>]*>[\s\S]*?<\/head>/gi, '')
|
.replace(/<head[^>]*>[\s\S]*?<\/head>/gi, '')
|
||||||
.replace(/<body[^>]*>/gi, '')
|
// Preserve body attributes
|
||||||
|
.replace(/<body[^>]*>/gi, (match) => {
|
||||||
|
const dir = match.match(/dir=["'](rtl|ltr)["']/i)?.[1] || defaultDir;
|
||||||
|
return `<body dir="${dir}">`;
|
||||||
|
})
|
||||||
.replace(/<\/body>/gi, '')
|
.replace(/<\/body>/gi, '')
|
||||||
.replace(/<html[^>]*>/gi, '')
|
.replace(/<html[^>]*>/gi, '')
|
||||||
.replace(/<\/html>/gi, '')
|
.replace(/<\/html>/gi, '')
|
||||||
@ -123,31 +131,25 @@ export function cleanHtml(html: string): string {
|
|||||||
.replace(/<\/td>/gi, ' ')
|
.replace(/<\/td>/gi, ' ')
|
||||||
.replace(/<th[^>]*>/gi, ' ')
|
.replace(/<th[^>]*>/gi, ' ')
|
||||||
.replace(/<\/th>/gi, ' ')
|
.replace(/<\/th>/gi, ' ')
|
||||||
.replace(/<tbody[^>]*>/gi, '')
|
// Handle lists
|
||||||
.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, '\n')
|
|
||||||
.replace(/<p[^>]*>/gi, '\n')
|
|
||||||
.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(/<\/ul>/gi, '\n')
|
.replace(/<\/ul>/gi, '\n')
|
||||||
.replace(/<ol[^>]*>/gi, '\n')
|
.replace(/<ol[^>]*>/gi, '\n')
|
||||||
.replace(/<\/ol>/gi, '\n')
|
.replace(/<\/ol>/gi, '\n')
|
||||||
.replace(/<li[^>]*>/gi, '\n• ')
|
.replace(/<li[^>]*>/gi, '• ')
|
||||||
.replace(/<\/li>/gi, '\n')
|
.replace(/<\/li>/gi, '\n')
|
||||||
.replace(/<blockquote[^>]*>/gi, '\n> ')
|
// Handle other block elements
|
||||||
.replace(/<\/blockquote>/gi, '\n')
|
.replace(/<div[^>]*>/gi, '\n')
|
||||||
|
.replace(/<\/div>/gi, '\n')
|
||||||
|
.replace(/<p[^>]*>/gi, '\n')
|
||||||
|
.replace(/<\/p>/gi, '\n')
|
||||||
|
.replace(/<br[^>]*>/gi, '\n')
|
||||||
|
.replace(/<hr[^>]*>/gi, '\n')
|
||||||
// Handle inline elements
|
// Handle inline elements
|
||||||
.replace(/<span[^>]*>/gi, '')
|
.replace(/<span[^>]*>/gi, '')
|
||||||
.replace(/<\/span>/gi, '')
|
.replace(/<\/span>/gi, '')
|
||||||
|
.replace(/<a[^>]*>/gi, '')
|
||||||
|
.replace(/<\/a>/gi, '')
|
||||||
.replace(/<strong[^>]*>/gi, '**')
|
.replace(/<strong[^>]*>/gi, '**')
|
||||||
.replace(/<\/strong>/gi, '**')
|
.replace(/<\/strong>/gi, '**')
|
||||||
.replace(/<b[^>]*>/gi, '**')
|
.replace(/<b[^>]*>/gi, '**')
|
||||||
@ -156,39 +158,19 @@ export function cleanHtml(html: string): string {
|
|||||||
.replace(/<\/em>/gi, '*')
|
.replace(/<\/em>/gi, '*')
|
||||||
.replace(/<i[^>]*>/gi, '*')
|
.replace(/<i[^>]*>/gi, '*')
|
||||||
.replace(/<\/i>/gi, '*')
|
.replace(/<\/i>/gi, '*')
|
||||||
// Handle HTML entities
|
// Handle special characters
|
||||||
.replace(/ /g, ' ')
|
.replace(/ /g, ' ')
|
||||||
.replace(/‌/g, '')
|
|
||||||
.replace(/»/g, '»')
|
|
||||||
.replace(/«/g, '«')
|
|
||||||
.replace(/>/g, '>')
|
|
||||||
.replace(/</g, '<')
|
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
.replace(/"/g, '"')
|
.replace(/"/g, '"')
|
||||||
.replace(/é/g, 'é')
|
.replace(/'/g, "'")
|
||||||
.replace(/è/g, 'è')
|
|
||||||
.replace(/ê/g, 'ê')
|
|
||||||
.replace(/ë/g, 'ë')
|
|
||||||
.replace(/à/g, 'à')
|
|
||||||
.replace(/â/g, 'â')
|
|
||||||
.replace(/ä/g, 'ä')
|
|
||||||
.replace(/î/g, 'î')
|
|
||||||
.replace(/ï/g, 'ï')
|
|
||||||
.replace(/ô/g, 'ô')
|
|
||||||
.replace(/ö/g, 'ö')
|
|
||||||
.replace(/û/g, 'û')
|
|
||||||
.replace(/ü/g, 'ü')
|
|
||||||
.replace(/ç/g, 'ç')
|
|
||||||
.replace(/Œ/g, 'Œ')
|
|
||||||
.replace(/œ/g, 'œ')
|
|
||||||
.replace(/Æ/g, 'Æ')
|
|
||||||
.replace(/æ/g, 'æ')
|
|
||||||
// Clean up whitespace
|
// Clean up whitespace
|
||||||
.replace(/^\s+$/gm, '')
|
.replace(/\s+/g, ' ')
|
||||||
.replace(/\n{3,}/g, '\n\n')
|
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
return html;
|
// Wrap in a div with the detected direction
|
||||||
|
return `<div dir="${defaultDir}">${html}</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseEmailHeaders(headers: string): { contentType: string; encoding: string; charset: string } {
|
export function parseEmailHeaders(headers: string): { contentType: string; encoding: string; charset: string } {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user