(body: string)
| 336 | * This avoids the narrow hard-wrapped rendering Gmail uses for `text/plain`. |
| 337 | */ |
| 338 | export function plainTextToHtml(body: string): string { |
| 339 | const normalized = body.replace(/\r\n/g, '\n').replace(/\r/g, '\n') |
| 340 | const paragraphs = normalized.split(/\n{2,}/) |
| 341 | const htmlParagraphs = paragraphs.map((paragraph) => { |
| 342 | const escaped = escapeHtml(paragraph).replace(/\n/g, '<br>') |
| 343 | return `<p>${escaped}</p>` |
| 344 | }) |
| 345 | return `<!DOCTYPE html><html><body>${htmlParagraphs.join('')}</body></html>` |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Best-effort conversion of an HTML body to a plain-text fallback. Used so we |
no test coverage detected