Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- feat: Add the `fill` and `stroke` keys to the Typst theme, so a template can set the code background and draw the window border on some sides only. (#97)
- fix: A code block or an executed cell with an empty `filename` now gets one window with an empty title in HTML and Typst, rather than the language label or a second window. (#98)

## 1.9.1 (2026-11-20)

Expand Down
8 changes: 5 additions & 3 deletions _extensions/code-window/code-window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,9 @@ local function resolve_window_params(block, resolved, auto_label)
local filename = block.attributes['filename']
local is_auto = false

if (not filename or filename == '') and not overrides.no_auto_filename then
-- An empty filename is a filename, as on the HTML path: the window keeps
-- an empty title rather than taking a derived label.
if filename == nil and not overrides.no_auto_filename then
-- A label asks for a window whatever auto-filename says.
if auto_label then
filename = auto_label
Expand Down Expand Up @@ -1118,7 +1120,7 @@ local function process_typst_block(block, next_block)

local filename, is_auto, block_style, lines_label =
resolve_window_params(block, resolved, auto_label)
local has_window = filename and filename ~= ''
local has_window = filename ~= nil
local effective_style = block_style or CONFIG.style

-- Resolve annotations if enabled and the code-annotations hot-fix is active.
Expand Down Expand Up @@ -1213,7 +1215,7 @@ local function get_decorated_codeblock_filename(div)
if not custom_id then return nil end
if not (_quarto and _quarto.ast and _quarto.ast.custom_node_data) then return nil end
local entry = _quarto.ast.custom_node_data[custom_id]
if type(entry) == 'table' and entry.filename and entry.filename ~= '' then
if type(entry) == 'table' and type(entry.filename) == 'string' then
return entry.filename
end
return nil
Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/empty-filename-cell.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: "An empty filename on an executed cell"
filters:
- code-window
format:
html: default
typst:
keep-typ: true
---

Quarto keeps the filename of an executed cell in its own registry, not on the
code block, so the filter reads it there. An empty filename read there is
still a filename, and the window keeps an empty title.

```{r}
#| filename: ""
a <- 1
```
4 changes: 4 additions & 0 deletions tests/fixtures/empty-filename.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
title: "An empty filename"
filters:
- code-window
format:
html: default
typst:
keep-typ: true
---

Quarto builds a window for a block whose filename is empty, so the filter must
Expand Down
34 changes: 32 additions & 2 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ set -euo pipefail
# fixtures rather than linked. docs/_scripts/sync-extension.sh solves the same
# problem for the documentation site.
#
# Requires: quarto, and pdftotext from poppler for the page-break and theme
# inset tests.
# Requires: quarto, R with knitr for the executed-cell test, and pdftotext
# from poppler for the page-break and theme inset tests.
#
# Usage: tests/run.sh

Expand Down Expand Up @@ -802,6 +802,36 @@ else
"two code-with-filename wrappers, got ${empty_windows}"
fi

# Typst gives an empty filename the same meaning: the window draws its title
# bar with no label, and takes no language label in its place.
render empty-filename typst
if grep -q '^#code-window(filename: "", is-auto: false' "${work_dir}/empty-filename.typ"; then
report pass "empty-filename: Typst draws a window with an empty title"
else
report fail "empty-filename: Typst draws a window with an empty title" \
'a #code-window(filename: "", is-auto: false call in empty-filename.typ'
fi

# An executed cell carries its filename in Quarto's registry. An empty one is
# read as a filename there too, so HTML keeps the single window Quarto builds
# and Typst draws a window with an empty title. Needs R and knitr.
if command -v Rscript >/dev/null 2>&1; then
render empty-filename-cell html
cell_windows="$({ grep -o '<div class="code-with-filename[" ]' "${work_dir}/empty-filename-cell.html" || true; } | wc -l | tr -d ' ')"
render empty-filename-cell typst
if [ "${cell_windows}" -eq 1 ] &&
[ "$(count_typst_windows "${work_dir}/empty-filename-cell.typ")" -eq 1 ] &&
grep -q '^#code-window(filename: "", is-auto: false' "${work_dir}/empty-filename-cell.typ"; then
report pass "empty-filename-cell: a cell with an empty filename gets one window with an empty title"
else
report fail "empty-filename-cell: a cell with an empty filename gets one window with an empty title" \
"one code-with-filename wrapper in HTML, got ${cell_windows}, and one #code-window(filename: \"\", is-auto: false call in Typst"
fi
else
report fail "empty-filename-cell: a cell with an empty filename gets one window with an empty title" \
"Rscript on PATH, with knitr installed"
fi

render auto-bar-render-time html
check_auto_bar "${work_dir}/auto-bar-render-time.html" html
render auto-bar-render-time revealjs
Expand Down