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

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

Open
devmotion opened this issue Nov 5, 2024 · 8 comments
Open

Comments

@devmotion
Copy link
Contributor

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
    ```

```{julia}
3 + 4
```

I ran

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
    ```

```{r}
3 + 4
```

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

image
@MichaelHatherly
Copy link
Collaborator

QuartoNotebookRunner only handles top-level code blocks?

Yes, that's currently all that is implemented.

@devmotion
Copy link
Contributor Author

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

@MichaelHatherly
Copy link
Collaborator

This is an upstream discussion: quarto-dev/quarto-cli#9970. Particularly: quarto-dev/quarto-cli#9970 (comment), since this package outputs ipynb JSON the same as Jupyter does.

@devmotion
Copy link
Contributor Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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"
```

:::

- first list entry
- Here's a list entry that contains the output of a code cell
  {{< contents nested-codeblock >}}
- another list entry that has a nested entry
  - and even in the nested entry you can place that content
    {{< contents nested-codeblock >}}
image

@devmotion
Copy link
Contributor Author

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

@jkrumbiegel
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants