Skip to content

Code cell inside Callout should still be runnable code cell when output if format: ipynb #13510

@cderv

Description

@cderv

Discussed in #13502

Originally posted by florian-wagner October 5, 2025

Description

Dear quarto community,

I would like to make code solutions available to students as a collapsible callout. This works great in HTML, but students should also be able to download the solutions as Jupyter notebooks to run the code (without callouts). Please find a minimal working example below. Unfortunately, the default behavior of replacing callouts with blockquotes in unsupported formats, breaks the Jupyter code cell. I have played with conditional content based on the output format, but I cannot put the opening and closing fences as conditional content.

Any idea how to solve this?

Thanks a lot!

---
title: Callouts for HTML, but not for notebooks
format:
  html: default
  ipynb: default
engine: jupyter
---

## First try (looks good in html, but breaks code cell in notebook)

Q: What is 1 + 1?

::: {.callout-tip collapse="true"}
# Solution

```{python}
print(1 + 1)
```
:::

Additional notes

Currently the default rendered is to use Blockquote

-- default renderer first
_quarto.ast.add_renderer("Callout", function(_)
return true
end, function(node)
node = _quarto.modules.callouts.decorate_callout_title_with_crossref(node)
local contents = _quarto.modules.callouts.resolveCalloutContents(node, true)
local callout = pandoc.BlockQuote(contents)
local result = pandoc.Div(callout, pandoc.Attr(node.attr.identifier or ""))
return result
end)

When format: ipynb is expected, this will break the code cell that won't be a computation cell anymore.

A custom renderer for Ipynb format should be used with a different default.

Ideas:

  • Only keep the content as is, so something like
Callout = function(callout) 
    if quarto.doc.is_format("ipynb") then
        return callout.content
    end
    return callout
end
  • Or try to be more clever and keep all content withing Blockquote except for computation code cells (which are probably identifiable by Div with class .cell

  • Or something else... ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions