Skip to content

Commit

Permalink
Handle application/pdf mimetypes (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHatherly authored May 24, 2024
1 parent 224d278 commit 65ab142
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/QuartoNotebookWorker/ext/QuartoNotebookWorkerPlotsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ function configure()
dpi_kwargs = Dict{Symbol,Any}()
end

pkgid = Base.PkgId(Plots)
if (QuartoNotebookWorker._pkg_version(pkgid) < v"1.28.1") && (fm.fig_format == "pdf")
Plots.gr(; size_kwargs..., fmt = :png, dpi_kwargs...)
else
Plots.gr(; size_kwargs..., fmt = fm.fig_format, dpi_kwargs...)
end
Plots.gr(; size_kwargs..., dpi_kwargs...)

return nothing
end

Expand Down
1 change: 1 addition & 0 deletions src/QuartoNotebookWorker/src/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ function render_mimetypes(value, cell_options)
"text/latex",
"image/svg+xml",
"image/png",
"application/pdf",
"application/json",
]
end
Expand Down
1 change: 1 addition & 0 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ just has to provide bytes.
function process_results(dict::Dict{String,@NamedTuple{error::Bool, data::Vector{UInt8}}})
funcs = Dict(
"application/json" => json_reader,
"application/pdf" => Base64.base64encode,
"text/plain" => String,
"text/markdown" => String,
"text/html" => String,
Expand Down
17 changes: 17 additions & 0 deletions test/examples/integrations/PlotsPDF.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Plots integration
fig-width: 4
fig-height: 3
fig-dpi: 150
fig-format: pdf
julia:
exeflags: ["--project=Plots"]
---

```{julia}
import Plots
```

```{julia}
Plots.plot(Plots.fakedata(50, 5), w = 3)
```
9 changes: 9 additions & 0 deletions test/testsets/integrations/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ test_example(joinpath(@__DIR__, "../../examples/integrations/Plots.qmd")) do jso
@test cell["outputs"][1]["metadata"]["image/png"] ==
Dict("width" => 575, "height" => 432) # Plots does not seem to follow standard dpi rules so the values don't match Makie
end

test_example(joinpath(@__DIR__, "../../examples/integrations/PlotsPDF.qmd")) do json
cells = json["cells"]

cell = cells[4]
output = cell["outputs"][1]

@test !isempty(output["data"]["application/pdf"])
end

0 comments on commit 65ab142

Please sign in to comment.