fix(email): preserve word wrap and line breaks in email body (#2139) (#2159)

This commit is contained in:
Tanushree Ahir
2025-11-14 09:42:36 +05:30
committed by GitHub
parent 56526f9448
commit 5811716d12
2 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,35 @@
import React from 'react';
export type TemplateCustomMessageBodyProps = {
text?: string;
};
export const TemplateCustomMessageBody = ({ text }: TemplateCustomMessageBodyProps) => {
if (!text) {
return null;
}
const normalized = text
.trim()
.replace(/\r\n?/g, '\n')
.replace(/\n\s*\n+/g, '\n\n')
.replace(/\n{2,}/g, '\n\n');
const paragraphs = normalized.split('\n\n');
return paragraphs.map((paragraph, i) => (
<p
key={`p-${i}`}
className="whitespace-pre-line break-words font-sans text-base text-slate-400"
>
{paragraph.split('\n').map((line, j) => (
<React.Fragment key={`line-${i}-${j}`}>
{j > 0 && <br />}
{line}
</React.Fragment>
))}
</p>
));
};
export default TemplateCustomMessageBody;