From e405d57be0bc468321119be090357605a3a836a2 Mon Sep 17 00:00:00 2001 From: movsb Date: Tue, 2 Apr 2024 20:00:37 +0800 Subject: [PATCH] make SetAttributeString() accept both []byte and string --- renderer/html/html.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/renderer/html/html.go b/renderer/html/html.go index 8738c2a..75ac6db 100644 --- a/renderer/html/html.go +++ b/renderer/html/html.go @@ -786,7 +786,14 @@ func RenderAttributes(w util.BufWriter, node ast.Node, filter util.BytesFilter) _, _ = w.Write(attr.Name) _, _ = w.WriteString(`="`) // TODO: convert numeric values to strings - _, _ = w.Write(util.EscapeHTML(attr.Value.([]byte))) + var value []byte + switch typed := attr.Value.(type) { + case []byte: + value = typed + case string: + value = util.StringToReadOnlyBytes(typed) + } + _, _ = w.Write(util.EscapeHTML(value)) _ = w.WriteByte('"') } }