fix: update the StripHTMLTags function

- Do not add an extra space between text tokens.
- Add a line break if the 'br' tag is detected.
This commit is contained in:
Dan Anglin 2024-05-26 01:18:44 +01:00
parent 2f38a07cb5
commit 7a3f2928de
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638

View file

@ -43,7 +43,13 @@ func StripHTMLTags(text string) string {
case html.ErrorToken:
return builder.String()
case html.TextToken:
builder.WriteString(token.Token().Data + " ")
text := token.Token().String()
builder.WriteString(text)
case html.StartTagToken:
tag := token.Token().String()
if tag == "<br>" {
builder.WriteString("\n")
}
}
}
}