Reputation: 1219
In Quarto, I'd like to change the default behavior of a single callout block type so that it will
collapse="true"
)Let's say I want this for the tip
callout block type while the others (note
, warning
, caution
, and important
) should not be affected.
In other words, I want the behavior/output of this:
:::{.callout-tip collapse="true"}
## Additional Resources
- Resource 1
- Resource 2
:::
by only having to write this:
:::{.callout-tip}
- Resource 1
- Resource 2
:::
Upvotes: 2
Views: 1288
Reputation: 55
Bit late to the party, but still gonna put it out there:
You can specify the title for a block-type in the file _quarto.yml
.
callout-tip-title: "Resources"
Sadly, there isn't an option to collapse callout-blocks by default.
You can find more useful yaml-defaults here.
For example, I tend to remove the callout-icons with callout-icon: false
.
Upvotes: 0
Reputation: 20027
Update:
I have actually converted the following lua filter into a quarto filter extension collapse-callout
, which allows specifying default options for specific callout blocks more easily. See the github readme for detailed instructions on installation and usage.
As @stefan mentioned, you can use pandoc Lua filter to do this more neatly.
quarto_doc.qmd
---
title: "Callout Tip"
format: html
filters:
- custom-callout.lua
---
## Resources
:::{.custom-callout-tip}
- Resource 1
- Resource 2
:::
## More Resources
:::{.custom-callout-tip}
- Resource 3
- Resource 4
:::
custom-callout.lua
local h2 = pandoc.Header(2, "Additional Resources")
function Div(el)
if quarto.doc.isFormat("html") then
if el.classes:includes('custom-callout-tip') then
local content = el.content
table.insert(content, 1, h2)
return pandoc.Div(
content,
{class="callout-tip", collapse='true'}
)
end
end
end
Just make sure that quarto_doc.qmd
and custom-callout.lua
files are in the same directory (i.e. folder).
Upvotes: 3
Reputation: 125408
After a look at the docs and based on my experience with customizing Rmarkdown I would guess that this requires to create a custom template and/or the use of pandoc Lua filters.
A more lightweight approach I used in the past would be to use a small custom function to add the code for your custom callout block to your Rmd or Qmd. One drawback is that this requires a code chunk. However, to make your life a bit easier you could e.g. create a RStudio snippet to add a code chunk template to your document.
---
title: "Custom Callout"
format: html
---
```{r}
my_call_out <- function(...) {
cat(":::{.callout-tip collapse='true'}\n")
cat("## Additional Resources\n")
cat(paste0("- ", ..., collapse = "\n\n"))
cat("\n:::\n")
}
```
```{r results="asis"}
my_call_out(paste("Resource", 1:2))
```
Blah blah
```{r results="asis"}
my_call_out("Resource 3", "Resource 4")
```
Blah blah
Upvotes: 3