I can't get it to look right!
See my question.
I was using a numbered list. I removed the list to fix the code.
More info and other fixes: Why is a code block not properly formatted when placed immediately after a list item?
You need to indent everything in the code block by four spaces.
You're getting the code blocks that you are because the start and end lines are not indented by four spaces. So add four spaces to the start of every line and it should work.