|
1 | 1 | --- |
2 | | -title: "Home" |
3 | | -format: |
| 2 | +title: "Toggle" |
| 3 | +subtitle: "Let readers control output visibility in Quarto documents" |
| 4 | +format: |
4 | 5 | html: |
5 | | - toc: false |
| 6 | + toc: true |
6 | 7 | --- |
7 | 8 |
|
8 | | -The `toggle` extension allows you to toggle between showing code with output or just code by itself in Quarto HTML documents by adding a convenient toggle button that appears when hovering over code blocks, similar to the copy button. |
| 9 | +Ever wished readers could hide verbose output while keeping the code visible? |
| 10 | +The `toggle` extension adds a button to your code blocks that shows or hides |
| 11 | +the output on demand. |
9 | 12 |
|
10 | | -## Installation |
11 | | - |
12 | | -To install the `toggle` extension, follow these steps: |
13 | | - |
14 | | -1. Open your terminal. |
| 13 | +Think of it as the opposite of Quarto's |
| 14 | +[`code-fold`](https://quarto.org/docs/output-formats/html-code.html#folding-code). |
| 15 | +Instead of hiding code and showing output, toggle hides output and shows code. |
15 | 16 |
|
16 | | -2. Execute the following command: |
| 17 | +## Installation |
17 | 18 |
|
18 | 19 | ```bash |
19 | 20 | quarto add coatless-quarto/toggle |
20 | 21 | ``` |
21 | 22 |
|
22 | | -This command will download and install the extension under the `_extensions` subdirectory of your Quarto project. If you are using version control, ensure that you include this directory in your repository. |
23 | | - |
24 | | -## Usage |
| 23 | +## Quick Start |
25 | 24 |
|
26 | | -At the top of your Quarto document, include the `filters` key with `toggle` specified in the YAML header: |
| 25 | +Add the filter and enable toggle for all cells: |
27 | 26 |
|
28 | 27 | ```yaml |
29 | | ---- |
30 | | -title: "My Document" |
31 | | -format: html |
| 28 | +extensions: |
| 29 | + toggle: |
| 30 | + output-toggle: true |
32 | 31 | filters: |
33 | 32 | - toggle |
34 | | ---- |
35 | 33 | ``` |
36 | 34 |
|
37 | | -This will allow the toggle extension to be applied to your document. |
38 | | - |
39 | | -### Cell-Level Configuration |
| 35 | +Hover over any code block to see the toggle button appear. Click to hide the |
| 36 | +output; click again to show it. |
40 | 37 |
|
41 | | -To enable toggle functionality for a specific code cell, add the `toggle: true` attribute: |
42 | | - |
43 | | -````md |
44 | | -```{{python}} |
45 | | -#| toggle: true |
46 | | -print("Hello, Python world!") |
47 | | -``` |
48 | | -```` |
49 | | - |
50 | | -You can also set whether the output is shown or hidden by default using the `output-hidden` attribute: |
| 38 | +To enable toggle for specific cells only, omit `output-toggle` and add |
| 39 | +`#| toggle: true` to individual cells: |
51 | 40 |
|
52 | 41 | ````md |
53 | 42 | ```{{r}} |
54 | 43 | #| toggle: true |
55 | | -#| output-hidden: true |
56 | | -print("Hello, R world!") |
| 44 | +summary(mtcars) |
57 | 45 | ``` |
58 | 46 | ```` |
59 | 47 |
|
60 | | -This will hide the output by default, and the user can click the toggle button to show it. |
| 48 | +## Options |
61 | 49 |
|
62 | | -### Document-Level Configuration |
| 50 | +Set these under `extensions.toggle` or per-cell with `#|` comments: |
63 | 51 |
|
64 | | -You can enable toggle functionality for all code cells in your document by adding the following to your YAML header: |
| 52 | +| Option | Default | Purpose | |
| 53 | +|--------|---------|---------| |
| 54 | +| `output-toggle` | `false` | Add toggle buttons to all cells | |
| 55 | +| `output-hidden` | `false` | Start with outputs collapsed | |
| 56 | +| `output-sync` | `false` | Sync all outputs in a cell together | |
| 57 | +| `global-toggle` | `false` | Floating button to toggle everything | |
| 58 | +| `persist` | `false` | Remember state across page reloads | |
| 59 | +| `button-text` | `"Output"` | Label shown on the button | |
65 | 60 |
|
66 | | -```yaml |
67 | | ---- |
68 | | -title: "My Document" |
69 | | -format: html |
70 | | -toggle: |
71 | | - output-toggle: true # Enable toggle buttons for all cells |
72 | | - output-hidden: false # Show outputs initially (default) |
73 | | -filters: |
74 | | - - toggle |
75 | | ---- |
76 | | -``` |
| 61 | +## Compatibility |
77 | 62 |
|
78 | | -#### Priority of Settings |
| 63 | +Works with HTML-based Quarto formats: documents, websites, books, and Revealjs |
| 64 | +presentations. |
79 | 65 |
|
80 | | -- Cell-level settings override document-level settings |
81 | | -- If no cell-level setting is provided, document-level settings apply |
82 | | -- If neither is provided, toggle is not enabled for that cell |
| 66 | +Toggle complements Quarto's |
| 67 | +[`code-fold`](https://quarto.org/docs/output-formats/html-code.html#folding-code). |
| 68 | +Use both together: |
83 | 69 |
|
84 | | -## Help |
| 70 | +```yaml |
| 71 | +format: |
| 72 | + html: |
| 73 | + code-fold: true |
| 74 | +extensions: |
| 75 | + toggle: |
| 76 | + output-toggle: true |
| 77 | +``` |
85 | 78 |
|
86 | | -To report a bug, please [add an issue](https://github.com/coatless-quarto/toggle/issues/new) to the repository's [bug tracker](https://github.com/coatless-quarto/toggle/issues). |
| 79 | +PDF, Word, and other non-HTML formats are unaffected. |
87 | 80 |
|
88 | | -Want to contribute a feature? Please open an issue ticket to discuss the feature before sending a pull request. |
| 81 | +## Getting Help |
89 | 82 |
|
| 83 | +- [FAQ](qtoggle-faq.qmd) — Common questions |
| 84 | +- [GitHub Issues](https://github.com/coatless-quarto/toggle/issues) — Bug reports |
| 85 | +- [Discussions](https://github.com/coatless-quarto/toggle/discussions) — Questions |
0 commit comments