I am trying to use a string containing a ' character as an attribute value. However, ' is always replaced with '. Is there a way around this? Since the value is enclosed with ", ' wouldn't necessarily have to be escaped, would it? The same happens when I try to add a plain text html node.
package main
import (
"os"
"strings"
"github.com/PuerkitoBio/goquery"
"golang.org/x/net/html"
)
var htmlString = `<div class="catch-me-if-you-can">♂️</div>`
func main() {
qHtml, err := goquery.NewDocumentFromReader(strings.NewReader(htmlString))
if err != nil {
panic(err)
}
n := &html.Node{
Type: html.ElementNode,
Data: "zombie-hunter",
Attr: []html.Attribute{
{Key: "meta", Val: "{name: 'RedEye!', equipment: 'Baseball Bat'}"},
},
}
qHtml.Find(`div`).First().ReplaceWithNodes(n)
goquery.Render(os.Stdout, qHtml.Contents())
}
Output:
<html><head></head><body><zombie-hunter meta="{name: 'RedEye!', equipment: 'Baseball Bat'}"></zombie-hunter></body></html>