diff --git a/CHANGELOG.md b/CHANGELOG.md index 5160a1f..58df2d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/_extensions/code-window/main.lua b/_extensions/code-window/main.lua index 2f28d44..ce3a73b 100644 --- a/_extensions/code-window/main.lua +++ b/_extensions/code-window/main.lua @@ -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 diff --git a/tests/fixtures/language-refused.qmd b/tests/fixtures/language-refused.qmd new file mode 100644 index 0000000..6dcd8ae --- /dev/null +++ b/tests/fixtures/language-refused.qmd @@ -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 +``` diff --git a/tests/run.sh b/tests/run.sh index f8eb138..9cd4e54 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -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 '^
and two default foo, got: ${refused_classes}"
+fi
+
# ============================================================================
# The Typst hot-fix stands down with the filter
# ============================================================================