Expose style attribute serializer as a function
fonsp opened this issue · 0 comments
fonsp commented
HypertextLiteral has the ability to format a style
attribute from a Julia Dict, Pair or NamedTuple:
@htl "<img style=$((width="10px", background="white"))>"
It would be cool if this ability was also available as a standalone function:
julia> HypertextLiteral.serialize_style_attribute((width="10px", background="white")) # or a better name
"width: 10px; background: white;"
I ran into this several times when working with widgets that set their initial style with HypertextLiteral (accepting style as a user input), but a later update will set the style from JS, so I need to give the new style attribute value to JS as a string.
My current solution is:
serialize_style_attribute(nt) = @view repr(
MIME"text/html"(),
@htl "<div style=$(nt)>"
)[13:end-2]