Hi! I just updated my package crudo, which can make it easier to work with raw blocks. If you ever needed to append or prepend some code to an existing raw block, you probably wished it was as simple as joining to arrays:
let a = (1, 2)
let b = (3, 4)
a + b // (1, 2, 3, 4)
however…
let a = ```typ
// first snippet
```
let b = ```typ
// second snippet
```
a + b // still two separate raw blocks!
// this is one block with both snippets:
raw(
a.text + "\n" + b.text,
block: a.block,
lang: a.lang,
)
Crudo provides a few convenient functions to make working with raw
elements more convenient. You can think of crudo as treating raw blocks as arrays of lines, while preserving the extra fields that raw blocks have. For example:
import "@preview/crudo:0.1.1"
// define a and b like before
crudo.join(a, b) // the block and lang properties of `a` are preserved!
Other useful functions include map()
let a = ```typ
// first snippet
```
crudo.map(a, line => line.replace("first", "only"))
and lines()
:
let example = ```typ
// the beginning is not important,
// only at line 3 does it get interesting:
Hello
World!
```
crudo.lines(example, "3-")
There are also a few more: filter()
, slice()
, transform()
; have a look at the docs here: https://raw.githubusercontent.com/typst/packages/main/packages/preview/crudo/0.1.1/docs/manual.pdf