I have webapp. Go html template will escape all unsafe tag. Is there way to selectively escape a string? For instance, Google.com will highlight your search query and wrap it with <em>
tag while all other html & javascript gets escaped. I have this:
package main
import (
"fmt"
"html/template"
)
func main() {
s := "<i>This should be escaped</i><strong>This should be in bold</strong>."
h := template.HTMLEscaper(s)
fmt.Println(h)
}
Right now everything gets escaped. I am aware you can do a template function with template.HTML(mystring) but how do I do that for part of a string?
thx!
EDIT: I would like the final string to be:
<i>This should be escaped</i><strong>This should be in bold</strong>.
To be clear, I have tried creating a template function to highlight matches...the html I add gets escaped in the actual template ;(