#Code block line nos and label

1 messages · Page 1 of 1 (latest)

distant oriole
#

While trying to play around with Typst I've noticed that when you use code blocks for displaying code listings, they appear without any line numbers and labels.

I wonder if it's possible to add line numbers to the code block, preferably starting arbitrarily (not necessarily from 1). Also I wonder if it's possible to add a label similarly to how Figure works, so that I would be able to reference the code listing from elsewhere

spiral crystal
#

There currently is a nice formatting code line number snippet shared in showcase, i.e. this is what I use

#show raw.where(block: true): it => { set par(justify: false); grid(
  columns: (100%, 100%),
  column-gutter: -100%,
  block(width: 100%, inset: 1em, for (i, line) in it.text.split("\n").enumerate() {
    box(width: 0pt, align(right, str(i + 1) + h(2em)))
    hide(line)
    linebreak()
  }),
  block(radius: 1em, fill: luma(246), width: 100%, inset: 1em, it),
)}

#show raw.where(block:true): block.with(
    width: 100%,
)