codly / docs

Make it yours

Applies to code displayed in the documentation.

GitHub

codly.line

A generated row component that styles one displayed line in a Codly code block. Codly creates these rows while rendering codly.new; use the set/show wrappers here to configure their style.

Signature

typst code
codly.line(body, ..fields)

body is required and positional. All other fields are named and optional.

Fields

Field Type Default / required Meaning
body none | content Required, positional The raw.line content to render; generated row content is passed through unchanged.
radius none | length 0.32em Corner radius used for the containing code grid.
inset none | length | dictionary 0.32em Padding around each code row, as a length or a Typst inset dictionary.
fill none | auto | paint | array<none | paint> | function (luma(240), none) Body-row paint, nonempty cycling palette, or row callback. The callback receives index, kind, source-line, and number; index is zero-based and includes header rows. auto restores the default palette, and whole-row highlights override this fill.
stroke none | stroke 1pt + luma(240) Border stroke of the containing code grid.
highlights none | array<highlight-config> none Character highlight configurations for displayed line numbers. Character bounds are one-based and inclusive.
smart-indent bool true Whether wrapped continuations retain indentation from the normalized source text.
block-label none | label none Label of the containing block used to generate line and highlight references.
reference none | dictionary none Internal displayed-number and suffix metadata for an unnumbered source line.

Behavior

The fill callback receives a dictionary with index, kind, source-line, and number. index is zero-based in displayed-row order, including header, footer, skip, and callout rows — header and footer rows count toward it but do not invoke the callback. kind is "code", "skip", or "callout" for callback rows. source-line is the one-based source line for code and callout rows, and none for generated skip rows. number is the displayed line number, or none for unnumbered and generated rows.

codly.line-set_(..args) sets row fields with show:; codly.line-show_(it => ...) replaces or wraps each generated row, receiving the row element as it.

Example

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

#show: codly.line-set_(fill: row => {
  if row.kind == "callout" { purple.lighten(80%) }
  else if row.kind == "code" { rgb(255, row-green, 190) }
  else { luma(238) }
})

#codly.new(
  ```py
  let answer = 42
  print(answer)
  ```,
  callouts: ((line: 1, body: [The value is set here.]),),
)
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