Codly is a package that lets you easily create beautiful code blocks for your Typst documents.
It uses the newly added raw.line
function to work across all languages easily. You can customize the icons, colors, and more to
suit your document's theme. By default it has zebra striping, line numbers, for ease of reading.
#let icon(codepoint) = {
box(
height: 0.8em,
baseline: 0.05em,
image(codepoint)
)
h(0.1em)
}
#show: codly-init.with()
#codly(languages: (
rust: (name: "Rust", icon: icon("brand-python.svg"), color: rgb("#CE412B")),
))
```rust
pub fn main() {
println!("Hello, world!");
}
```
Which renders to:
You can find all of the documentation in the example file.
To start using codly, you need to initialize codly using a show rule:
#show: codly-init.with()
Then you need to congigure codly with your parameters:
#codly(
languages: (
rust: (name: "Rust", icon: icon("\u{fa53}"), color: rgb("#CE412B")),
)
)
Then you just need to add a code block and it will be automatically displayed correctly:
```rust
pub fn main() {
println!("Hello, world!");
}
```
To locally disable codly, you can just do the following, you can then later re-enable it using the codly
configuration function.
#disable-codly()
If you wish to add an offset to your code block, but without selecting a subset of lines, you can use the codly-offset
function:
// Sets a 5 line offset
#codly-offset(5)
If you wish to select a subset of lines, you can use the codly-range
function. By setting the start to 1 and the end to none
you can select all lines from the start to the end of the code block.
#codly-range(start: 5, end: 10)
You can configure this with the codly
function:
#codly(
width-numbers: none,
)
You disable zebra striping by setting the zebra-color
to white.
#codly(
zebra-color: white,
)
You can customize the stroke surrounding the figure using the stroke-width
and stroke-color
parameters of the codly
function:
#codly(
stroke-width: 1pt,
stroke-color: red,
)
You can also disable the icon, by setting the display-icon
parameter to false
:
#codly(
display-icon: false,
)
Same with the name, whether the block is breakable, the radius, the padding, and the width of the numbers columns.