Skip to content

Commit c3cca5c

Browse files
committed
code-appendix readme
1 parent a4eeb83 commit c3cca5c

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

README.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,70 @@
1-
# Code-appendix Extension For Quarto
1+
# `code-appendix` Extension For Quarto
22

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.
47

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`.
637

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
850

951
```bash
10-
quarto add <github-organization>/code-appendix
52+
quarto add cl-roberts/.lua-filters/code-appendix
1153
```
1254

1355
This will install the extension under the `_extensions` subdirectory.
1456
If you're using version control, you will want to check in this directory.
1557

1658
## Using
1759

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+
```
1968

2069
## Example
2170

0 commit comments

Comments
 (0)