I’ve always used the <pre> and <code> tags to show code in WordPress posts. This isn’t very good because the formatting always goes wrong because the lines don’t wrap automatically. Today, I discovered that some other bits of code causes WordPress to close the block and then screw up the display of all subsequent lines.
A bit of Googling led to a solution. Turns out that this is actually a common enough problem to be properly supported in WordPress.com. All you have to do is to use the ‘sourcecode’ shortcode. See the link below for instructions.