DEV Community

Cover image for Ordered list in Markdown made easy
Amin
Amin

Posted on

Ordered list in Markdown made easy

What we are going to see in this tiny article is how to generate a Markdown's ordered list without even thinking about the ordering, and thus preventing any mistake.

The issue

Ordered lists in Markdown are awesome, we write an index and some text, and it formats it right for us.

Unfortunately, this can lead to some errors if we edit our steps afterthought, or if we try to insert a new element.

Let's take a quick example.

1. Open https://dev.to/
2. Search "Ordered list in Markdown made easy"
3. Read the article
4. ???
5. Profit
Enter fullscreen mode Exit fullscreen mode

Pretty straightforward. We define an ordered list for how to read this article. Each step has an index that indicates the order in which we should follow in order to successfully find and read this article.

Now, let's say we want to add another step to this ordered list.

1. Open https://dev.to/
2. Search "Ordered list in Markdown made easy"
3. Read the article
3. Leave a comment
4. ???
5. Profit
Enter fullscreen mode Exit fullscreen mode

Oops! we just made a mistake: we are repeating the index 3 two times. Of course, with such a small list we would catch the error pretty quickly. Now let's assume we have a bigger list. Not so easy anymore, huh...

The solution

Actually, we don't even have to think about the order when we are writing Markdown since the engine is already able to compute the order for us.

1. Open https://dev.to/
1. Search "Ordered list in Markdown made easy"
1. Read the article
1. ???
1. Profit
Enter fullscreen mode Exit fullscreen mode

It seems weird, right? Well, this totally works and we can test it on our own projects, for instance if we want to add some steps for the installation of a GitHub project.

And now, adding another item to this list has just become easier.

1. Open https://dev.to/
1. Search "Ordered list in Markdown made easy"
1. Read the article
1. Leave a comment
1. ???
1. Profit
Enter fullscreen mode Exit fullscreen mode

Just like that, the Markdown engine will recompile our code and compute the order for us, without making any mistakes.

Top comments (0)