List numbering Jupyter notebook markdown
There are multiple ways we can create lists in Jupyter notebook in markdown mode. The easiest way that I recommend myself is simple:
just append *
(make sure to include the space after the asterisk) before the item in the list. For example:
* one
* two
* three
Output:
- one
- two
- three
Another way you just type any number
and dot
like 1.
and then type item of the list.
1. one
2. two
3. three
so will see the output as:
- one
- two
- three
and if you want to change the list format like convert dot to number or number to dot just simple change one element in the appropriate format and the whole list will convert.
e.g.
1. one
* two
* three
output will
- one
- two
- three
and
* one
2. two
3. three
output :
- one
- two
- three
This is not directly possible with standard Markdown, although you can "fake it" (see below). In fact the rules state:
It’s important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. ... 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.
That future never arrived, officially. However a few different Markdown implementations may offer such a feature as a non-default option. Unfortunately, it is rare (and I don't recall which implementations they are).
Regardless, you will have another problem. It is not clear to me how your desired output would be valid HTML. Essentially, you are asking for paragraphs outside of your list items which are nested inside your list. That would be invalid HTML:
<ol>
<p>This is some info.</p>
<li>This is question one.</li>
<p>This is more info.</p>
<li>This is question two.</li>
</ol>
That said, it will (almost) display as you desire (the non-list items are also indented).
This is some info.
- This is question one.
This is more info.
- This is question two.
I wouldn't recommend it but you could use that as raw HTML. Perhaps you could find some other method or format to represent your data.
I considered suggesting use an ordered list nested inside a definition list if your Markdown implementation supports it (while non-standard, this feature is very common and consistent across implementations, although it may not be on by default). It does give you the proper nesting but the same problem if nonconsecutive numbers persists. However, if you manually add the numbers and escape them so that they are not interpreted as list items, it works like this:
This is some info.
: 1\. This is question one.
This is more info.
: 2\. This is question two.
That renders as:
<dl>
<dt>This is some info.</dt>
<dd>1. This is question one.</dd>
<dt>This is more info.</dt>
<dd>2. This is question two.</dd>
</dl>
And displays as:
- This is some info.
- 1. This is question one.
- This is more info.
- 2. This is question two.
Interestingly, as SO removes the (commonly default) indentation on definition lists, in my attempts to fake it in the demo above, I realized there is a simpler solution which should work in all Markdown implementations. Just use paragraphs, manual numbers, and non-breaking spaces to force indentation:
This is some info.
1. This is question one.
This is more info.
2. This is question two.
Note that the non-breaking spaces cause Markdown to not see those lines as list items negating the need to escape them. The above renders as:
<p>This is some info.</p>
<p> 1. This is question one.</p>
<p>This is more info.</p>
<p> 2. This is question two.</p>
And displays as:
This is some info.
1. This is question one.
This is more info.
2. This is question two.