diff --git a/apps/sim/tools/gmail/utils.test.ts b/apps/sim/tools/gmail/utils.test.ts
index 826968261b5..e21eaddff30 100644
--- a/apps/sim/tools/gmail/utils.test.ts
+++ b/apps/sim/tools/gmail/utils.test.ts
@@ -91,10 +91,10 @@ describe('escapeHtml', () => {
})
describe('plainTextToHtml', () => {
- it('renders blank lines as paragraph breaks and single newlines as
', () => {
+ it('converts newlines to
without paragraph margins', () => {
const html = plainTextToHtml('Hi Janice,\n\nHope you are well.\nSecond line.')
- expect(html).toContain('
Hi Janice,
') - expect(html).toContain('Hope you are well.
Second line.
')
+ expect(html).toContain('Hi Janice,
Hope you are well.
Second line.')
})
it('escapes HTML in the source text', () => {
@@ -150,7 +150,7 @@ describe('buildSimpleEmailMessage', () => {
expect(plainIdx).toBeGreaterThan(-1)
expect(htmlIdx).toBeGreaterThan(plainIdx)
expect(decodePart(decoded, 'text/plain')).toBe('Hi Janice,\n\nQuick question.')
- expect(decodePart(decoded, 'text/html')).toContain('
Hi Janice,
') + expect(decodePart(decoded, 'text/html')).toContain('Hi Janice,Hello
') + expect(decodePart(message, 'text/html')).toContain('Hello') }) it('emits multipart/alternative without multipart/mixed when no attachments', () => { diff --git a/apps/sim/tools/gmail/utils.ts b/apps/sim/tools/gmail/utils.ts index f913e84ddcc..1c9ba38e3ea 100644 --- a/apps/sim/tools/gmail/utils.ts +++ b/apps/sim/tools/gmail/utils.ts @@ -339,17 +339,18 @@ export function escapeHtml(value: string): string { /** * Convert a plain-text body to an HTML body that flows naturally in Gmail. - * Blank lines become paragraph breaks; single newlines become `` tags or a CSS + * `white-space` rule — `
` margins are what Gmail's "Remove formatting"
+ * button strips, and `white-space` has inconsistent support across email
+ * clients (including Gmail for non-Google accounts). Plain `
` line
+ * breaks are the standard, client-agnostic way to preserve plain-text
+ * formatting in an HTML alternative part.
* This avoids the narrow hard-wrapped rendering Gmail uses for `text/plain`.
*/
export function plainTextToHtml(body: string): string {
const normalized = body.replace(/\r\n/g, '\n').replace(/\r/g, '\n')
- const paragraphs = normalized.split(/\n{2,}/)
- const htmlParagraphs = paragraphs.map((paragraph) => {
- const escaped = escapeHtml(paragraph).replace(/\n/g, '
')
- return `
${escaped}
` - }) - return `${htmlParagraphs.join('')}` + const escaped = escapeHtml(normalized).replace(/\n/g, '