go-html/pipeline.go
Claude 8ac512362a
feat: add StripTags for render-reverse pipeline
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 00:08:44 +00:00

30 lines
623 B
Go

package html
import "strings"
// StripTags removes HTML tags from rendered output, returning plain text.
// Tag boundaries are replaced with a single space; result is trimmed.
func StripTags(html string) string {
var b strings.Builder
inTag := false
for _, r := range html {
if r == '<' {
inTag = true
b.WriteByte(' ')
continue
}
if r == '>' {
inTag = false
continue
}
if !inTag {
b.WriteRune(r)
}
}
// Collapse multiple spaces into one.
result := b.String()
for strings.Contains(result, " ") {
result = strings.ReplaceAll(result, " ", " ")
}
return strings.TrimSpace(result)
}