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

JSString should be printable to text/javascript #40

Open
clarkevans opened this issue May 2, 2021 · 0 comments
Open

JSString should be printable to text/javascript #40

clarkevans opened this issue May 2, 2021 · 0 comments

Comments

@clarkevans
Copy link

Hello. So, the HTML object permits one to create objects that are HTML fragments, suitable to be displayed as "text/html".

julia> obj = HTML("<span>Hi</span>")
HTML{String}("<span>Hi</span>")
julia> display("text/html", obj)
<span>Hi</span>

The same should be true for JSString.

julia> expr = @js for i in 1:10
           console.log(i)
       end
JSString("for(var i = 1; i <= 10; i = i + 1){console.log(i)}")
julia> display("text/javascript", expr)
ERROR: MethodError: no method matching show(::Base.TTY, ::MIME{Symbol("text/javascript")}, ::JSString)

This issue can be addressed with the following:

julia> Base.show(io::IO, ::MIME"text/javascript", js::JSString) = 
           print(io, js)

julia> display("text/javascript", expr)
for(var i = 1; i <= 10; i = i + 1){console.log(i)}

Thanks.

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