26 lines
481 B
Go
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))
|
|
}
|