From a8e6c25ee6ce1cfdc17d7aad8adc37b586899450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:02:52 +0100 Subject: [PATCH 1/4] fix: keep an empty filename empty in Typst Typst took an empty filename for a missing one and drew the language label, while HTML keeps the empty title of the window Quarto builds. Both now draw a window with an empty title. --- CHANGELOG.md | 1 + _extensions/code-window/code-window.lua | 6 ++++-- tests/fixtures/empty-filename.qmd | 4 ++++ tests/run.sh | 10 ++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d28ea9..7fba8aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 with an empty `filename` now gets a window with an empty title in Typst, as in HTML, rather than the language label. ## 1.9.1 (2026-11-20) diff --git a/_extensions/code-window/code-window.lua b/_extensions/code-window/code-window.lua index 466d249..d3fcc3c 100644 --- a/_extensions/code-window/code-window.lua +++ b/_extensions/code-window/code-window.lua @@ -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 @@ -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. diff --git a/tests/fixtures/empty-filename.qmd b/tests/fixtures/empty-filename.qmd index 8c83d53..f238b41 100644 --- a/tests/fixtures/empty-filename.qmd +++ b/tests/fixtures/empty-filename.qmd @@ -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 diff --git a/tests/run.sh b/tests/run.sh index 9025dc7..a5cf1fa 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -802,6 +802,16 @@ 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 + render auto-bar-render-time html check_auto_bar "${work_dir}/auto-bar-render-time.html" html render auto-bar-render-time revealjs From a01d9125217429eb686e1181d298d47a1fbc4e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:12:45 +0100 Subject: [PATCH 2/4] fix: read an empty cell filename as a filename Quarto keeps the filename of an executed cell in its registry, and the filter dropped an empty one there. Typst then drew the language label, and HTML nested an auto window inside the window Quarto builds. --- CHANGELOG.md | 2 +- _extensions/code-window/code-window.lua | 2 +- tests/fixtures/empty-filename-cell.qmd | 18 ++++++++++++++++++ tests/run.sh | 18 ++++++++++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/empty-filename-cell.qmd diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fba8aa..5160a1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +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 with an empty `filename` now gets a window with an empty title in Typst, as in HTML, rather than the language label. +- 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) diff --git a/_extensions/code-window/code-window.lua b/_extensions/code-window/code-window.lua index d3fcc3c..4b9eefc 100644 --- a/_extensions/code-window/code-window.lua +++ b/_extensions/code-window/code-window.lua @@ -1215,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 diff --git a/tests/fixtures/empty-filename-cell.qmd b/tests/fixtures/empty-filename-cell.qmd new file mode 100644 index 0000000..49e59b4 --- /dev/null +++ b/tests/fixtures/empty-filename-cell.qmd @@ -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 +``` diff --git a/tests/run.sh b/tests/run.sh index a5cf1fa..1962c31 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -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 @@ -812,6 +812,20 @@ else '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. +render empty-filename-cell html +cell_windows="$(grep -o '
Date: Sun, 22 Nov 2026 23:19:38 +0100 Subject: [PATCH 3/4] test: report the executed-cell test without stopping the run --- tests/run.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/run.sh b/tests/run.sh index 1962c31..f51658a 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -815,15 +815,20 @@ 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. -render empty-filename-cell html -cell_windows="$(grep -o '
/dev/null 2>&1; then + render empty-filename-cell html + cell_windows="$({ grep -o '
Date: Sun, 22 Nov 2026 23:24:53 +0100 Subject: [PATCH 4/4] test: count the Typst windows of the executed cell --- tests/run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/run.sh b/tests/run.sh index f51658a..f8eb138 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -820,11 +820,12 @@ if command -v Rscript >/dev/null 2>&1; then cell_windows="$({ grep -o '