Skip to content

Code echo is hoisted out of a layout div when the cell is nested inside another div #14841

Description

@mcanouil

I have:

  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI
  • formatted my issue following the Bug Reports guide

Bug description

Reported by @rchaput in https://github.com/orgs/quarto-dev/discussions/14824.

When an executable cell is placed inside a div that is itself inside a div with a layout attribute, the echoed source of the cell is moved out of the layout and emitted before the whole layout panel.
Only the cell outputs stay inside the layout cell.

A static code block in the same position is left in place.
The difference in treatment comes from the cell-code class that the engine adds to the echo of an executable cell.
This makes the behaviour depend on whether the code block came from execution, not on the document structure the author wrote.

Two further effects follow from the same move:

  • Any class on the div that contained the cell is lost for the echo.
    In the RevealJS case of the discussion, the echo is inside ::: {.fragment} but is never shown as a fragment.
  • Document order is broken, because the echo is placed before content that the author wrote before it.

The behaviour is not specific to RevealJS or to Jupyter.
It reproduces with format: html and with the knitr engine.

Steps to reproduce

---
title: Test code fragments in Revealjs
format: revealjs
---

## Slide 1

:::: {layout="[50, 50]"}
::: {}
- A list of items
- That should appear on the left side
:::

::: {.fragment}
A code fragment that should appear on the right side

```{python}
#| echo: true
print("Hello from Python")
```
:::
::::

The same result occurs with format: html, and with an {r} cell on the knitr engine.

Actual behavior

The echoed code block is emitted as a sibling before <div class="quarto-layout-panel">.

<section id="slide-1" class="slide level2">
<h2>Slide 1</h2>
<div class="sourceCode cell-code" id="cb1">...print("Hello from Python")...</div>
<div class="quarto-layout-panel" data-layout="[50, 50]">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" ...>
<ul>
<li>A list of items</li>
<li>That should appear on the left side</li>
</ul>
</div>
<div class="fragment quarto-layout-cell" ...>
<p>A code fragment that should appear on the right side</p>
<div class="cell" data-execution_count="1">
<div class="cell-output cell-output-stdout">
<pre><code>Hello from Python</code></pre>
</div>
</div>
</div>
</div>
</div>
</section>

For comparison, the same document with a static ```python block instead of the executable cell keeps the code block inside the layout cell.

Expected behavior

The echoed code block stays inside the layout cell, next to its outputs, in the order the author wrote it.
It keeps the classes of the div that contains it, so .fragment applies to it in RevealJS.

Your environment

  • IDE: none, run from the terminal.
  • OS: macOS 26.6.2 (build 25G83).

Quarto check output

$ quarto check
Quarto 99.9.9
[✓] Checking environment information...
      Quarto cache location: /Users/mcanouil/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.10.0: OK
      Dart Sass version 1.101.0: OK
      Deno version 2.7.14: OK
      Typst version 0.15.1: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      commit: 7eebb00b94674e7f7c6b23c2e994b352b912e7c5
      Path: /Users/mcanouil/Projects/quarto-dev/quarto-cli/package/dist/bin
[✓] Checking tools....................OK
      TinyTeX: v2026.07
      Chrome Headless Shell: (not installed)
      VeraPDF: (not installed)
[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/mcanouil/Library/TinyTeX/bin/universal-darwin
      Version: 2026
[✓] Checking Chrome Headless....................OK
      Using: Chrome from QUARTO_CHROMIUM
      Path: /Applications/Brave Browser.app/Contents/MacOS/Brave Browser
[✓] Checking basic markdown render....OK
[✓] Checking R installation...........OK
      Version: 4.6.1
      Path: /Library/Frameworks/R.framework/Versions/4.6/Resources
      knitr: 1.51
      rmarkdown: 2.31
[✓] Checking Knitr engine render......OK
[✓] Checking Python 3 installation....OK
      Version: 3.12.13
      Jupyter: 5.9.1
      Kernels: julia-1.12, python3
[✓] Checking Jupyter engine render....OK

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions