diff --git a/src/Kroki.jl b/src/Kroki.jl index c7ac955..fca479e 100644 --- a/src/Kroki.jl +++ b/src/Kroki.jl @@ -229,6 +229,8 @@ const LIMITED_DIAGRAM_SUPPORT = Dict{MIME, Tuple{Symbol, Vararg{Symbol}}}( # that actually support the format Base.show(io::IO, ::MIME"application/pdf", diagram::Diagram) = write(io, render(diagram, "pdf")) +Base.show(io::IO, ::MIME"image/jpeg", diagram::Diagram) = + write(io, render(diagram, "jpeg")) Base.show(io::IO, ::MIME"image/png", diagram::Diagram) = write(io, render(diagram, "png")) @@ -241,6 +243,16 @@ Base.show(io::IO, ::MIME"image/svg+xml", diagram::Diagram) = Base.showable(::T, diagram::Diagram) where {T <: MIME} = Symbol(lowercase(String(diagram.type))) ∈ get(LIMITED_DIAGRAM_SUPPORT, T(), Tuple([])) +# Calling `Base.show` for JPEGs is explicitly disabled, for the time being. +# JPEG rendering is broken for all, supposedly supported, diagram types in the +# Kroki service. Should the support be fixed in the service, this method can be +# easily redefined by consuming software to support JPEG in case Kroki.jl has +# not been updated and released. +# +# Note that this only affects automatic rendering of `Diagram`s to JPEGs in +# supported environments. It is still possible to use `render` to render JPEGs +Base.showable(::MIME"image/jpeg", ::Diagram) = false + # The two-argument `Base.show` version is used to render the "text/plain" MIME # type. Those `Diagram` types that can render text versions, e.g. PlantUML, # Structurizr, should render those. All others should render their diff --git a/test/runtests.jl b/test/runtests.jl index 1cf3fc9..ab5f4f9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -200,6 +200,11 @@ end @test !showable("application/pdf", svgbob_diagram) @test_throws(InvalidOutputFormatError, sprint(show, MIME"image/png"(), svgbob_diagram)) @test !showable(MIME"image/png"(), svgbob_diagram) + @test_throws( + InvalidOutputFormatError, + show(IOBuffer(), MIME"image/jpeg"(), svgbob_diagram) + ) + @test !showable("image/jpeg", svgbob_diagram) testShowMethodRenders(svgbob_diagram, MIME"image/svg+xml"(), "svg") @test !showable("non-existent/mime-type", svgbob_diagram)