diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d28ea9..5160a1f 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 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 466d249..4b9eefc 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. @@ -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 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/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..f8eb138 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 @@ -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 '