JuliaWeb / Hyperscript.jl

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

Raw string rendering #14

Closed tshort closed 5 years ago

tshort commented 5 years ago

I need to output un-encoded strings that include raw HTML. This is easy enough to implement externally:

struct Raw
    str::String
end
Base.show(io::IO, m::MIME"text/html", rawstr::Raw) = print(io, rawstr.str)

Example:

julia> m("div", Raw("<span>hi</span>"))
<div><span>hi</span></div>

Is there any interest in having this in Hyperscript?

yurivish commented 5 years ago

I was going to mention @tags_noescape, and m(Hyperscript.NOESCAPE_HTMLSVG_CONTEXT, "div", "<span>hi</span>"), but doesn't your last PR actually solve this for us?

julia> @tags div

julia> div("<span>hi</span>")
<div>&#60;span&#62;hi&#60;/span&#62;</div>

julia> div(HTML("<span>hi</span>"))
<div><span>hi</span></div>
tshort commented 5 years ago

Nice! Thanks, @yurivish.

tshort commented 5 years ago

Thanks also for the reminder on @tags_noescape. That will be helpful for me in another scenario.