Quarto

Quarto
A collection of short Quarto code snippets and tricks that individually are too short for a blog post
Author

LW Pembleton

Modified

November 30, 2023

~Photo by Solstice Hannan on Unsplash~

Folding Non-Executable Code in Quarto Documents

In Quarto, folding non-executable code blocks may seem challenging since the built-in code-folding `#| code-fold: true` for non-executed blocks is not supported. This can be particularly inconvenient when working with extensive external commands like bash scripts used for data preprocessing.

Fortunately, a simple solution is available, as shared in response to a Quarto GitHub issue. You can achieve code folding for non-executable code by wrapping it in HTML <details> tags. Here’s an example:

<details>
<summary>Code: My non-executable code</summary>

```bash
cat vcf_file | sed -n '/#CHROM/,$p' | cut -f 1,2,4,5 > variant_info.txt 
```

</details>

Which when rendered will look like 👇

Code: My non-executable code
cat vcf_file | sed -n '/#CHROM/,$p' | cut -f 1,2,4,5 > variant_info.txt 

This method allows you to organize and present non-executable code blocks more effectively in your Quarto documents.