Repository: PumasAI/QuartoNotebookRunner.jl (julia)

Issue:
Pdf plotting is broken (worked on iJulia)
Conside the follwoing: 

````
---
title: "title"
engine: julia
format: beamer # or pdf
---


# Intro

## Slide working 
bla bla 

## Slide not working 

```{julia}
#| echo: false
#| fig-cap: "my caption"
using Random, Plots
x = rand(2,1000)
scatter(x[1,:],x[2,:])
```
````

Produces: 

```
Error showing value of type Plots.Plot{Plots.GRBackend}
only png or svg allowed. got: :pdf
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:35
 [2] _show(io::IOContext{IOBuffer}, ::MIME{Symbol("text/html")}, plt::Plots.Plot{Plots.GRBackend})
   @ Plots [...]\src\output.jl:203
 [3] #invokelatest#2
   @ .\essentials.jl:887 [inlined]
 [4] invokelatest
   @ .\essentials.jl:884 [inlined]
 [5] show(io::IOContext{IOBuffer}, m::MIME{Symbol("text/html")}, plt::Plots.Plot{Plots.GRBackend})
   @ Plots [...]\src\output.jl:232
 [6] show(io::IOContext{IOBuffer}, m::String, x::Plots.Plot{Plots.GRBackend})
   @ Base.Multimedia .\multimedia.jl:123
```

Is there a quick workaround ?

Pull request description:

Patch:
diff --git a/src/QuartoNotebookWorker/ext/QuartoNotebookWorkerPlotsExt.jl b/src/QuartoNotebookWorker/ext/QuartoNotebookWorkerPlotsExt.jl
index a08ff3c6..880ad514 100644
--- a/src/QuartoNotebookWorker/ext/QuartoNotebookWorkerPlotsExt.jl
+++ b/src/QuartoNotebookWorker/ext/QuartoNotebookWorkerPlotsExt.jl
@@ -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
 
diff --git a/src/QuartoNotebookWorker/src/render.jl b/src/QuartoNotebookWorker/src/render.jl
index 0f943d51..0e8b17d3 100644
--- a/src/QuartoNotebookWorker/src/render.jl
+++ b/src/QuartoNotebookWorker/src/render.jl
@@ -396,6 +396,7 @@ function render_mimetypes(value, cell_options)
             "text/latex",
             "image/svg+xml",
             "image/png",
+            "application/pdf",
             "application/json",
         ]
     end
diff --git a/src/server.jl b/src/server.jl
index 526a1f2d..518b6567 100644
--- a/src/server.jl
+++ b/src/server.jl
@@ -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,


Test patch:
diff --git a/test/examples/integrations/PlotsPDF.qmd b/test/examples/integrations/PlotsPDF.qmd
new file mode 100644
index 00000000..5d2520ef
--- /dev/null
+++ b/test/examples/integrations/PlotsPDF.qmd
@@ -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)
+```
\ No newline at end of file
diff --git a/test/testsets/integrations/Plots.jl b/test/testsets/integrations/Plots.jl
index 2d5a5beb..66dc93d4 100644
--- a/test/testsets/integrations/Plots.jl
+++ b/test/testsets/integrations/Plots.jl
@@ -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