From ff2e427aa5a22686899b9fca0a7662064caebc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:15:01 +0100 Subject: [PATCH 1/3] fix: drop the code block frame inside a Typst window The Skylighting override passed a 0.5pt stroke and a 2pt radius as explicit arguments, which beat the set rules of the window body. With a theme stroke on some sides only, the frame showed around the code. --- CHANGELOG.md | 2 ++ .../_modules/hotfix/skylighting-typst-fix.lua | 5 +++-- _extensions/code-window/code-window.lua | 4 ++++ docs/reference.qmd | 3 +++ tests/run.sh | 11 +++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64859f8..66ff9db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- fix: A highlighted code block in a Typst window no longer draws its own thin border and round corners, so the window's stroke and the title bar rule are the only edges. + ## 1.10.0 (2026-11-23) - 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) diff --git a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua index 1ea4fd3..4a02448 100644 --- a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua +++ b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua @@ -47,6 +47,7 @@ local function build_skylighting_override() let _page-bg = _cw-page-bg() let _fg = _cw-fg(_page-bg) let _border-colour = color.mix((_fg, 15%%), (_page-bg, 85%%)) + let in-window = _cw-in-window.get() let annot-data = _cw-annotations.get() let blocks = [] let lnum = start - 1 @@ -97,8 +98,8 @@ local function build_skylighting_override() fill: bgcolor, width: 100%%, inset: _cw-body-inset.get(), - radius: 2pt, - stroke: 0.5pt + _border-colour, + radius: if in-window { 0pt } else { 2pt }, + stroke: if in-window { none } else { 0.5pt + _border-colour }, blocks, ) } diff --git a/_extensions/code-window/code-window.lua b/_extensions/code-window/code-window.lua index 0106399..1fc326a 100644 --- a/_extensions/code-window/code-window.lua +++ b/_extensions/code-window/code-window.lua @@ -389,6 +389,8 @@ local TYPST_COLOUR_HELPERS = [==[ ) // the inset of a code block: the theme's body-inset inside a window #let _cw-body-inset = state("cw-body-inset", _cw-theme-defaults.body-inset) +// whether a code block sits in a window, where the window draws the only edges +#let _cw-in-window = state("cw-in-window", false) // code-window: adaptive colour helpers (derive UI tones from page background) #let _cw-page-bg() = { @@ -643,7 +645,9 @@ local function build_typst_function_def(has_hotfixes, has_own_wrapper) below: 0pt, ) _cw-body-inset.update(theme.body-inset) + _cw-in-window.update(true) %s _cw-body-inset.update(_cw-theme-defaults.body-inset) + _cw-in-window.update(false) } }, ) diff --git a/docs/reference.qmd b/docs/reference.qmd index 98715fd..46e219a 100644 --- a/docs/reference.qmd +++ b/docs/reference.qmd @@ -110,6 +110,9 @@ The function receives the code as its first argument, and these named arguments: A call gives only the arguments that apply to its block, so give each named argument a default, or collect them with `..args`. With the Skylighting hot-fix, the code block in the window takes its inset from `state("cw-body-inset")`, which is 8pt by default. If the function adds its own padding, it can set this state before the code and reset it to 8pt after the code. +Outside a window, the code block has a thin border and round corners. +If the function draws its own border, it can set `state("cw-in-window")` to `true` before the code and to `false` after the code. +Then the code block has no border and square corners. To show code annotations, the function must give the code to the `-annotated-content` helper. If it does not, the code has no annotation markers, and the annotation list has no links to the code. diff --git a/tests/run.sh b/tests/run.sh index 95886e0..0866166 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -547,6 +547,17 @@ else "one blue side, one red side, and no red frame, got ${blue_sides}, ${red_sides}, and ${red_frames}" fi +# The highlighted block draws its own thin frame in the mixed border colour, +# which Typst writes as an oklab stroke. In the window the theme's stroke is the +# only edge, so only the block outside the window keeps that frame. +block_frames="$(count_in "${fill_stroke_svg}" 'stroke="oklab(')" +if [ "${block_frames}" -eq 1 ]; then + report pass "typst-theme-fill-stroke: the code in the window has no frame of its own" +else + report fail "typst-theme-fill-stroke: the code in the window has no frame of its own" \ + "one oklab stroke in typst-theme-fill-stroke.svg, got ${block_frames}" +fi + # With fill left at auto, both code blocks keep the highlight style's # background. With fill set to none, neither block has one. The background is # read from the override's fallback, so the test follows the highlight style. From 38c8ee0ccbcaf458d929bf37accdaaf8d56599cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:21:21 +0100 Subject: [PATCH 2/3] docs: note the window state in the body comment --- _extensions/code-window/code-window.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_extensions/code-window/code-window.lua b/_extensions/code-window/code-window.lua index 1fc326a..04ac41e 100644 --- a/_extensions/code-window/code-window.lua +++ b/_extensions/code-window/code-window.lua @@ -625,7 +625,8 @@ local function build_typst_function_def(has_hotfixes, has_own_wrapper) title-bar, ) // Strip code block chrome so content fills flush against the window body. - // set block() provides defaults for Skylighting blocks (explicit fill preserved). + // set block() provides defaults for Skylighting blocks (explicit fill preserved); + // the Skylighting override reads cw-in-window to drop its own stroke and radius. // show raw overrides the document-level raw block styling (fill, radius). { set block( From f9661e99860aaac915c0c2fc31deec95fb054a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:23:19 +0100 Subject: [PATCH 3/3] docs: add the pull request to the changelog entry [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ff9db..89e5d84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- fix: A highlighted code block in a Typst window no longer draws its own thin border and round corners, so the window's stroke and the title bar rule are the only edges. +- fix: A highlighted code block in a Typst window no longer draws its own thin border and round corners, so the window's stroke and the title bar rule are the only edges. (#102) ## 1.10.0 (2026-11-23)