Skip to content

Commit 5fe3dbb

Browse files
domenicannevk
authored andcommitted
Make <li> ordinal value calculation precise
Fixes #1608. As noted there, the existing prose was using confusing concepts of attributes being "treated as if they were absent" and "attribute values" that were distinct from the usual meaning.
1 parent 5bafd7e commit 5fe3dbb

File tree

1 file changed

+68
-28
lines changed

1 file changed

+68
-28
lines changed

source

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17487,27 +17487,32 @@ interface <dfn>HTMLOListElement</dfn> : <span>HTMLElement</span> {
1748717487
the attribute is omitted, the list is an ascending list (1, 2, 3, ...).</p>
1748817488

1748917489
<p>The <dfn><code data-x="attr-ol-start">start</code></dfn> attribute, if present, must be a
17490-
<span>valid integer</span> giving the <span>ordinal value</span> of the first list item.</p>
17490+
<span>valid integer</span>. It is used to determine the <span data-x="concept-ol-start">starting
17491+
value</span> of the list.</p>
1749117492

1749217493
<div w-nodev>
1749317494

17494-
<p>If the <code data-x="attr-ol-start">start</code> attribute is present, user agents must <span
17495-
data-x="rules for parsing integers">parse it as an integer</span>, in order to determine the
17496-
attribute's value. The default value, used if the attribute is missing or if the value cannot be
17497-
converted to a number according to the referenced algorithm, is 1 if the element has no <code
17498-
data-x="attr-ol-reversed">reversed</code> attribute, and is the number of child <code>li</code>
17499-
elements otherwise.</p>
17495+
<p>An <code>ol</code> element has a <dfn data-x="concept-ol-start">starting value</dfn>, which is
17496+
an integer determined as follows:</p>
1750017497

17501-
<p>The first item in the list has the <span>ordinal value</span> given by the <code>ol</code>
17502-
element's <code data-x="attr-ol-start">start</code> attribute, unless that <code>li</code> element
17503-
has a <code data-x="attr-li-value">value</code> attribute with a value that can be successfully
17504-
parsed, in which case it has the <span>ordinal value</span> given by that <code
17505-
data-x="attr-li-value">value</code> attribute.</p>
17498+
<ol>
17499+
<li>
17500+
<p>If the <code>ol</code> element has a <code data-x="attr-ol-start">start</code> attribute,
17501+
then:</p>
1750617502

17507-
<p>Each subsequent item in the list has the <span>ordinal value</span> given by its <code
17508-
data-x="attr-li-value">value</code> attribute, if it has one, or, if it doesn't, the <span>ordinal
17509-
value</span> of the previous item, plus one if the <code data-x="attr-ol-reversed">reversed</code>
17510-
is absent, or minus one if it is present.</p>
17503+
<ol>
17504+
<li><p>Let <var>parsed</var> be the result of <span data-x="rules for parsing integers">parsing
17505+
the value of the attribute as an integer</span>.</p></li>
17506+
17507+
<li><p>If <var>parsed</var> is not an error, then return <var>parsed</var>.</p></li>
17508+
</ol>
17509+
</li>
17510+
17511+
<li><p>If the <code>ol</code> element has a <code data-x="attr-ol-reversed">reversed</code>
17512+
attribute, then return the number of child <code>li</code> elements.</p></li>
17513+
17514+
<li><p>Return 1.</p></li>
17515+
</ol>
1751117516

1751217517
</div>
1751317518

@@ -17699,26 +17704,60 @@ interface <dfn>HTMLLIElement</dfn> : <span>HTMLElement</span> {
1769917704
parent element's list, as defined for those elements. Otherwise, the list item has no defined
1770017705
list-related relationship to any other <code>li</code> element.</p>
1770117706

17702-
<p>If the parent element is an <code>ol</code> element, then the <code>li</code> element has an
17703-
<dfn>ordinal value</dfn>.</p>
17704-
1770517707
<p>The <dfn><code data-x="attr-li-value">value</code></dfn> attribute, if present, must be a
17706-
<span>valid integer</span> giving the <span>ordinal value</span> of the list item.</p>
17708+
<span>valid integer</span>. It is used to determine the <span>ordinal value</span> of the list
17709+
item, when the parent element is an <code>ol</code> element.</p>
1770717710

1770817711
<div w-nodev>
1770917712

17710-
<p>If the <code data-x="attr-li-value">value</code> attribute is present, user agents must <span
17711-
data-x="rules for parsing integers">parse it as an integer</span>, in order to determine the
17712-
attribute's value. If the attribute's value cannot be converted to a number, the attribute must be
17713-
treated as if it was absent. The attribute has no default value.</p>
17713+
<p>If the parent element is an <code>ol</code> element, then the <code>li</code> element has an
17714+
<dfn>ordinal value</dfn>, which is an integer determined as follows:</p>
1771417715

17715-
<p>The <code data-x="attr-li-value">value</code> attribute is processed relative to the element's
17716-
parent <code>ol</code> element (q.v.), if there is one. If there is not, the attribute has no
17717-
effect.</p>
17716+
<ol>
17717+
<li>
17718+
<p>If the <code>li</code> element has a <code data-x="attr-li-value">value</code> attribute,
17719+
then:</p>
17720+
17721+
<ol>
17722+
<li><p>Let <var>parsed</var> be the result of <span data-x="rules for parsing integers">parsing
17723+
the value of the attribute as an integer</span>.</p></li>
17724+
17725+
<li><p>If <var>parsed</var> is not an error, then return <var>parsed</var>.</p></li>
17726+
</ol>
17727+
</li>
17728+
17729+
<li><p>If the <code>li</code> element is the first <code>li</code> child of its parent
17730+
<code>ol</code> element, then return the <code>ol</code> element's <span
17731+
data-x="concept-ol-start">starting value</span>.</p></li>
17732+
17733+
<li><p>Let <var>previous</var> be the <span>ordinal value</span> of the first preceding sibling
17734+
that is an <code>li</code> element.</p></li>
17735+
17736+
<li><p>If the parent <code>ol</code> element has a <code
17737+
data-x="attr-ol-reversed">reversed</code> attribute, then return <var>previous</var> &#x2212;
17738+
1.</p></li>
17739+
17740+
<li><p>Return <var>previous</var> + 1.</p></li>
17741+
</ol>
1771817742

1771917743
<p>The <dfn><code data-x="dom-li-value">value</code></dfn> IDL attribute must <span>reflect</span>
1772017744
the value of the <code data-x="attr-li-value">value</code> content attribute.</p>
1772117745

17746+
<div class="example">
17747+
<p>The element's <code data-x="dom-li-value">value</code> IDL attribute does not directly
17748+
correspond to its <span>ordinal value</span>; it simply <span data-x="reflect">reflects</span>
17749+
the content attribute. For example, given this list:
17750+
17751+
<pre>&lt;ol>
17752+
&lt;li>Item 1
17753+
&lt;li value="3">Item 3
17754+
&lt;li>Item 4
17755+
&lt;/ol></pre>
17756+
17757+
<p>The <span data-x="ordinal value">ordinal values</span> are 1, 3, and 4, whereas the <code
17758+
data-x="dom-li-value">value</code> IDL attributes return 0, 3, 0 on getting.</p>
17759+
</div>
17760+
1772217761
</div>
1772317762

1772417763
<div class="example">
@@ -116729,7 +116768,7 @@ interface <dfn>External</dfn> {
116729116768
<tr>
116730116769
<th> <code data-x="">start</code>
116731116770
<td> <code data-x="attr-ol-start">ol</code>
116732-
<td> <span>Ordinal value</span> of the first item
116771+
<td> <span data-x="concept-ol-start">Starting value</span> of the list
116733116772
<td> <span>Valid integer</span>
116734116773
<tr>
116735116774
<th> <code data-x="">step</code>
@@ -119089,6 +119128,7 @@ INSERT INTERFACES HERE
119089119128
David Vest,
119090119129
David Woolley,
119091119130
David Zbarsky,
119131+
Dave Methvin,
119092119132
DeWitt Clinton,
119093119133
Dean Edridge,
119094119134
Dean Edwards,

0 commit comments

Comments
 (0)