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

fix display(d, m, x) where m expects a json string #756

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ipy_mime = [
"application/vnd.dataresource+json",
"application/vnd.vegalite.v2+json",
"application/vnd.vega.v3+json",
"application/vnd.vega.v4+json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be handled in the display_dict function, I think.

"text/html",
"text/latex",
"image/svg+xml",
Expand Down Expand Up @@ -47,14 +48,29 @@ function limitstringmime(mime::MIME, x)
return String(take!(buf))
end

const ipy_mime_json = [
"application/vnd.dataresource+json",
"application/vnd.vegalite.v2+json",
"application/vnd.vega.v3+json",
"application/vnd.vega.v4+json",
]
_display_dict(m::MIME, m_str, x) = Dict(m_str=>limitstringmime(m, x))
# escape JSON string correctly before send_ipython
for mime in ipy_mime_json
@eval begin
_display_dict(m::MIME{Symbol($mime)}, m_str, x) = Dict(m_str=>JSON.JSONText(limitstringmime(m, x)))
Base.Multimedia.istextmime(::MIME{Symbol($mime)}) = true
Copy link
Member

@stevengj stevengj Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried that this will conflict with other packages, since we don't "own" this type. (i.e. it is type piracy)

Maybe define _istextmime(::MIME{Symbol($mime)}) = true here, along with a fallback definition

_istextmime(m) = istextmime(m)

and then call _istextmime rather than textmime elsewhere in IJulia.

end
end

for mime in ipy_mime
@eval begin
function display(d::InlineDisplay, ::MIME{Symbol($mime)}, x)
send_ipython(publish[],
msg_pub(execute_msg, "display_data",
Dict(
"metadata" => metadata(x), # optional
"data" => Dict($mime => limitstringmime(MIME($mime), x)))))
"data" => _display_dict(MIME($mime), $mime, x))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than MIME($mime), you should just give the argument ::MIME{Symbol($mime)} a name, e.g. m, and use that. This way _display_dict will be dispatched statically here.

end
displayable(d::InlineDisplay, ::MIME{Symbol($mime)}) = true
end
Expand Down