A filter to auto-generate a code appendix in rendered Quarto documents #12498
Replies: 2 comments 3 replies
-
Awesome ! Nice idea! Could you open a PR in quarto-dev/quarto-web to list your extension in https://quarto.org/docs/extensions/ ? Thanks ! |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing.
May I ask you to harmonise the code cell options to only use YAML syntax instead of mixing R inline and YAML syntaxes? ```{r}
#| echo: true
#| eval: false
#| ref-label: r-code
``` |
Beta Was this translation helpful? Give feedback.
-
Description
Overview
I recently made a lua filter called
code-appendix
that moves the display of code chunks whenecho: true
to an appendix at the end of rendered Quarto documents. It can also write the code chunks to a user-defined file as a side effect, if desired. I have so far tested it withpdf
,typst
,html
anddocx
formats.Use case
This filter is useful when you want to show the outputs of analysis code in a Quarto document but don't want the code chunks themselves displayed until the very end. Such a scenario might be a homework assignment, an analysis report to both technical and non-technical readers, or a blog post which focuses on analysis rather than code (i.e., not a tutorial).
An example
The traditional way to control the location of code chunks in the rendered
.qmd
(or.rmd
) document is to useref-label
(when usingknitr
engine). For example, as discussed in #6650. An example of creating a code appendix usingref-label
is:My
code-appendix
filter represents a simpler but less flexible tool to achieve the same goal. The same example above using the filter:Features
The default behavior of
code-appendix
is to stop the rendering of code chunks throughout the main body of the document and instead display them altogether in an appendix at the end. The title of the appendix can be controlled with YAML options.As a side-effect, the filter can write the content of the code chunks to a file specified in the YAML. This is useful for two reasons:
.qmd
file into a working.r
or.py
script on rendering.qmd
file containing the analysis code. This can be handy as it allows the user to make edits to the code appendix by hand and can then be included in the main document via the{{< include >}}
shortcode.Beta Was this translation helpful? Give feedback.
All reactions