Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose style attribute serializer as a function #40

Open
fonsp opened this issue Jul 12, 2024 · 0 comments
Open

Expose style attribute serializer as a function #40

fonsp opened this issue Jul 12, 2024 · 0 comments

Comments

@fonsp
Copy link
Member

fonsp commented Jul 12, 2024

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant