Code Window
Quarto Extension
Explicit Filename
Code blocks with a filename attribute display a window header with the filename. The decoration style depends on the style option (default: "macos").
fibonacci.py
def fibonacci(n: int) -> int:
"""Calculate the nth Fibonacci number."""
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)analysis.R
# Load data and create summary
data <- read.csv("data.csv")
summary(data)Auto-Generated Filename
With auto-filename: true (the default), code blocks without explicit filenames automatically show the language name in small-caps styling.
python
def greet(name: str) -> str:
"""Return a greeting message."""
return f"Hello, {name}!"r
# Create sample data
data <- data.frame(
x = 1:10,
y = rnorm(10)
)
summary(data)bash
#!/bin/bash
echo "Hello, World!"Plain Code Block
Code blocks without a language are not affected by the extension.
This is a plain code block without any language specified.
No window decoration is applied here.
Disabled Auto-Filename
To disable auto-generated filenames, set auto-filename: false in the extension configuration. Only code blocks with an explicit filename attribute will display window decorations.
Window Styles
Three decoration styles are available via the style option. The global style can be set in the document configuration. Individual blocks can override the style with the code-window-style attribute.
macOS Style (default)
Traffic light buttons on the left, filename on the right.
macos-example.py
print("macOS style window")Windows Style
Minimise, maximise, and close buttons on the right, filename on the left.
windows-example.py
print("Windows style window")Default Style
Plain filename on the left, no window decorations.
default-example.py
print("Default style window")Configuration
Set the global style in the document front matter:
yaml
extensions:
code-window:
style: "macos"Override per block with the code-window-style attribute:
markdown
```{.python filename="example.py" code-window-style="windows"}
print("Windows style for this block only")
```