Possible Duplicate:
Code block is not properly formatted when placed immediately after a list item

I was just submitting a new answer to an old question on Stackoverflow and noticed my code block was not being formatted as code.

It was originally positioned between a bulleted list and some plain text.

I discovered that when I cut and paste it to after the plain text it would be formatted correctly, but pasting it back in its old positions would always be without format. Adding blank lines around it made no difference.

Here's a screenshot of the same code block in both positions showing the first unformatted and the second correctly formatted:
formatting bug screenshot

Let's see what happens here:

var foo = 'bar'; // works
  • random
  • bullet
  • list

    var bar = 'foo'; // doesn't work


To have a code block immediately after a list, you can put a HTML comment between them:

 * item 1
 * item 2

<!-- -->

    code block


  • item 1
  • item 2
code block

Inside list markdown, you need to indent 8-spaces for code sample.

Example markdown:

- List Item

        /** code block */

Markdown output:

  • List Item

    /** code block */
  • This is handy to know, but it actually makes the code block itself part of a list item, which is not what I was trying to achieve. hammar's workaround hits the nail on the head though. – hippietrail Nov 18 '12 at 3:31

Not the answer you're looking for? Browse other questions tagged .