codly.annotation
codly.annotation is the generated brace element displayed beside an annotated source-line range in a Codly code block.
Signature
// Create a new annotation.
codly.annotation(body, ..fields)
// Equivalent set-rule for an annotation.
codly.annotation-set_(..args)
// Override the show-rule for an annotation.
codly.annotation-show_(it, ..args)
Codly creates this element while rendering codly.new and supplies its fields. body is the required positional content field; the remaining fields are named.
Fields
| Field | Type | Default / required | Meaning |
|---|---|---|---|
body |
none | content |
Required, positional | Annotation content displayed after its number. |
label |
none | content |
Required, positional | Internal reference marker content appended to the annotation; this field is not a Typst label. |
height |
none | length |
0.0pt |
Resolved height of the spanned annotation cell, used to size the brace. |
num |
none | int |
0 |
Automatic annotation number within the block. |
numbering |
none | function |
numbering.with("(1)") |
Annotation number formatter; none hides the number. |
Behavior
Codly emits one annotation element for a configured line range. Range endpoints are one-indexed source-line positions, independent of displayed line-number offsets; annotation ranges cannot overlap. Use codly.annotation-config to configure a range.
codly.annotation-set_(..args) sets fields on generated annotations in scope; codly.annotation-show_(it, ..args) installs replacement content or a callback receiving the generated element.
Example: Basic Usage
#import "@preview/codly:2.0.0" as codly
#codly.new(
```py
prepare()
result = compute()
print(result)
cleanup()
```,
annotations: ((
start: 2,
end: 4,
content: [Computes and displays\ the result],
numbering: if show-annotation-number { n => [(#n)] } else { none },
),),
)
Edit & run on your device
The controls supply the example variables. Their definitions are hidden here; Copy code includes the current values and your edits.