Begin ordered list from 0 in Markdown

别说谁变了你拦得住时间么 提交于 2019-12-09 07:36:22

问题


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:

Table of Contents

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

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

If not, I can simply rename all of my indices, but this is annoying when I have several items. And I didn't think I would got this problem, begin a list from zero looks so natural to me like begin the index of an array from zero.


回答1:


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>



回答2:


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



回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/15078393/begin-ordered-list-from-0-in-markdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!