/
unescape.go
43 lines (32 loc) · 869 Bytes
/
unescape.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package processor
import (
"html"
"github.com/urandom/readeef/content"
"github.com/urandom/readeef/log"
"github.com/urandom/readeef/parser"
)
type Unescape struct {
log log.Log
}
func NewUnescape(l log.Log) Unescape {
return Unescape{log: l}
}
func (p Unescape) ProcessArticles(articles []content.Article) []content.Article {
if len(articles) == 0 {
return articles
}
p.log.Infof("Unescaping articles of feed %d", articles[0].FeedID)
for i := range articles {
articles[i].Description = p.processDescription(articles[i].Description)
}
return articles
}
func (p Unescape) ProcessFeed(f parser.Feed) parser.Feed {
for i := range f.Articles {
f.Articles[i].Description = p.processDescription(f.Articles[i].Description)
}
return f
}
func (p Unescape) processDescription(description string) string {
return html.UnescapeString(description)
}