When you post code, expand the toolbar:
In the expanded toolbar, click more and Syntax highlighter:
Select the language (for instance Python):
Paste you code:
Click OK in the lower part of the screen
And the code will appear with the correct format:
I would also like to point out that you can't edit a code block in place. You have to left click in it to select the block, then repeat the steps above to open the syntax highlighter.
I'd like to also add suggestion of copying your code to something like notepad or notepad++ to deal with spacing/wraparound and then past it back into the codeblock per Dan Patterson suggestion in comments found here.
and to tie in all the links...