codly / docs

Make it yours

Applies to code displayed in the documentation.

GitHub

codly.sublang-block

The generated element that holds one syntax-highlighted language range inside a Codly code block.

Signature

typst code
codly.sublang-block(body, idx)

Codly creates this element while rendering codly.new. In normal use, configure language ranges with the block’s sublangs field and codly.sublang, rather than constructing this element directly. Both required fields are positional in the generated element constructor.

Fields

Field Type Default / required Meaning
body content Required, positional Raw block used to resolve syntax styling for the sublanguage range.
idx int Required, positional Zero-based index of the sublanguage configuration within the block.

Behavior

For each configured sublanguage range, Codly creates a raw block with that range’s language and stores it in body. Its display keeps the syntax highlighting while attaching per-line metadata so the block renderer can reuse it.

Example

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

#codly.new(
  ```sh
  > cat test.rs
  fn main() {
      println!("hello");
  }
  > exit

  ```,
  sublangs: ((start: 2, end: 4, lang: "rs"),),
)
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