Skip to content
Permalink
Browse files

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.
  • Loading branch information...
domenic authored and annevk committed Aug 4, 2016
1 parent 5bafd7e commit 5fe3dbb016f40f0b7af0538dae9adc134be29c3f
Showing with 68 additions and 28 deletions.
  1. +68 −28 source
96 source
the attribute is omitted, the list is an ascending list (1, 2, 3, ...).</p>

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

<div w-nodev>

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

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

<p>Each subsequent item in the list has the <span>ordinal value</span> given by its <code
data-x="attr-li-value">value</code> attribute, if it has one, or, if it doesn't, the <span>ordinal
value</span> of the previous item, plus one if the <code data-x="attr-ol-reversed">reversed</code>
is absent, or minus one if it is present.</p>
<ol>
<li><p>Let <var>parsed</var> be the result of <span data-x="rules for parsing integers">parsing
the value of the attribute as an integer</span>.</p></li>

<li><p>If <var>parsed</var> is not an error, then return <var>parsed</var>.</p></li>
</ol>
</li>

<li><p>If the <code>ol</code> element has a <code data-x="attr-ol-reversed">reversed</code>
attribute, then return the number of child <code>li</code> elements.</p></li>

<li><p>Return 1.</p></li>
</ol>

</div>

parent element's list, as defined for those elements. Otherwise, the list item has no defined
list-related relationship to any other <code>li</code> element.</p>

<p>If the parent element is an <code>ol</code> element, then the <code>li</code> element has an
<dfn>ordinal value</dfn>.</p>

<p>The <dfn><code data-x="attr-li-value">value</code></dfn> attribute, if present, must be a
<span>valid integer</span> giving the <span>ordinal value</span> of the list item.</p>
<span>valid integer</span>. It is used to determine the <span>ordinal value</span> of the list
item, when the parent element is an <code>ol</code> element.</p>

<div w-nodev>

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

<p>The <code data-x="attr-li-value">value</code> attribute is processed relative to the element's
parent <code>ol</code> element (q.v.), if there is one. If there is not, the attribute has no
effect.</p>
<ol>
<li>
<p>If the <code>li</code> element has a <code data-x="attr-li-value">value</code> attribute,
then:</p>

<ol>
<li><p>Let <var>parsed</var> be the result of <span data-x="rules for parsing integers">parsing
the value of the attribute as an integer</span>.</p></li>

<li><p>If <var>parsed</var> is not an error, then return <var>parsed</var>.</p></li>
</ol>
</li>

<li><p>If the <code>li</code> element is the first <code>li</code> child of its parent
<code>ol</code> element, then return the <code>ol</code> element's <span
data-x="concept-ol-start">starting value</span>.</p></li>

<li><p>Let <var>previous</var> be the <span>ordinal value</span> of the first preceding sibling
that is an <code>li</code> element.</p></li>

<li><p>If the parent <code>ol</code> element has a <code
data-x="attr-ol-reversed">reversed</code> attribute, then return <var>previous</var> &#x2212;
1.</p></li>

<li><p>Return <var>previous</var> + 1.</p></li>
</ol>

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

<div class="example">
<p>The element's <code data-x="dom-li-value">value</code> IDL attribute does not directly
correspond to its <span>ordinal value</span>; it simply <span data-x="reflect">reflects</span>
the content attribute. For example, given this list:

<pre>&lt;ol>
&lt;li>Item 1
&lt;li value="3">Item 3
&lt;li>Item 4
&lt;/ol></pre>

<p>The <span data-x="ordinal value">ordinal values</span> are 1, 3, and 4, whereas the <code
data-x="dom-li-value">value</code> IDL attributes return 0, 3, 0 on getting.</p>
</div>

</div>

<div class="example">
<tr>
<th> <code data-x="">start</code>
<td> <code data-x="attr-ol-start">ol</code>
<td> <span>Ordinal value</span> of the first item
<td> <span data-x="concept-ol-start">Starting value</span> of the list
<td> <span>Valid integer</span>
<tr>
<th> <code data-x="">step</code>
David Vest,
David Woolley,
David Zbarsky,
Dave Methvin,
DeWitt Clinton,
Dean Edridge,
Dean Edwards,

0 comments on commit 5fe3dbb

Please sign in to comment.
You can’t perform that action at this time.