mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
convert attribute values to strings
This commit is contained in:
parent
66a48f66b8
commit
afb6db3f1a
1 changed files with 23 additions and 2 deletions
|
|
@ -651,8 +651,29 @@ func RenderAttributes(w util.BufWriter, node ast.Node, filter util.BytesFilter)
|
||||||
_, _ = w.WriteString(" ")
|
_, _ = w.WriteString(" ")
|
||||||
_, _ = w.Write(attr.Name)
|
_, _ = w.Write(attr.Name)
|
||||||
_, _ = w.WriteString(`="`)
|
_, _ = w.WriteString(`="`)
|
||||||
// TODO: convert numeric values to strings
|
// convert attribute values to strings
|
||||||
_, _ = w.Write(util.EscapeHTML(attr.Value.([]byte)))
|
var value []byte
|
||||||
|
switch v := attr.Value.(type) {
|
||||||
|
case []byte:
|
||||||
|
value = v
|
||||||
|
case string:
|
||||||
|
value = util.StringToReadOnlyBytes(v)
|
||||||
|
case float64:
|
||||||
|
value = util.StringToReadOnlyBytes(
|
||||||
|
strconv.FormatFloat(v, 'f', -1, 32))
|
||||||
|
case []interface{}:
|
||||||
|
var buf bytes.Buffer
|
||||||
|
for i, obj := range v {
|
||||||
|
if i > 0 {
|
||||||
|
_ = buf.WriteByte(' ')
|
||||||
|
}
|
||||||
|
_, _ = fmt.Fprint(&buf, obj)
|
||||||
|
}
|
||||||
|
value = buf.Bytes()
|
||||||
|
default:
|
||||||
|
value = util.StringToReadOnlyBytes(fmt.Sprint(v))
|
||||||
|
}
|
||||||
|
_, _ = w.Write(util.EscapeHTML(value))
|
||||||
_ = w.WriteByte('"')
|
_ = w.WriteByte('"')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue