# Is there a problem with code formatting?

This answer appears not to be formatting correctly. (Its current version is correctly formatted in a different approach.) Could someone have a look and tell me what I've done wrong?

I've tagged this as a bug, though I appreciate the bug may be in my head.

• I edited the link to point to the version that was current when you asked the question (and added an explanatory sentence) because the current version doesn't show the problem anymore. – doncherry Jun 7 '12 at 11:35

After I removed and added the four spaces at the begin of every line it got formatted correctly. Maybe there were some Unicode spaces or line breaks included which confused the system.

Note that code blocks which are part of a list element you need to be indented with 8 spaces, not just with 4.

If the code block directly follows a list, but should not be part of it, then you need to add some non-indented line between them. The simplest thing is an HTML comment <!-- --> which is not shown in the formatted output.

• Thanks, Martin. I'm wondering if leading tabs plated a part... – Brent.Longborough Jun 7 '12 at 11:49

Markdown can be "too aware" sometimes. When you typed 1., the parser automatically treated the current line as a list. If there's a list going on the line above, a new line starting with at least one space will make it part of that list:

1. This is a list.

I'm not part of the list.

1. This is another list.

Now I'm part of the list.


which will render as:

1. This is a list.

I'm not part of the list.

1. This is another list.

Now I'm part of the list.

A workaround to insert code after a list is (based on Stefan's answer to Why do code snippets not work after lists?) to add an HTML comment right after the list:

1. This is a list.

I'm part of the list.

\begin{env} < This code syntax wont work.

2. I'm another list.

<!-- Hidden message here! -->

\begin{env}
Hello
\end{env}


1. This is a list.

I'm part of the list.

\begin{env} < This code syntax wont work.

2. I'm another list.

\begin{env}
Hello
\end{env}


In order to insert a code block in a list, we need to add eight spaces instead of the usual four:

1. I'm a list.

\begin{env}
Hello
\end{env}


which will be rendered as:

1. I'm a list.

\begin{env}
Hello
\end{env}


In meta.SO, there's a thread about it: Code block is not properly formatted when placed immediately after a list item. The syntax is quite annoying, but it seems it's unfixable. :(