Markdown reverse ordered list?

Is there a way to display a reverse ordering list in regular Markdown?

I read about the "reverse" HTML option ( How do I display a reverse ordered list in HTML?, Http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ol_reversed ), but will help Markdown if it exists.

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

0. Coffee 0. Tea 0. Milk 

and display it as

3 Coffee

2 Tea

1 milk

instead of the usual

1 coffee

2 Tea

3 Milk

+6
source share
2 answers

I don't know a simple Markdown solution, but for those who want to consider the fairly common markup extensions, you can achieve this using kramdown. In Kramdown, you can add any attribute to any HTML block. So all you have 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 create the desired effect.

See kramdown documentation for syntax.

+5
source

The documentation states (partially):

It is important to note that the actual numbers you use to mark the list do not affect the HTML output that Markdown produces .... [examples are excluded for clarity and conciseness] ...

The point is, if you want, you can use serial numbers in ordered Markdown lists so that the numbers in your source match the numbers of the published HTML. But if you want to be lazy, you do not need.

However, if you are using the numbering of lazy lists, you should still run list number 1. At some point in the future, Markdown may support the launch of ordered lists with an arbitrary number.

In fact, several implementations began to support the start attribute ( one example ); however, this is rare. And even then only the number of the first element is mentioned. The numbers left by the rest of the elements are still ignored.

I do not know any implementation that supports the reverse attribute. Also, how would a parser detect this? Will the whole number have to be checked by the parser? Or just the first two?

Since HTML does not provide a way to manually quantify each item in a list manually, there is no reason for the Markdown parser to care about which numbers are assigned to each individual item. Therefore, most (all?) Do not.

Of course, Markdown supports raw HTML . According to the syntax rules:

For any markup that is not covered by Markdowns syntax, you simply use HTML.

Therefore, you can manually define your list in raw HTML in a 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 of why this is the right way to do this is explained as follows:

Markdown is not a replacement for HTML or even close to it. Its syntax is very small, which corresponds to only a very small subset of HTML tags. The idea is not to create syntax that simplifies the insertion of HTML tags. In my opinion, HTML tags are already easily inserted.

+4
source

Source: https://habr.com/ru/post/986764/


All Articles