How can i render and execute typst code at the same time?

I have been messing around with the scripting aspec to typst and it is very powerful, I can generate matrices and while its relly useful I want to document this, currently the best workaround to show the code in the rendered output is either to copy paste it into a raw typst block or to do the following

#let code_block= " some code "
#raw(lang: "typst", code_block)
#eval(code_block)

which is annoying since I don’t get any syntax highlighting. when the code is in a string. Is there any better way I could do this?

You can use lang typc for typst in code mode, and it will highlight typst code (not markup) correctly.

found a solution, just do the following

#let code_block = '''typ
code
'''
#code_block
#eval(code_block.text)

just replace the quotes with backticks

Hello. You can look at how self-example – Typst Universe and showman – Typst Universe do this.

The general flow is:

#let code = ```typ
#rect()
```
#code
#eval(code.text, mode: "markup")

But usually with a wrapper function.