18

If you put a block of code after a bullet point it doesn't get formatted properly unless there's an intervening line of normal text. Just blank lines doesn't do any good. See my examples below, the first demonstrate the problem, the second and third potential ways to mitigate it; one of which doesn't always apply and the second of which is a kludge with side effects.

  • Example 1: bullet point with empty lines after it. This breaks the code block.

    //4 spaces of indent - should be code block but not

    //8 spaces of indent - should be code block and indented 4 spaces but is 
    //showing as no indent in the code, but the block as a while indented to 
    //match the last bullet.
    

  • Example 2: bullet point

Normal text after the bullet, this makes everything work correctly. But there isn't always something to reasonably put here.

//4 spaces of indent - works this time

    //8 spaces of indent - works this time

  • Example 3: bullet point with an   on the following line as a kludge to work around the problem. This makes the code format correct, but increases the amount of displayed white space.

 

//4 spaces of indent - works this time

    //8 spaces of indent - works this time
3
  • 4
    Go @Oded! Under 50 seconds to status-bydesign. Can he make it under 30 next time? Stay tuned for another exiting episode of: Previously Reported Non-bugs! Commented Jul 26, 2014 at 19:48
  • 3
    @Anonymous: that's the other problem: wanting your code block to be part of the bullet point. The OP here doesn't want the code block to be part of the bullet. Commented Jul 27, 2014 at 1:10
  • @MartijnPieters True. It was the closest duplicate that I could find at the time, but I felt it was suitable because this question could be answered by the answers on that question and this question is at least somewhat similar to the other.
    – Anonymous
    Commented Jul 27, 2014 at 4:06

3 Answers 3

36

After a bullet point, any following indented text is always still part of that bullet point. The only way you can 'break' that association is by inserting text without indentation.

That text does not have to be visible however. Insert a <!-- --> empty comment, for example:

* Bullet point

<!-- bullet, be-gone -->

    Code block

which is rendered as:

  • Bullet point

Code block
6
  • 2
    Oh, nice trick. I spend a lot of time formatting others posts. That will come in handy.
    – jww
    Commented Jul 26, 2014 at 19:55
  • 6
    This seems like a bug to me. You shouldn't need to add a comment (which shouldn't do anything, by definition) after bullets in order to get code blocks to display correctly.
    – Ajedi32
    Commented Jan 15, 2015 at 14:42
  • 1
    @Ajedi32: so how would you propose differentiating between paragraphs that are still part of the bullet point, and a code block that isn't? Take into account that you can now create a bullet point with multiple paragraphs, simply by indenting those extra paragraphs. Commented Jan 15, 2015 at 14:43
  • 1
    @Ajedi32: at issue here is that the indentation needed to denote a code block conflicts with the indentation for further paragraphs. The comment is one way (an invisible way) to insert text that is not indented to signal the end of the bullet point. Commented Jan 15, 2015 at 14:45
  • 1
    @MartijnPieters Hmm, good point. My original thought was that extra paragraphs should only be indented two spaces, since that would make them line up with the bullet, and that paragraphs indented 4 spaces could still be treated as code. Now that I think about it though, that wouldn't solve the problem for bullets that are two levels deep, since 4 spaces would be exactly the right amount to line up an extra paragraph with the 2nd-level bullet. Maybe we just need fenced code blocks...
    – Ajedi32
    Commented Jan 15, 2015 at 14:57
  • 1
    @Ajedi32: one day we'll have CommonMark and perhaps fenced blocks will be included in the implementation. :-) Commented Jan 15, 2015 at 14:59
3

That's how code blocks in markdown work.

You need to indent 8 spaced within a list (bullet or numbered).

4
  • 8
    Or insert a <!-- --> if it is not meant to be part of the bullet. Commented Jul 26, 2014 at 19:49
  • The code isn't supposed to be part of the list. I'm looking for a non-kludge way to get it displayed normally. Commented Jul 26, 2014 at 19:49
  • @MartijnPieters thanks, that gets the identing back to normal without adding excess whitespace. Commented Jul 26, 2014 at 19:51
  • Since this is really a support request, I've retagged it as such. Perhaps the status-bydesign should be removed? Commented Jul 26, 2014 at 19:59
0

You can also use a fail HTML tag:

* Bullet point text

<lols

    class Shepard extends Dog {}

You will get:

  • Bullet point text

class Shepard extends Dog {}
1
  • 2
    Use a HTML comment instead: <!---->
    – Cerbrus
    Commented Mar 23, 2016 at 14:46

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