Begin ordered list from 0 in Markdown
Asked Answered
S

4

40

I'm new to Markdown. I was writing something like:

# Table of Contents  
0. Item 0  
1. Item 1  
2. Item 2

But that generates a list that starts with 1, effectively rendering something like:

# Table of Contents
1. Item 0
2. Item 1
3. Item 2

I want to start the list from zero. Is there an easy way to do that?

If not, I could simply rename all of my indices, but this is annoying when there are several items. Beginning a list from zero seems so natural to me, it's like beginning the index of an array from zero.

Shipshape answered 25/2, 2013 at 23:16 Comment(0)
E
44

Simply: NO

Longer: YES, BUT

When you create ordered list in Markdown it is parsed to HTML ordered list, i.e.:

# Table of Contents

0. Item 0  
1. Item 1  
2. Item 2

Will create:

<h1>Table of Contents</h1>
<ol>
  <li>Item 0</li>
  <li>Item 1</li>
  <li>Item 2</li>
</ol>

So as you can see, there is no data about starting number. If you want to start at certain number, unfortunately, you have to use pure HTML and write:

<ol start="0">
  <li>Item 0</li>
  <li>Item 1</li>
  <li>Item 2</li>
</ol>
Enamel answered 25/2, 2013 at 23:24 Comment(0)
F
7

You can use HTML start tag:

<ol start="0">
  <li> item 1</li>
  <li> item 2</li>
  <li> item 3</li>
</ol>

It's currently supported in all browsers: Internet Explorer 5.5+, Firefox 1+, Safari 1.3+, Opera 9.2+, Chrome 2+

Optionally you can use type tab for more sophisticated enumerating:

  • type="1" - decimal (default style)
  • type="a" - lower-alpha
  • type="A" - upper-alpha
  • type="i" - lower-roman
  • type="I" - upper-roman
Faucher answered 25/2, 2013 at 23:22 Comment(0)
W
4

Via html: use <ol start="0">

Via CSS:

ol {
    counter-reset: num -1; // reset counter to -1 (any var name is possible)
}
ol li {
    list-style-type: none; // remove default numbers
}
ol li:before {
    counter-increment: num; // increment counter
    content: counter(num) ". "; 
}

FIDDLE

Wirer answered 30/4, 2015 at 4:32 Comment(0)
K
1

Update: Depends on the implementation.

The current version of CommonMark requires the start attribute. Some implementations already support this, e.g. pandoc and markdown-it. For more details see babelmark.

Ked answered 12/3, 2017 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.