codly.line-ref
Formats native Typst references to displayed lines in labeled Codly code blocks.
Signature
codly.line-ref(body, block: label, number: int, suffix: none, separator: auto, numbering: auto)
codly.line-ref-set_(..args)
codly.line-ref-show_(it, ..args)
codly.line-ref is a generated element definition; Codly creates it for line targets, so user code normally refers to those targets with @block:line rather than constructing the element. line-ref-set_(...) applies field defaults to generated line references in the current scope. line-ref-show_(it) installs a show rule; its first argument is the replacement callback or content, not field overrides.
Fields
| Field | Type | Default / required | Meaning |
|---|---|---|---|
body |
none | content |
Required, positional | Internal reference body. |
block |
label |
Required, named | Label of the containing code block or figure. |
number |
int |
Required, named | Displayed line number after offsets and skips. |
suffix |
none | content |
none |
Suffix identifying an unnumbered line relative to the preceding displayed number. |
separator |
none | auto | str | content |
auto |
Separator after the block reference; auto inherits codly.ref.sep. |
numbering |
none | auto | function |
auto |
Line-number formatter; auto inherits codly.ref.numbering, and none hides the line number. |
Behavior
The constructor is exported, but references are normally generated from native @block:line syntax; the element has no custom casts and cannot itself carry a label. The reference shows the block figure followed by the formatted line number — the displayed number, not a source position.
separator: auto and numbering: auto inherit codly.ref’s sep and numbering settings. Explicit fields set through line-ref-set_ override those shared defaults for line references in scope. A numbering function receives the displayed line number. line-ref-show_ lets a show rule replace or wrap the generated reference; its callback receives the element.
See codly.ref for shared reference defaults.
Example
Labels a code block and refers to its second displayed line; the local set rule changes the separator and number format:
#import "@preview/codly:2.0.0" as codly
#show: codly.line-ref-set_(separator: " line ", numbering: n => [L#n])
#figure(caption: [A small code block])[
#codly.new(
```
first line
second line
```,
)
]<example>
The reference points to line two of the block: @example:2.
Edit & run on your device
The highlighted source and output update after you stop typing. Copy code includes your edits.