Skip to content

Contents shortcode does not work on code-cell div with knitr #12065

Open
@mcanouil

Description

@mcanouil

Bug description

It appears {{< contents ID >}} cannot move code-cells with an ID when the engine is set to knitr.

I'm not sure what the limitation actually is:

Currently, {{< contents >}} itself does not work inside code elements. We may lift that limitation in the future.

Steps to reproduce

Jupyter (works)knitr (does not work)
Div
---
title: "Quarto Playground"
format: html
engine: jupyter
---

## Section 1

```{python}
#| label: my-figure
import matplotlib.pyplot as plt
plt.plot([1,2,3])
```

## Section 2

{{< contents my-figure >}}
---
title: "Quarto Playground"
format: html
engine: knitr
---

## Section 1

```{r}
#| label: my-figure
plot(1:10)
```

## Section 2

{{< contents my-figure >}}
Cross-ref Div
---
title: "Quarto Playground"
format: html
engine: jupyter
---

## Section 1

```{python}
#| label: fig-figure
import matplotlib.pyplot as plt
plt.plot([1,2,3])
```

## Section 2

{{< contents fig-figure >}}
---
title: "Quarto Playground"
format: html
engine: knitr
---

## Section 1

```{r}
#| label: fig-figure
plot(1:10)
```

## Section 2

{{< contents fig-figure >}}

Expected behavior

Content is moved without warning.

Actual behavior

WARNING (/Users/mcanouil/Projects/quarto/quarto-cli/src/resources/filters/./quarto-pre/contentsshortcode.lua:79) [Malformed document] Found `contents` shortcode without a corresponding div with id: my-figure.
This might happen because the shortcode is used in div context, while the id corresponds to a span.
Removing from document.
WARNING (/Users/mcanouil/Projects/quarto/quarto-cli/src/resources/filters/./quarto-pre/contentsshortcode.lua:79) [Malformed document] Found `contents` shortcode without a corresponding div with id: fig-figure.
This might happen because the shortcode is used in div context, while the id corresponds to a span.
Removing from document.

Your environment

No response

Quarto check output

Quarto 99.9.9
[✓] Checking environment information...
      Quarto cache location: /Users/mcanouil/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      commit: b822c3f5cc2b7dd57238bed2bcbbd2c2ed7688b8
      Path: /Users/mcanouil/Projects/quarto/quarto-cli/package/dist/bin

[✓] Checking tools....................OK
      TinyTeX: v2025.02
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/mcanouil/Library/TinyTeX/bin/universal-darwin
      Version: 2024

[✓] Checking Chrome Headless....................OK
      Using: Chrome found on system
      Path: /Applications/Brave Browser.app/Contents/MacOS/Brave Browser
      Source: QUARTO_CHROMIUM

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.13.2
      Path: /Users/mcanouil/Projects/quarto/quarto-playground/.venv/bin/python
      Jupyter: 5.7.2
      Kernels: julia-1.11, python3

[✓] Checking Jupyter engine render....OK

(|) Checking R installation...........ℹ R version 4.4.2 (2024-10-31)
! Config '~/.Rprofile' was loaded!
[✓] Checking R installation...........OK
      Version: 4.4.2
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Users/mcanouil/Projects/quarto/quarto-playground/renv/library/macos/R-4.4/aarch64-apple-darwin20
        - /Users/mcanouil/Library/Caches/org.R-project.R/R/renv/sandbox/macos/R-4.4/aarch64-apple-darwin20/f7156815
      knitr: 1.46
      rmarkdown: 2.29

[✓] Checking Knitr engine render......OK

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingearly-in-releaseAn issue that should be worked on early in the release (likely due to risk)knitrshortcodesissues related to shortcodes

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions