Skip to main content
5 of 9
added 34 characters in body
user1114
  • 1
  • 8
  • 120
  • 221

How to nest code within a list using markdown

Oftentimes I want to include code samples in a list, for example:

  1. Item One
  2. Item Two, for example:

    private bool ItemTwo() { return this.IFeelLucky; }
  3. Item Three

The problem is there isn't a good and intuitive way to do this using markdown. It's doable, but you have to do some formatting black-magic to get it that way, which is just not "nice" to deal with.

Source that produces this:

1. Item One 2. Item Two, for example: <br/><br/><pre><code>private bool ItemTwo() { return this.IFeelLucky; }</code></pre> 3. Item Three

I would love to just be able to do it this way:

1. Item One 2. Item Two, for example: private bool Test() { return this.IFeelLucky; } 3. Item Three

Which results in, well, this:

  1. Item One

  2. Item Two, for example:

    private bool Test() { return this.IFeelLucky; }

  3. Item Three


Update: In order to use markdown, you have to indent a minimum of 8 spaces. I still stand my ground that this isn't 100% intuitive - you can indent only a single space to continue a list item (see below) - but at least it's good and easy.

1. List item Item continued 2. Another list item

Results in:

  1. List item

Item continued

  1. Another list item

Return to FAQ index

lc.
  • 4.9k
  • 4
  • 24
  • 21