Yes, via showable:
struct Foo
html::Bool
end
Base.showable(::MIME"juliavscode/html", f::Foo) = f.html
Base.show(io::IO, ::MIME"juliavscode/html", f::Foo) = print(io, "<h1>pretty!</h1>")
Base.show(io::IO, ::MIME"text/plain", f::Foo) = print(io, "a bit plain, don't you think?")
Foo(false)
Foo(true)
or by throwing a MethodError to make the display system think your show method doesn’t exist:
struct Bar
html::Bool
end
function Base.show(io::IO, m::MIME"juliavscode/html", f::Bar)
if f.html
print(io, "<h1>pretty!</h1>")
else
throw(MethodError(show, (io, m, f)))
end
end
Bar(false)
Bar(true)