codly / docs

Make it yours

Applies to code displayed in the documentation.

GitHub

codly.number

A displayed line number in a Codly code block; number-set_ configures its style and number-show_ replaces its rendered content.

Signature

typst code
codly.number(number, parent, ..fields)

number and parent are required positional fields; the remaining fields are named. Codly normally creates these elements while rendering codly.new.

Fields

Field Type Default / required Meaning
number none | content | int | array<int> Required, positional Displayed line number, number tuple, or replacement content; none leaves the cell empty.
parent any Required, positional Containing raw-block value supplied by the code renderer.
numbering str | function numbering.with("1") Numbering pattern or formatter applied to numeric values.
align none | alignment left + horizon Alignment of the automatic number column.
placement none | "inside" | "outside" "inside" Whether gutter columns appear inside or outside the code block border.
fill none | auto | paint auto Number-column background; auto follows each body row's resolved fill.

Behavior

An integer is formatted with numbering; an array passes its values to the numbering function as separate arguments. A content value renders as-is, and number: none displays nothing. number-set_(..fields) sets scoped fields with #show:; number-show_(it => ...) replaces the generated number element with the callback’s result.

The placement setting applies to the number column for code blocks in scope. Outside placement also positions any configured gutters outside the code.

Example

Try the controls
false
Typst source
#import "@preview/codly:2.0.0" as codly

#show: codly.number-set_(placement: if number-outside { "outside" } else { "inside" })

#codly.new(
  ```txt
  first line
  second line
  ```,
)
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.

OUTPUTPre-rendered default
Rendered output of the Typst example