Closed movsb closed 8 months ago
goldmark is designed to be able to support various output formats by custom renderer implementations, so attribute values designed to be able to have any kind of values.
In HTML outputs, attribute values should be rendered as a string.
The problem:
Since the
Value
of anAttribute
is defined as of typeinterface{}
, I may think that it accepts all usual types (such as[]byte
,string
, and even numbers).The problem is that when I
SetAttributeString(`target`, `_blank`)
of aLink
, theRenderAttributes
function force the Value to be[]byte
, which results in runtime panic.https://github.com/yuin/goldmark/blob/ce6424aa0e15504f675a0f224972d3c8d0c86654/renderer/html/html.go#L789
The solution:
I switch cased the type and rewritten the code as below:
I cannot assume that people don't force the Value to be of type
[]byte
, or that they already know that, and whileSetAttributeString
, use[]byte
. May god bless all those who switch caseNode::AttributeString()
's return value.