PumasAI / QuartoNotebookRunner.jl

MIT License
63 stars 10 forks source link

Code blocks in lists not executed - only top-level code supported? #208

Open devmotion opened 13 hours ago

devmotion commented 13 hours ago

I tried to add item-specific code to a Markdown list but it seems currently QuartoNotebookRunner only handles top-level code blocks?

A simple comparison with knitr:

Julia

test_list.qmd:

---
engine: julia
---

A list:

  - One item:
    ```{julia}
    1 + 2
3 + 4

I ran
```julia
julia> using QuartoNotebookRunner

julia> server = QuartoNotebookRunner.Server();

julia> QuartoNotebookRunner.run!(server, "test_list.qmd"; output = "test_list.ipynb")

shell> quarto render test_list.ipynb --to=html

A screenshot of the resulting HTML file:

image

R

test_list_r.qmd:

---
engine: knitr
---

A list:

  - One item:
    ```{r}
    1 + 2
3 + 4


I rendered it within RStudio, resulting in the following ouput:

<img width="840" alt="image" src="https://github.com/user-attachments/assets/6797632c-a77b-462b-b424-6f8efc33105b">
MichaelHatherly commented 13 hours ago

QuartoNotebookRunner only handles top-level code blocks?

Yes, that's currently all that is implemented.

devmotion commented 13 hours ago

On purpose? Or is this limitation (and the example above) considered a bug?

MichaelHatherly commented 13 hours ago

This is an upstream discussion: https://github.com/quarto-dev/quarto-cli/issues/9970. Particularly: https://github.com/quarto-dev/quarto-cli/issues/9970#issuecomment-2163313909, since this package outputs ipynb JSON the same as Jupyter does.

devmotion commented 13 hours ago

I see, the explanation makes sense. From a user perspective, however, I think it's quite unfortunate, I think it would be a very useful feature. For instance, I had a list of different requirements and it would be nice to illustrate each of these requirements with a short code block or generated plot. Putting them later at a top-level introduced unnecessary separation and arguably made it more difficult to read.

MichaelHatherly commented 12 hours ago

The only ways we'll be able to resolve this is either:

  1. Jupyter changes its format to allow for this.
  2. We stop outputting Jupyter JSON and instead implement a similar output to what Knitr does. This is likely a significant change and would incur a heavy maintenance burden on this package.
jkrumbiegel commented 12 hours ago

Note that in quarto 1.6 you can use the new contents shortcode for a workaround:

---
engine: julia
---

::: {#nested-codeblock}

```{julia}
"this should appear" * " in a list"

:::

image
devmotion commented 11 hours ago

Nice, I didn't know that this is possible!

jkrumbiegel commented 9 hours ago

I didn't either 😄 this issue just reminded me of the release notes of 1.6 and then I thought maybe one could be used to solve the other