I can’t say that working with code blocks in callouts is a pleasant experience, but your example seems to be working.
There is also the Insert callout command you can use. Write the code block as you’d like, select the entire thing (including the beginning and ending backticks ``` ) , and run Insert callout to wrap the code block in a callout.