commonmark-spec
commonmark-spec copied to clipboard
Ordered lists have the wrong numbers
I saw that Stack Overflow was switching to CommonMark and wondered if this spec fixes the old problems with ordered list numbering, and tried it out on https://spec.commonmark.org/dingus/
Starting a list at a number other than 1 is fixed, but skipping numbers is not:
3. This should be 3.
4. This should be 4.
7. This should be 7.
8. This should be 8.
should produce itself, but instead produces
3. This should be 3.
4. This should be 4.
5. This should be 7.
6. This should be 8.
(The most common reason to do this is to respond point-by-point to something without responding to every point.)
I personally like to respond like so:
> 3. asd
Response.
> 8. asd
Response.
HTML does allow a value attribute on <li> elements, when in <ol>:
<ol>
<li>Item 1
<li value="3">Item 3
<li>Item 4
</ol>
I would generally be in favor of supporting something like this, but it breaks a common pattern in Markdown:
1. Item 1
1. Item 2
1. Item 3
…authors in Markdown are expecting that further list-item values don’t matter.
I would generally be in favor of supporting something like this, but it breaks a common pattern in Markdown:
1. Item 1 1. Item 2 1. Item 3…authors in Markdown are expecting that further list-item values don’t matter.
Yes, I use that, too, but repeated non-consecutive numbers could still be treated differently from skipped consecutive numbers.
How would this idea work with:
1. a
2. b
2. c
1. d
And:
4. a
3. b
2. c
1. d
Something like this may work:
An algorithm to determine the ordinal value of an item in an ordered (numbered) list:
- let current be the literal value of the current list item
- if there is no previous list item, return current
- let ordinal be the ordinal value of the previous list item incremented by
1 - if current is the literal value of the previous list item, return ordinal
- if current is ordinal, return ordinal
- return current
Ordinal values are then used to set attributes:
- if the ordinal value of the first item is not
1, setstarton the list to the ordinal value. - if the ordinal value of an item is not the ordinal value of the previous item incremented by
1, setvalueon the item to the ordinal value.
1. asd
1. asd
1. asd
1. asd
Yields:
<ol>
<li>asd</li>
<li>asd</li>
<li>asd</li>
<li>asd</li>
</ol>
1. asd
1. asd
3. asd
4. asd
Yields:
<ol>
<li>asd</li>
<li>asd</li>
<li>asd</li>
<li>asd</li>
</ol>
3. asd
3. asd
3. asd
3. asd
Yields:
<ol start="3">
<li>asd</li>
<li>asd</li>
<li>asd</li>
<li>asd</li>
</ol>
3. asd
4. asd
5. asd
6. asd
Yields:
<ol start="3">
<li>asd</li>
<li>asd</li>
<li>asd</li>
<li>asd</li>
</ol>
1. asd
3. asd
4. asd
5. asd
Yields:
<ol>
<li>asd</li>
<li value="3">asd</li>
<li>asd</li>
<li>asd</li>
</ol>
4. asd
3. asd
2. asd
1. asd
Yields:
<ol start="4">
<li>asd</li>
<li value="3">asd</li>
<li value="2">asd</li>
<li value="1">asd</li>
</ol>
1. asd
1. asd
1. asd
4. asd
Yields:
<ol>
<li>asd</li>
<li>asd</li>
<li>asd</li>
<li>asd</li>
</ol>