5

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

In my answer here, I wrote up a solution with step-by-step instructions. However, my numbered items are being reset to 1. This only happens in Item B and Item C. The first section of my answer doesn't suffer from this problem.

Is this a bug in markdown, or am I doing something wrong?

1

2 Answers 2

7

It's tricky to mix code blocks and numbered lists. You need to indent the code blocks 8 spaces (4 to put them "inside" the numbered list and 4 to make them code blocks):

This markup:

1. foo bar:

        some.code()

2. baz quux

produces this result:

  1. foo bar:

    some.code()
    
  2. baz quux

1
  • "You need to indent the code blocks 8 spaces (4 to put them "inside" the numbered list and 4 to make them code blocks)" Thanks, I never new that, it's something I struggled with on a few answers. +1 Commented Apr 19, 2012 at 7:27
3

I have edited your post you can see what I've done.

In addition to what Joachim said, you also had some fancy space character in some of your lines, for example:

      map.getOverlays().add(overlay);

As you can see although it's indented it's not recognized as code block because those are not ordinary space character (ASCII value 32) but something else. I verified it in this online tool which says those characters are NULL.

Replacing it with ordinary spaces:

               map.getOverlays().add(overlay);

Solved the issue of course. What IDE are you using? Maybe something there went funky.

5
  • Thanks! I'm using Eclipse and instructed it to convert tabs into spaces, but this may not be happening correctly... Commented Apr 19, 2012 at 7:32
  • @Tony any chance you're under Korean, Chinese, or Japanese language settings on your machine? I believe it cause such a "double space" character. Commented Apr 19, 2012 at 7:36
  • No, just a basic US English install. What's a good tool to sanitize whitespace and tabs prior to posting? Commented Apr 19, 2012 at 7:42
  • @Tony that's really weird then. Not aware of any such tool, but if you see your code won't get formatted even with spaces it probably means fake spaces. Commented Apr 19, 2012 at 8:03
  • @Tony: Other users have had the same problem with spaces-that-are-not-spaces when using Chrome. Commented Apr 20, 2012 at 2:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.