codly / docs

Make it yours

Applies to code displayed in the documentation.

GitHub

codly.sublang

Assigns a syntax-highlighting language to an inclusive range of source lines in a code block.

Signature

typst code
codly.sublang(
  start: int,
  end: int,
  lang: str,
)

All fields are required and named. The value can also be supplied as a dictionary.

Fields

Field Type Default / required Meaning
start int Required, named First source line of the range, one-based and positive.
end int Required, named Last source line of the range, inclusive and at least start.
lang str Required, named Syntax-highlighting language key.

Behavior

Pass one or more codly.sublang values in the sublangs argument to codly.new. start must be positive and end at least start; invalid ranges raise an error. Lines outside the ranges keep the raw block’s language. Ranges may also be supplied as dictionaries with the same three fields.

Example: Basic Usage

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

#codly.new(
  ```sh
  echo before
  fn answer() {
      42
  }
  echo after

  ```,
  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