– in other words, more text is a regular second paragraph within the list item.

It's indistinguishable which of the two meanings is the intended one; both are correct. And what the Markdown converter (actually, all of them) chooses is the second meaning.

The only way to fix this would be adding an additional syntax to Markdown, enabling you to distinguish the two. I can, however, not think of any intutitive and unobtrusive thing to do, so using one of the workarounds here is as good as anything. My preferred workaround, by the way, would be an HTML comment like this:

* list item
<!-- -->
code

turns into this:

list item

code

– but it doesn't really matter which one you use. Bottom line is: As sad as it is, this is unfixable.

I've been throwing in &nbsp; inbetween when this became an issue. I'll be doing this from now on.
–
Jeff MercadoJul 24 '11 at 10:26

2

I guess Markdown converters choosing the second meaning is the best of the two, as then one could still use the above-mentioned workarounds to force it to not do that. If a converter would NOT add it to the list item itself, there would be no way to force it to do so? (Even two spaces at the end of the first line would not help, as then the next lines would not be formatted as code.)
–
ArjanJul 24 '11 at 14:08

This don't work when I put two ordered list items and code for them, even if you put number 1. to first and 2. to second, you got two items 1.
–
jcubicDec 4 '13 at 7:18

3

@jcubic In that case (which is the usual case), you want the code to appear inside the list, not after it. That's absolutely possible by indenting the code eight spaces (four for the list and four to make it code). This question is only about the rare case that you want code to appear immediately below the list, but outside it.
–
balpha♦Dec 4 '13 at 7:22

Maybe subjective, but: placing code snippet right after list seems as a sub-optimal writing practice (well, a "subset" of bad practice of using too much naked bullet point lists); It will almost always break the narrative of the text. Everytime I ever hit this, I eventually realized that best thing is adding "For example" or something anyway. So in fact, I never cared about the problem: it only reminded me of bad writing.
–
Alois MahdalMar 30 at 16:25

IOW, I have always accepted this as a hidden message that bullet point list and code snippet do not belong next to each other (they may belong inside each other though).
–
Alois MahdalMar 30 at 16:28

Aha. So then Markdown treats the code as part of the list item. A slight semantic difference. Also, I suppose then that the functionality of ctrl-k should be upgraded such that it cycles between 0, 4 and 8 spaces (instead of only 0 and 4). Maybe also 12 spaces, for nested lists. Perhaps that could be a separate feature request?
–
Stephan202Jul 7 '09 at 19:08

1

This seems to be true even if you don't intend for the code to be part of a bullet. I was trying to post a question with 2 bulleted questions followed by the code.
–
IAbstractFeb 14 '10 at 5:00

@IAbstract Seems I beat you to that idea, even though 4 years later. :) meta.stackoverflow.com/questions/278228/… Fought with the same problem, but with balpha's fantastic workaround things worked out right. However, I left the "wrong" code in so people can see the difference.
–
syntaxerrorDec 2 '14 at 1:30

@IAbstract Amen to that! :) But there is always one thing I will never understand: why do some people always have the urge to downvote a duplicate answer in meta? See, there are zillions of metas. And once someone posts the same question in SO meta, I will not necessarily see it because I'm much more active in *.SE.com metas.
–
syntaxerrorDec 2 '14 at 13:34

@syntaxerror: I don't worry about them on meta sites (btw, I didn't down-vote it :) ).
–
IAbstractDec 2 '14 at 13:37

This is only appropriate if the code block doesn't have anything to do with the list item.
–
Brad GilbertJul 21 '09 at 16:21

+1 I was getting ready to ask a question about formatting R code when I saw this. The 8 spaces hack did it.
–
DaveParilloNov 6 '09 at 5:21

2

@Brad Gilbert - this is a common scenario if you want to have a list of points followed immediately by a code sample that is related to the answer in general and not to the final list item. (i.e. probably most of the time.)
–
GalacticCowboyJun 29 '10 at 15:09

2

I use a horizontal rule, which has the same effect but actually blends in a little better.
–
GalacticCowboyJun 29 '10 at 15:10

You can also put </foobar> there, it will have the same result. Or use a comment, as I said in my answer. Your version has the disadvantage that it can a) cause subtle errors, and b) it's totally non-obvious to someone editing your question.
–
balpha♦Jun 21 '13 at 12:55

@balpha: yeah that is correct. Thanks for the comment.
–
Midhun MPJun 21 '13 at 13:09