courrier preview
This commit is contained in:
parent
9c2c909f71
commit
1211b43f46
@ -278,35 +278,15 @@ export function processHtmlContent(htmlContent: string, textContent?: string): s
|
|||||||
textNodes.forEach(node => {
|
textNodes.forEach(node => {
|
||||||
if (node.nodeValue) {
|
if (node.nodeValue) {
|
||||||
// Replace sequences of whitespace with a single space
|
// Replace sequences of whitespace with a single space
|
||||||
// But don't change whitespace in <pre> tags
|
node.nodeValue = node.nodeValue.replace(/\s+/g, ' ').trim();
|
||||||
if (!isInPreTag(node)) {
|
|
||||||
node.nodeValue = node.nodeValue.replace(/\s+/g, ' ').trim();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Helper function to check if a node is inside a pre tag
|
|
||||||
function isInPreTag(node: Node): boolean {
|
|
||||||
let parent = node.parentNode;
|
|
||||||
while (parent) {
|
|
||||||
if (parent.nodeName.toLowerCase() === 'pre') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
parent = parent.parentNode;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove empty paragraphs and divs that contain only whitespace
|
// Remove empty paragraphs and divs that contain only whitespace
|
||||||
const emptyElements = tempDiv.querySelectorAll('p, div, span');
|
const emptyElements = tempDiv.querySelectorAll('p, div, span');
|
||||||
emptyElements.forEach(el => {
|
emptyElements.forEach(el => {
|
||||||
if (el.innerHTML.trim() === '' || el.innerHTML === ' ') {
|
if (el.innerHTML.trim() === '' || el.innerHTML === ' ') {
|
||||||
// Only remove if not a child of a layout container like table
|
el.parentNode?.removeChild(el);
|
||||||
if (el.parentNode &&
|
|
||||||
el.parentNode.nodeName.toLowerCase() !== 'td' &&
|
|
||||||
el.parentNode.nodeName.toLowerCase() !== 'th') {
|
|
||||||
el.parentNode?.removeChild(el);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -332,7 +312,7 @@ export function processHtmlContent(htmlContent: string, textContent?: string): s
|
|||||||
.replace(/src="data:image\/[^;]+;base64,\s*([^"]+)\s*"/gi, (match, p1) => {
|
.replace(/src="data:image\/[^;]+;base64,\s*([^"]+)\s*"/gi, (match, p1) => {
|
||||||
return `src="data:image/png;base64,${p1.replace(/\s+/g, '')}"`;
|
return `src="data:image/png;base64,${p1.replace(/\s+/g, '')}"`;
|
||||||
})
|
})
|
||||||
// Remove excessive whitespace from the HTML string itself, but be careful not to break preformatted text
|
// Remove excessive whitespace from the HTML string itself
|
||||||
.replace(/>\s+</g, '> <');
|
.replace(/>\s+</g, '> <');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error processing HTML content:', error);
|
console.error('Error processing HTML content:', error);
|
||||||
|
|||||||
@ -372,27 +372,8 @@ export function formatForwardedEmail(originalEmail: EmailMessage | LegacyEmailMe
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
// Use the original HTML content if available, otherwise format the text
|
// Use the original HTML content if available, otherwise format the text
|
||||||
let contentHtml = '';
|
const contentHtml = html || (text ? `<p>${text.replace(/\n/g, '</p><p>')}</p>` : '<p>No content available</p>');
|
||||||
|
|
||||||
if (html) {
|
|
||||||
// Preserve the original HTML structure
|
|
||||||
// The key is to preserve all formatting without trying to modify it
|
|
||||||
contentHtml = `<div class="original-email-content" style="margin-top: 10px;">${html}</div>`;
|
|
||||||
} else if (text) {
|
|
||||||
// For plain text, convert to HTML with proper line breaks
|
|
||||||
const formattedText = text
|
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/</g, '<')
|
|
||||||
.replace(/>/g, '>')
|
|
||||||
.replace(/\n/g, '<br>');
|
|
||||||
|
|
||||||
contentHtml = `<div class="original-email-content" style="margin-top: 10px; font-family: monospace; white-space: pre-wrap;">${formattedText}</div>`;
|
|
||||||
} else {
|
|
||||||
contentHtml = '<div class="no-content" style="color: #777; font-style: italic;">No content available</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just concatenate the header with the original content
|
|
||||||
// Don't try to process or reformat the original content
|
|
||||||
const cleanHtml = `${forwardHeader}${contentHtml}`;
|
const cleanHtml = `${forwardHeader}${contentHtml}`;
|
||||||
|
|
||||||
// Plain text version - with clearer formatting
|
// Plain text version - with clearer formatting
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user