JuliaWeb / Hyperscript.jl

Hyperscript: A lightweight DOM representation for Julia
Other
101 stars 11 forks source link

Using Symbols as attribute values #3

Closed tshort closed 6 years ago

tshort commented 6 years ago

In some cases, it'd be nice to be able to use Symbols instead of Strings for some values, especially ones that are names. Here's ana example:

julia> m("div", id = :hi, "hello")
<div id=":hi">hello</div>

Right now, this symbol is rendered as ":hi" rather than "hi". The sprint(show, ...) construct causes this. Would it be possible to use print instead to get rid of the colon? Or, could we have some other way to do that?

Great package, by the way! I really like the div.someclass and div."some-class" syntax.

yurivish commented 6 years ago

Hi Tom, thanks for the issue — I think this makes sense, and am trying to remember why I thought using show was a good idea at the time. I still occasionally get confused by the printing infrastructure, but revisiting this it looks like print is the better choice here since we don't want to print Julia-specific formatting to the web if there's a better canonical representation.

I just pushed a commit to make your suggested change. And now:

julia> m("div", id = :hi, "hello")
<div id="hi">hello</div>

Great package, by the way! I really like the div.someclass and div."some-class" syntax.

Thanks!