Thanks for some great input and explanations! I do understand it a bit more now, and your suggestions are solid. However, I really do want to have it as a function so that I can control the language and the size of the source code (as well as being easier to just copy-and-paste from the editor to typst). I will have a look at codly and others as well, but previously, they have not been able to help me all the way.
But thanks a lot for all the patience and the really good explaining!