diff --git a/rss/item.go b/rss/item.go
index 77dff2f..136b64c 100755
--- a/rss/item.go
+++ b/rss/item.go
@@ -63,6 +63,8 @@ func newItem(i *gofeed.Item, contentFilter, copyright string) (*Item, error) {
item.Content = fmt.Sprintf(`%s
%s`, item.Link, item.Title, item.Content)
+ item.Content = clearBlankLines(item.Content)
+
return item, nil
}
@@ -109,3 +111,10 @@ func (is Items) Swap(i, j int) {
is[i] = is[j]
is[j] = k
}
+
+func clearBlankLines(s string) string {
+ r := regexp.MustCompile(`(?m)^\s*
\s*$`)
+ s = r.ReplaceAllLiteralString(s, "")
+ r = regexp.MustCompile(`(?m)\s\s*`)
+ return r.ReplaceAllLiteralString(s, "\n")
+}
diff --git a/rss/item_test.go b/rss/item_test.go
index 56a9ac2..6a94b26 100755
--- a/rss/item_test.go
+++ b/rss/item_test.go
@@ -3,6 +3,7 @@ package rss
import (
"fmt"
"net/http"
+ "strings"
"testing"
"github.com/mmcdole/gofeed"
@@ -75,3 +76,32 @@ func TestRSSItemNewEncodeDecode(t *testing.T) {
t.Fatal(err)
}
}
+
+func TestClearBlankLines(t *testing.T) {
+ cases := map[string]struct {
+ in string
+ outLines int
+ }{
+ "remove with and without whitespace": {
+ in: `
+