Files
2026-04-26 18:23:50 +02:00

26 lines
481 B
Go

package utils
import (
"html"
"regexp"
"strings"
)
var htmlTagRe = regexp.MustCompile(`<[^>]*>`)
// StripHTML removes HTML tags and decodes HTML entities from s.
func StripHTML(s string) string {
stripped := htmlTagRe.ReplaceAllString(s, "")
decoded := html.UnescapeString(stripped)
return StripCRLF(decoded)
}
func StripCRLF(s string) string {
return strings.TrimSpace(strings.Map(func(r rune) rune {
if r == '\r' || r == '\n' {
return -1
}
return r
}, s))
}