Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle application/pdf mimetypes #136

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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...)

Check warning on line 36 in src/QuartoNotebookWorker/ext/QuartoNotebookWorkerPlotsExt.jl

View check run for this annotation

Codecov / codecov/patch

src/QuartoNotebookWorker/ext/QuartoNotebookWorkerPlotsExt.jl#L36

Added line #L36 was not covered by tests
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format wasn't really relevant to pass here, since we call show on each valid mimetype rather than relying on the default format set here. The addition of application/pdf support seems to resolve this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what I gathered from the linked Plots code as well. I'm not sure what backends would actually use pdf assets if we offer them, maybe latex-based ones.


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
Loading