How can I use codly only for specific code blocks?

I’d like to use codly only for longer snippets of code and leave shorter blocks in the normal Typst style. What’s the recommended way to do that?

You can enable and disable codly as described here: GitHub - Dherse/codly: A Typst package for even better code blocks

if you have a specific number of lines, then I would create a show rule for that. It would look roughly like this:

#show raw: it => {
  if it.text.split("\n").len() <= 3 {
    no-codly(it)
  } else {
    it
  }
}
1 Like

I’ve seen this, but I find it kind of cumbersome to enable and disable after the code blocks.

I have opened a Issue on their repo to enable codly only in specific blocks.

You don’t have to do that manually with the show rule proposed by @SillyFreak

But if you want the opposite of no-codly, is it not just the following?

#import "@preview/codly:1.2.0": *

#let with-codly(it) = {
  show: codly-init
  it
}

```rust
pub fn main() {
    println!("Hello, world!");
}
```

#with-codly[
  ```rust
  pub fn main() {
      println!("Hello, world!");
  }
  ```
]

```rust
pub fn main() {
    println!("Hello, world!");
}
```

Going even further, it looks to me like with-codly is pretty much the same as just codly-init here:

#import "@preview/codly:1.2.0": *

```rust
pub fn main() {
    println!("Hello, world!");
}
```

#codly-init[
  ```rust
  pub fn main() {
      println!("Hello, world!");
  }
  ```
]

```rust
pub fn main() {
    println!("Hello, world!");
}
```
2 Likes