From 7cd9c16ff9efc53246dd8b0e43fc6d3900ca7561 Mon Sep 17 00:00:00 2001 From: drew Date: Tue, 29 Jul 2025 14:00:38 +0400 Subject: [PATCH] fix: no more than 2 whitespaces (#17) --- view/html.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/view/html.go b/view/html.go index 37487482377f91d08d33b6c63bcb64f8e924593f..fd1de9237447a1a2043b6f861c696fbca7fb7811 100644 --- a/view/html.go +++ b/view/html.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "mime/quotedprintable" + "regexp" "strings" "github.com/PuerkitoBio/goquery" @@ -62,6 +63,12 @@ func ProcessBody(rawBody string) (string, error) { s.ReplaceWithHtml(hyperlink(href, s.Text())) }) - // Return the document's text content, which now includes our formatting - return doc.Text(), nil + // Get the text content, which now includes our formatting + text := doc.Text() + + // Collapse more than 2 consecutive newlines into 2 + re := regexp.MustCompile(`\n{3,}`) + text = re.ReplaceAllString(text, "\n\n") + + return text, nil } \ No newline at end of file