-
Notifications
You must be signed in to change notification settings - Fork 383
Description
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
quarto-cli/src/resources/filters/customnodes/callout.lua
Lines 124 to 133 in 22ecd3c
-- 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... ?