mirror of
https://github.com/nkanaev/yarr.git
synced 2025-12-16 09:00:15 +00:00
server-side item sanitization
This commit is contained in:
24
src/storage/utils.go
Normal file
24
src/storage/utils.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
func HTMLText(s string) string {
|
||||
tokenizer := html.NewTokenizer(strings.NewReader(s))
|
||||
contents := make([]string, 0)
|
||||
for {
|
||||
token := tokenizer.Next()
|
||||
if token == html.ErrorToken {
|
||||
break
|
||||
}
|
||||
if token == html.TextToken {
|
||||
content := strings.TrimSpace(html.UnescapeString(string(tokenizer.Text())))
|
||||
if len(content) > 0 {
|
||||
contents = append(contents, content)
|
||||
}
|
||||
}
|
||||
}
|
||||
return strings.Join(contents, " ")
|
||||
}
|
||||
Reference in New Issue
Block a user