Skip to content

display(::InlineDisplay, ::MIME, x) fails for JSON mimes #990

@jlumpe

Description

@jlumpe

display(::InlineDisplay, x) calls display_dict(x) which iterates through ijulia_mime_types and ijulia_jsonmime_types separately, and calls display_mimestring and display_mimejson as appropriate. In contrast, display(::InlineDisplay, ::MIME, x) always calls display_mimestring. The underlying problem is that there is no way of telling whether a given MIME type should be treated as JSON or not.

What's needed is a function isjsonmime which functions similarly to Base.istextmime. A simple implementation would just be to check whether the mime type is in ijulia_jsonmime_types.

I think a better implementation would be to encode JSON-ness in a type trait, like the following:

abstract type MIMEFormat end
struct TextMIME <: MIMEFormat end
struct BinaryMIME <: MIMEFormat end
struct JSONMIME <: MIMEFormat end

MIMEFormat(mime::MIME) = istextmime(mime) ? TextMIME() : BinaryMIME()

for M in ijulia_jsonmime_types
    MIMEFormat(::M) = JSONMIME()
end

This would eliminate the need for separate JSON versions of many methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions