|
1 |
| -# Code-appendix Extension For Quarto |
| 1 | +# `code-appendix` Extension For Quarto |
2 | 2 |
|
3 |
| -_TODO_: Add a short description of your extension. |
| 3 | +Moves the display of code chunks when `echo: true` to an appendix at the end of |
| 4 | +`.qmd` documents. Also can facilitate writing the code chunks to a user-defined |
| 5 | +file, if desired. Compatible with `pdf`, `typst`, `html`, `docx`, and possibly |
| 6 | +other formats. |
4 | 7 |
|
5 |
| -## Installing |
| 8 | +## Use case |
| 9 | + |
| 10 | +This filter is useful when you want to include the outputs of analysis code in a |
| 11 | +Quarto document but don't want the code chunks themselves displayed until the |
| 12 | +very end. Such a scenario might be a homework assignment, an analysis |
| 13 | +presented to both technical and non-technical readers, or a blog post which focuses |
| 14 | +on the analysis itself (i.e., not a tutorial). |
| 15 | + |
| 16 | +The traditional way to control the location of code chunks in the rendered/knit |
| 17 | +`.qmd`/`.rmd` document is to use `ref.label` (when using `knitr` engine). |
| 18 | +For example [#6650](https://github.com/quarto-dev/quarto-cli/discussions/6650#discussioncomment-6861503). |
| 19 | +This filter represents a simpler but less flexible tool to achieve the same goal. |
| 20 | + |
| 21 | +## Features |
| 22 | + |
| 23 | +When enabled, this filter stops the rendering of code chunks throughout the main |
| 24 | +body of the document and instead prints them altogether in an appendix at the |
| 25 | +end. The behavior of the filter can be controlled using the following YAML options: |
| 26 | + |
| 27 | +- `code-appendix-title: str`. A string giving the code appendix title. Defaults to "Code". |
| 28 | +- `code-appendix-header-level: int`. An integer giving the code appendix header |
| 29 | + level. Defaults to 1. |
| 30 | +- `code-appendix-file: str`. A string giving a path pointing to an external file |
| 31 | + to write the code chunks to. If not specified, no file is written. File path is relative |
| 32 | + to the location of the `.qmd` file for which a code appendix is desired. If |
| 33 | + no file extension is included, the code chunks are written to a `.md` file by |
| 34 | + default. |
| 35 | +- `code-appendix-write: bool`. If `false`, don't create code appendix when rendering |
| 36 | + `.qmd`. If `true` do create code appendix. Defaults to `true`. |
6 | 37 |
|
7 |
| -_TODO_: Replace the `<github-organization>` with your GitHub organization. |
| 38 | +For greatest flexibility, users can write code chunks to an external `.qmd` file |
| 39 | +using `code-appendix-file`, make edits by hand if necessary, then include in the |
| 40 | +main document via the `{{< include >}}` shortcode. Note that this workflow would |
| 41 | +require two renderings: one to create external file and one to render the appendix |
| 42 | +with the `{{< include >}}` shortcode and `code-appendix-write: false` to turn off |
| 43 | +the automatic appendix. |
| 44 | + |
| 45 | +Note that `echo: true` must be set in the document YAML for this filter to be |
| 46 | +useful. Otherwise, no code chunks are available to the filter to create a code |
| 47 | +appendix. |
| 48 | + |
| 49 | +## Installing |
8 | 50 |
|
9 | 51 | ```bash
|
10 |
| -quarto add <github-organization>/code-appendix |
| 52 | +quarto add cl-roberts/.lua-filters/code-appendix |
11 | 53 | ```
|
12 | 54 |
|
13 | 55 | This will install the extension under the `_extensions` subdirectory.
|
14 | 56 | If you're using version control, you will want to check in this directory.
|
15 | 57 |
|
16 | 58 | ## Using
|
17 | 59 |
|
18 |
| -_TODO_: Describe how to use your extension. |
| 60 | +Basic usage requires writing `.qmd` files which contain code chunks that you would |
| 61 | +like to display as an appendix at the end of the document. In the YAML of your Quarto |
| 62 | +document, include the following lines: |
| 63 | + |
| 64 | +``` |
| 65 | +filters: |
| 66 | + - code-appendix |
| 67 | +``` |
19 | 68 |
|
20 | 69 | ## Example
|
21 | 70 |
|
|
0 commit comments