A Quarto extension that adds window-style decorations to code blocks. Three styles are available: macOS traffic lights, Windows title bar buttons, or a plain filename bar. Supports HTML, Reveal.js, and Typst formats.
quarto add mcanouil/quarto-code-window@0.3.0This will install the extension under the _extensions subdirectory.
If you are using version control, you will want to check in this directory.
Add the filter to your document or project:
filters:
- at: pre-quarto
path: code-windowCode blocks with a filename attribute display a window header with the filename.
The decoration style depends on the style option.
```{.python filename="fibonacci.py"}
def fibonacci(n: int) -> int:
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
```By default, code blocks without an explicit filename automatically show the language name in small-caps styling.
```python
print("Hello, World!")
```Configure the extension in your document's YAML front matter:
extensions:
code-window:
enabled: true
auto-filename: true
style: "macos"
wrapper: "code-window"
hotfix:
quarto-version: ~
code-annotations: true
skylighting: true| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | true |
Enable or disable the code-window filter. |
auto-filename |
boolean | true |
Automatically generate filename labels from the code block language. |
style |
string | "macos" |
Window decoration style: "macos", "windows", or "default". |
wrapper |
string | "code-window" |
Typst wrapper function name for code-window rendering. |
These options are temporary and will be removed in a future version (see Temporary hot-fixes).
| Option | Type | Default | Description |
|---|---|---|---|
hotfix.quarto-version |
string | unset | Quarto version at or above which all hot-fixes are automatically disabled. |
hotfix.code-annotations |
boolean | true |
Enable the code-annotations hot-fix for Typst output. |
hotfix.skylighting |
boolean | true |
Enable the Skylighting hot-fix for Typst output (overrides block styling and inline code). |
"macos"(default): Traffic light buttons (red, yellow, green) on the left, filename on the right."windows": Minimise, maximise, and close buttons on the right, filename on the left."default": Plain filename on the left, no window decorations.
Override the style for a single code block using the code-window-style attribute:
```{.python filename="example.py" code-window-style="windows"}
print("Windows style for this block only")
```The extension includes two temporary hot-fixes for Typst output that compensate for missing Quarto/Pandoc features. Both will be removed once quarto-dev/quarto-cli#14170 is released. After that, the extension will focus solely on auto-filename and code-window-style features.
hotfix.code-annotations: processes code annotation markers for Typst, since Quarto does not yet supportcode-annotationsin Typst output. Thefilenameattribute for code blocks will also become natively supported.hotfix.skylighting: overrides Pandoc's Skylighting output for Typst to fix block and inline code styling.
Set hotfix.quarto-version to automatically disable both hot-fixes once you update Quarto to the version that includes native support:
extensions:
code-window:
hotfix:
quarto-version: "1.10.0"Future removal playbook:
- Delete
hotfixparsing fromcode-window.lua(HOTFIX_DEFAULTS, hotfix section inMeta). - Remove the
hotfixsection from_schema.yml. - Remove the skylighting guard and loader in
main.lua. - Remove annotation processing from
code-window.lua. - Delete
_modules/hotfix/directory entirely.
Here is the source code for a minimal example: example.qmd.
Rendered output: