codly / docs

Make it yours

Applies to code displayed in the documentation.

GitHub

codly.gutter-column

Defines one independently styled column beside a code block. Use it in gutters to show source-line labels, markers, or other row-specific content.

Signature

typst code
codly.gutter-column(
  values: array<none | str | int | float | content> | function,
  width: auto | length | ratio | fraction = auto,
  align: auto | alignment = auto,
  inset: auto | length | dictionary = auto,
  stroke: auto | stroke | dictionary | none = auto,
  fill: auto | paint | array<paint | none> | function | none = auto,
  text: dictionary = (:),
)

values is required and named. Arrays and functions can also be passed directly as gutter column specifications; dictionaries are cast to this type.

Parameters

Field Type Default / required Meaning
values array<none | str | int | float | content> | function Required, named Source-line values or a callback receiving index, kind, source-line, number, and text. Short arrays and none entries leave cells empty; generated rows have no source text.
width auto | length | ratio | fraction auto Nonnegative column width; auto sizes to its content.
align auto | alignment auto Cell alignment; auto inherits the grid number alignment.
inset auto | length | dictionary auto Cell padding; auto inherits the grid number inset.
stroke none | auto | stroke | dictionary auto Cell border; auto inherits the grid stroke, and none disables it.
fill none | auto | paint | array<none | paint> | function auto Cell background, nonempty cycling palette, or row callback. auto follows the body-row fill; none leaves the cell unfilled.
text dictionary (:) Text settings applied to the column content.

Behavior

A callback receives the rendered row dictionary with index, kind, source-line, number, and text. index counts displayed rows, including headers and callouts; source-line is one-based for source rows and none for generated rows. Callbacks may return content, strings, numbers, or none.

Values are validated when resolved, and width must be non-negative. auto alignment and insets inherit the number column’s settings; fill: auto follows the body row. A fill callback also receives the row dictionary, with text populated from the source line where available.

Example: Basic Usage

Typst source
#import "@preview/codly:2.0.0" as codly

#codly.new(
  ```
  let answer = 42
  print(answer)
  ```,
  gutters: (
    codly.gutter-column(
      values: row => if row.kind == "code" {
        str(row.source-line) + ". " + row.text
      } else { none },
      align: right,
      inset: (left: 4pt, right: 8pt),
      fill: gray.lighten(90%),
    ),
  ),
)
Edit & run on your device

The highlighted source and output update after you stop typing. Copy code includes your edits.

OUTPUTPre-rendered default
Rendered output of the Typst example