···2233import (
44 "fmt"
55+ "html"
56 "net/http"
67)
7889// Notice performs a hx-oob-swap to replace the content of an element with a message.
910// Pass the id of the element and the message to display.
1011func (s *Pages) Notice(w http.ResponseWriter, id, msg string) {
1111- html := fmt.Sprintf(`<span id="%s" hx-swap-oob="innerHTML">%s</span>`, id, msg)
1212+ escaped := html.EscapeString(msg)
1313+ markup := fmt.Sprintf(`<span id="%s" hx-swap-oob="innerHTML">%s</span>`, id, escaped)
12141315 w.Header().Set("Content-Type", "text/html")
1416 w.WriteHeader(http.StatusOK)
1515- w.Write([]byte(html))
1717+ w.Write([]byte(markup))
1818+}
1919+2020+func (s *Pages) NoticeHTML(w http.ResponseWriter, id string, trustedHTML string) {
2121+ markup := fmt.Sprintf(`<span id="%s" hx-swap-oob="innerHTML">%s</span>`, id, trustedHTML)
2222+2323+ w.Header().Set("Content-Type", "text/html")
2424+ w.WriteHeader(http.StatusOK)
2525+ w.Write([]byte(markup))
1626}
17271828// HxRefresh is a client-side full refresh of the page.