Shaxx, there isn't any general way to do this. You can look at List of forum editor issues and bugs to see which bugs are already known and how to workaround them.
I personally don't use code highlighting at the moment. If I add code I use the quote insert and try to use courier new as font. This works most of the time.
In addition to the prevous response, there seems to be no universal or easy solution until the forum editor is fixed.
At the minimum you will probably want to replace all newlines of your code with Shift-Return to address the double-line spacing (paragraph) problem when copying code from the forum. You can also use multiple Shift-Return's to enter empty lines. Using a fixed width font is a good idea. The success to change the font of multiple lines at once varies.
Perhaps the easiest way right now is the following:
Copy and past your code into the editor window.
Verify the content. When finally posting, some content may change (1).
Select the code and change the font to “New Courier” (2).
Replace all line-endings (Return) with Shift-Return.
Select the code and choose Quote from the >> menu.
(1)(2) There may have been some progress recently.