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 @@ -4,6 +4,7 @@

- 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)
- fix: A code block that gets no title, through `code-window-enabled="false"` or `code-window-no-auto-filename="true"`, now keeps the language class the author wrote. (#99)

## 1.9.1 (2026-11-20)

Expand Down
33 changes: 15 additions & 18 deletions _extensions/code-window/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,29 @@ end
--- "auto-filename" belongs in the same question, because it is the reader
--- itself: with no derived name to build, both window paths return before they
--- read the label, so the pass would rewrite a class for nobody again.
--- Every question this asks is about the render, not about one block. A block
--- can still draw no chrome inside a render that does, through
--- "code-window-no-auto-filename" or "code-window-enabled", and its class is
--- rewritten with no reader either. Answering that per block means relabelling
--- where the name is built, which is a change to the two window paths rather
--- than to this gate.
--- A block can also draw no title inside a render that does, through
--- "code-window-no-auto-filename" or "code-window-enabled". Nothing reads its
--- label either, so it is left alone whatever "auto-filename" says. A block
--- with a filename of its own still gets a title, so it still takes the pass.
--- A block that carries "code-window-auto-label" asks for a window by itself,
--- so it takes the pass whatever "auto-filename" says. Without it, a block in
--- a language Pandoc cannot highlight would get no wrapper to frame. Such a
--- block that also refuses the window has no reader for the label, so it is
--- left alone here.
--- a language Pandoc cannot highlight would get no wrapper to frame.
--- @param block pandoc.CodeBlock
--- @return pandoc.CodeBlock|nil Relabelled block, or nil when the pass is skipped
local function normalise_language(block)
if not code_window.draws_chrome() or code_window.is_quarto_block(block) then
return nil
end
if not code_window.CONFIG().auto_filename then
-- Lowercased to match the schema's boolean coercion. Resolving through the
-- schema check here would report each of its warnings twice per block.
local enabled = (block.attributes['code-window-enabled'] or ''):lower()
local no_auto_filename = (block.attributes['code-window-no-auto-filename'] or ''):lower()
local refuses_window = enabled == 'false' or no_auto_filename == 'true'
if not language.auto_label(block) or refuses_window then
return nil
end
-- Lowercased to match the schema's boolean coercion. Resolving through the
-- schema check here would report each of its warnings twice per block.
local enabled = (block.attributes['code-window-enabled'] or ''):lower()
local no_auto_filename = (block.attributes['code-window-no-auto-filename'] or ''):lower()
local refuses_derived_name = no_auto_filename == 'true' and block.attributes['filename'] == nil
if enabled == 'false' or refuses_derived_name then
return nil
end
if not code_window.CONFIG().auto_filename and not language.auto_label(block) then
return nil
end
return language.CodeBlock(block)
end
Expand Down
25 changes: 25 additions & 0 deletions tests/fixtures/language-refused.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: "A language Pandoc cannot highlight, on blocks with no title"
filters:
- code-window
---

The first two blocks refuse a title, so nothing reads a derived label and each
keeps the class the author wrote. The last two get a title, from the language
or from the filename, and are relabelled.

```{.foo code-window-no-auto-filename="true"}
x = 1
```

```{.foo code-window-enabled="false"}
y = 2
```

```foo
z = 3
```

```{.foo filename="w.foo" code-window-no-auto-filename="true"}
w = 4
```
14 changes: 14 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ else
"a default class before the foo class, a code-window-auto wrapper, and data-filename=\"foo\" on the block"
fi

# A block that refuses a title inside a render that draws chrome has no reader
# for the label either, so it keeps its class. The last two blocks still get a
# title, from the language or from the filename, which shows the gate is per
# block and not for the whole render.
render language-refused html
refused_classes="$(block_classes "${work_dir}/language-refused.html")"
if [ "$(printf '%s\n' "${refused_classes}" | grep -c '^<pre class="foo"$')" -eq 2 ] &&
[ "$(printf '%s\n' "${refused_classes}" | grep -c 'default foo')" -eq 2 ]; then
report pass "language-refused: a block with no title keeps its class"
else
report fail "language-refused: a block with no title keeps its class" \
"two <pre class=\"foo\"> and two default foo, got: ${refused_classes}"
fi

# ============================================================================
# The Typst hot-fix stands down with the filter
# ============================================================================
Expand Down