codly / docs

Make it yours

Applies to code displayed in the documentation.

GitHub

codly.file

Creates the filename badge used beside a code block or in its header or footer.

Signature

typst code
// Create a filename badge
codly.file(
  body: str | content,
  fill: paint | none = luma(240),
  stroke: stroke | none = 0.5pt + luma(160),
  inset: length | dictionary = (x: 0.4em, y: 0.2em),
  radius: length | dictionary = 2pt,
)

// Equivalent set-rule for `codly.file`
codly.file-set_(..args)

// Equivalent show rule for `codly.file`
codly.file-show_(it => ...)

body is required and may be supplied positionally; it is the displayed filename or filename content. The remaining fields are named. codly.new documents how code blocks derive and place this badge.

codly.file-set_(..args) sets badge defaults in scope; codly.file-show_(it => ...) replaces each rendered badge with the callback’s result.

Fields

Field Type Default / required Meaning
body str | content Required, positional Displayed filename.
fill none | paint luma(240) Background paint of the filename badge.
stroke none | stroke 0.5pt + luma(160) Border stroke of the filename badge.
inset length | dictionary (x: 0.4em, y: 0.2em) Padding inside the filename badge.
radius length | dictionary 2pt Corner radius of the filename badge.

Behavior

The badge is a box using fill, stroke, inset, and radius around body. A length applies uniformly; an inset dictionary sets padding by side or axis, and a radius dictionary sets individual corners.

Example

Try the controls
4pt
rgb("#d8eaff")
Typst source
#import "@preview/codly:2.0.0" as codly

#codly.file("src/main.typ", radius: example-radius, fill: fill)
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