Add feed description view (#12)

with colors!
This commit is contained in:
Dave Gallant
2020-07-03 23:25:48 -04:00
committed by GitHub
parent 85bf323fe8
commit afbfa53ae6
8 changed files with 99 additions and 21 deletions

23
utils/html.go Normal file
View File

@@ -0,0 +1,23 @@
package utils
import (
"regexp"
"sort"
"strings"
)
// StripHtmlTags uses regex to strip all html elements
func StripHtmlTags(s string) string {
const pattern = `(<\/?[a-zA-A]+?[^>]*\/?>)*`
r := regexp.MustCompile(pattern)
groups := r.FindAllString(s, -1)
sort.Slice(groups, func(i, j int) bool {
return len(groups[i]) > len(groups[j])
})
for _, group := range groups {
if strings.TrimSpace(group) != "" {
s = strings.ReplaceAll(s, group, "")
}
}
return s
}