Remove blank lines
parent
37408af647
commit
98adb53caf
|
|
@ -63,6 +63,8 @@ func newItem(i *gofeed.Item, contentFilter, copyright string) (*Item, error) {
|
||||||
|
|
||||||
item.Content = fmt.Sprintf(`<a href="%s">%s</a><br>%s`, item.Link, item.Title, item.Content)
|
item.Content = fmt.Sprintf(`<a href="%s">%s</a><br>%s`, item.Link, item.Title, item.Content)
|
||||||
|
|
||||||
|
item.Content = clearBlankLines(item.Content)
|
||||||
|
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,3 +111,10 @@ func (is Items) Swap(i, j int) {
|
||||||
is[i] = is[j]
|
is[i] = is[j]
|
||||||
is[j] = k
|
is[j] = k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clearBlankLines(s string) string {
|
||||||
|
r := regexp.MustCompile(`(?m)^\s*<br>\s*$`)
|
||||||
|
s = r.ReplaceAllLiteralString(s, "")
|
||||||
|
r = regexp.MustCompile(`(?m)\s\s*`)
|
||||||
|
return r.ReplaceAllLiteralString(s, "\n")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package rss
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mmcdole/gofeed"
|
"github.com/mmcdole/gofeed"
|
||||||
|
|
@ -75,3 +76,32 @@ func TestRSSItemNewEncodeDecode(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClearBlankLines(t *testing.T) {
|
||||||
|
cases := map[string]struct {
|
||||||
|
in string
|
||||||
|
outLines int
|
||||||
|
}{
|
||||||
|
"remove with and without whitespace": {
|
||||||
|
in: `<html>
|
||||||
|
<head>
|
||||||
|
<script>something</script>
|
||||||
|
<style>body{hello:"blue";}</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
</body>
|
||||||
|
</html>`,
|
||||||
|
outLines: 8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, c := range cases {
|
||||||
|
out := clearBlankLines(c.in)
|
||||||
|
if v := len(strings.Split(out, "\n")); v != c.outLines {
|
||||||
|
t.Errorf("%v: want %v lines, got %v from %q: %q", name, c.outLines, v, c.in, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue