Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown reverse ordered list?

Is there a way to display a reverse-ordered list in plain Markdown?

I read about the HTML "reverse" option here and here, but would favor a Markdown solution if that exists.

To clarify, is there a way to write something like:

0. Coffee 
0. Tea 
0. Milk 

and have it rendered as

 3. Coffee
 2. Tea
 1. Milk

instead of the regular

 1. Coffee
 2. Tea
 3. Milk
like image 544
user42174 Avatar asked May 07 '15 16:05

user42174


2 Answers

I don't know of a plain Markdown solution, but for those who are willing to consider pretty common markdown extensions, you can achieve this using kramdown. In Kramdown, you can add any attribute to any HTML block. So, all you need to do is:

0. first item
0. second item
0. another item
{: reversed="reversed"}

This will add the reversed attribute to your <ol> block and will generate the desired effect.

See the kramdown documentation for the syntax.

like image 156
stacksia Avatar answered Oct 04 '22 17:10

stacksia


The documentation states (in part):

It’s important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. ... [examples excluded for clarity and brevity] ...

The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don’t have to.

If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number.

In fact, a few implementations have started to support the start attribute (one example); however, it is rare. And even then, only the number of the first item is referenced. The numbers given to the rest of the items are still ignored.

I am not aware of any implementation which supports the reverse attribute. Besides, how would the parser detect it? Would all the numbers need to be checked by the parser? Or just the first two?

As HTML does not really provide a way to manually define the number of each and every list item manually, there is no reason for a Markdown parser to care about which numbers are assigned to each individual item. Therefore most (all?) don't.

Of course, Markdown does support raw HTML. As the Syntax Rules state:

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.

Therefore, you can manually define your list in raw HTML within your Markdown document:

A paragraph of Markdown text

<ol reversed>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>

More Markdown text.

And the philosophy behind why that is the correct way to do it is explained this way:

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert.

like image 42
Waylan Avatar answered Oct 04 '22 15:10

Waylan