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.
display(::InlineDisplay, x)callsdisplay_dict(x)which iterates throughijulia_mime_typesandijulia_jsonmime_typesseparately, and callsdisplay_mimestringanddisplay_mimejsonas appropriate. In contrast,display(::InlineDisplay, ::MIME, x)always callsdisplay_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
isjsonmimewhich functions similarly toBase.istextmime. A simple implementation would just be to check whether the mime type is inijulia_jsonmime_types.I think a better implementation would be to encode JSON-ness in a type trait, like the following:
This would eliminate the need for separate JSON versions of many methods.