Printing code outside of code block

Starting this topic form here again since it is still an issue within this community-forum. (sorry can’t post links here, search for “printing code outside of code block”)

I have exactly the same problem:

But only for some files. If I copy the code from above the codeblock into the codeblock it looks fine, except for some indents.
Any idea, is there a workaround? For now I always have to copy the code myself into the codeblock.