I asked a question on StackOverflow recently and had trouble with the MarkDown processor: the code block would not render as code despite being indented four spaces. I've not had this trouble before; maybe the StackOverflow devs have been tinkering and have broken something? It seems to be connected with the fact that the code block is preceded by a list.

In the end, I had to use a <pre> tag, but this doesn't provide colouring, so it's not as nice.

I'd be grateful for feedback from the community, and if that doesn't help, I'd be glad if someone from the SO team could take a look to see what's going wrong.

Many thanks.

  • I know it's not really 'completed', because the problem still exists for other posts. However, the larger issue is tracked in another item (no link handy at the moment) so I'm marking it completed in the sense that your particular post is completed. Sep 29, 2009 at 13:53
  • @Joel: has this been fixed since then? I was having trouble with modifying stackoverflow.com/questions/1985094/… Mar 8, 2011 at 5:57
  • @JoelCoehoorn Can you post the link here? thanks.
    – rwong
    Aug 25, 2012 at 5:29

2 Answers 2


For some reason having the code immediately follow the unordered list was causing a problem. By inserting an innocuous line of text between the end of the list and the code ("Here's the code:"), the code formatting worked as intended.

  • Thanks for diving in and sorting it out for me :) Am I right in thinking that the problem wasn't with my markup but with SO's MarkDown formatter, or is there something special in MarkDown about needing to have non-whitespace text between the end of a list and the start of a code block?
    – user136089
    Sep 29, 2009 at 12:41
  • @sampablokuper: Yes, it wasn't your fault, although I'm not sure whether the problem is with SO's particular MD implementation or with the original MD as they adopted it. Sep 29, 2009 at 12:45
  • 4
    What I do, which is similar, is add a blank line, then a comment like <!-- end the list --> and then another blank line. This tells the MD parser that the list is over and allows me to have a normal code block follow. The formatted output does not show the blank lines, so it's slightly better than forcing yourself to write some text.
    – Sam Stern
    Nov 6, 2013 at 16:19

I had this problem before. See the linked thread for solutions. Basically, you need to indent by eight spaces (four for the list, four for the code), or insert some invisible text, such as a space between backticks.

  • 3
    This is the correct answer. It's not a workaround but the (poorly documented) right way. Apr 23, 2012 at 5:26

You must log in to answer this question.