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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. (#102)

## 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
}
Expand Down
7 changes: 6 additions & 1 deletion _extensions/code-window/code-window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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() = {
Expand Down Expand Up @@ -623,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(
Expand All @@ -643,7 +646,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)
}
},
)
Expand Down
3 changes: 3 additions & 0 deletions docs/reference.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<wrapper>-annotated-content` helper.
If it does not, the code has no annotation markers, and the annotation list has no links to the code.

Expand Down
11 changes: 11 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down