From 678f4ce074d305bffe517efb192d28876850decb Mon Sep 17 00:00:00 2001 From: LightQuantum Date: Thu, 25 Jun 2026 17:17:56 -0400 Subject: [PATCH] Fix highlight baseline misalignment on Typst 0.15 --- src/args.json | 2 +- src/lib.typ | 8 +++++++- tests/issues/131-highlight-baseline-typst-015.typ | 13 +++++++++++++ tests/issues/test.typ | 6 +++++- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/issues/131-highlight-baseline-typst-015.typ diff --git a/src/args.json b/src/args.json index 7ed868c..e297aaf 100644 --- a/src/args.json +++ b/src/args.json @@ -365,7 +365,7 @@ }, "highlights": { "title": "Highlights", - "description": "You can apply highlights to the code block using the `highlights` argument. It consists of a list of dictionaries, each with the following keys:\n- `line`: the line number to start highlighting\n- `start`: the character position to start highlighting, zero if omitted or `none`\n- `end`: the character position to end highlighting, the end of the line if omitted or `none`\n- `fill`: the fill of the highlight, defaults to the default color\n- `tag`: an optional tag to be displayed alongside the highlight.\n- `inset`: overrides the global @arg-highlight-inset.\n- `baseline`: overrides the baseline which is set by default to the `bottom` component of @arg-highlight-inset.\n- `clip`: overrides the global @arg-highlight-clip.\n- `outset`: overrides the global @arg-highlight-outset.\n- `radius`: overrides the global @arg-highlight-radius.\n- `label`: *if and only if* the code block is in a `figure`, sets the label by which the highlight can be referenced.\n\nAs with other code block settings, annotations are reset after each code block. #one-indexed #zero-indexed", + "description": "You can apply highlights to the code block using the `highlights` argument. It consists of a list of dictionaries, each with the following keys:\n- `line`: the line number to start highlighting\n- `start`: the character position to start highlighting, zero if omitted or `none`\n- `end`: the character position to end highlighting, the end of the line if omitted or `none`\n- `fill`: the fill of the highlight, defaults to the default color\n- `tag`: an optional tag to be displayed alongside the highlight.\n- `inset`: overrides the global @arg-highlight-inset.\n- `baseline`: overrides the highlight box baseline. By default, Typst 0.15 and newer use `auto`; older Typst versions use the `bottom` component of @arg-highlight-inset.\n- `clip`: overrides the global @arg-highlight-clip.\n- `outset`: overrides the global @arg-highlight-outset.\n- `radius`: overrides the global @arg-highlight-radius.\n- `label`: *if and only if* the code block is in a `figure`, sets the label by which the highlight can be referenced.\n\nAs with other code block settings, annotations are reset after each code block. #one-indexed #zero-indexed", "default": "none", "ty": [ "array", "type(none)" ], "function": true, diff --git a/src/lib.typ b/src/lib.typ index 30f072e..4f3d4fb 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -789,6 +789,12 @@ state("codly-highlight-inset", __codly-args.highlight-inset.default).get() }); + let highlight-baseline = if sys.version >= version(0, 15, 0) { + auto + } else { + __codly-inset(highlight-inset).bottom + } + show raw.line.where(label: ): codly-line.with( (__codly-args.highlight-stroke.type_check)(if "highlight-stroke" in extra { extra.highlight-stroke @@ -806,7 +812,7 @@ state("codly-highlight-radius", __codly-args.highlight-radius.default).get() }), highlight-inset, - __codly-inset(highlight-inset).bottom, + highlight-baseline, (__codly-args.highlight-outset.type_check)(if "highlight-outset" in extra { extra.highlight-outset } else { diff --git a/tests/issues/131-highlight-baseline-typst-015.typ b/tests/issues/131-highlight-baseline-typst-015.typ new file mode 100644 index 0000000..b63f95c --- /dev/null +++ b/tests/issues/131-highlight-baseline-typst-015.typ @@ -0,0 +1,13 @@ +#import "../../codly.typ": * + +#show: codly-init.with() + +#codly(highlights: ( + (line: 3, start: 3, end: 10, fill: orange), +)) +```rust +pub fn main() { + println!("Hello, world!"); + println!("Hello, world!"); +} +``` diff --git a/tests/issues/test.typ b/tests/issues/test.typ index 3104ab9..78faf78 100644 --- a/tests/issues/test.typ +++ b/tests/issues/test.typ @@ -58,4 +58,8 @@ contained within a figure and that figure must have a label.")*/ #codly-reset() #include "89-nested-highlights.typ" -#codly-reset() \ No newline at end of file +#pagebreak() +#codly-reset() + +#include "131-highlight-baseline-typst-015.typ" +#codly-reset()