user1027169
user1027169

Reputation: 2867

Create an automatically numbered list in Markdown format

What is the best way to create a numbered list in Markdown format? I currently have to manually enter the number I want to appear, but if I add items, I have to renumber them all.

Upvotes: 127

Views: 83933

Answers (4)

ilu
ilu

Reputation: 234

If you need add any comment/description/whatever under an item in the list. Only this option solved my case.

<ol>
<li>option 1</li>
Description
<li>option 2</li> 

    // Code example require empty line between and 4 spaces in front of the code line
    Hello World!
<li>option 3</li>
</ol>

Result:

  1. option 1
  2. Description
  3. option 2
  4. // Code example require empty line between and 4 spaces in front of the code line
    Hello World!
    
  5. option 3

Upvotes: -1

Nivethan
Nivethan

Reputation: 3629

OP's Question is easy to solve by adding a number with a dot then a space after. eg: 1.

we can keep use the same 1. for all the items so we don't have to number everything manually and even if you remove the second item you don't have to rename all numbers below

  1. item one
  2. item two
  3. item three


But I faced a problem while creating a GitHub gist. auto numbering was not working if i have a code block between them.

Problem if you have a code block in between

  1. step one
  2. step two
// a sample code block
  1. step three (this should be 3. )
  2. step four


Simple Solution

in order to solve this you need to add four spaces to indent content between bullet points

  1. step one
  2. step two
    // a sample code block
    
  3. step three
  4. step four

Note: you can click on the "edit" button below on this answer to see the underlying Markdown code but click on the cancel button instead of save!

Upvotes: 8

Timely10
Timely10

Reputation: 151

if you type the first one with a one like this 1. lorem then as long as the rest have a space after the dot then it should work

1. lorem
4. hello
3. blah blah blah

you should get this:

  1. lorem
  2. hello
  3. blah blah blah

Upvotes: 15

PeeHaa
PeeHaa

Reputation: 72671

That should happen automatically (at least in SO flavored MD):

  1. test 1
  2. test 2

The code I used it:

1. test 1
1. test 2

The same works for GitHub flavored MD: https://gist.github.com/3489721

You can test it here: https://meta.stackexchange.com/questions/3122/formatting-sandbox

Upvotes: 155

Related Questions