Skip to content
Permalink
Browse files

Fix how <li>s are numbered and associated with <ol>s

Closes #1911 and closes #1617.
  • Loading branch information...
domenic committed Nov 8, 2016
1 parent 4954d93 commit fd726b069bee2c73600fbccac8e36f8783549bfc
Showing with 59 additions and 16 deletions.
  1. +59 −16 source
75 source

<div w-nodev>

<!-- https://github.com/whatwg/html/issues/1617
https://github.com/whatwg/html/issues/1911 -->

<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>

</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>
attribute, then return the number of <span data-x="list owner">owned <code>li</code>
elements</span>.</p></li>

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

<p>The <dfn><code data-x="attr-li-value">value</code></dfn> attribute, if present, must be a
<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>
item, when the <code>li</code>'s <span>list owner</span> is an <code>ol</code> element.</p>

<div w-nodev>

<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>
<hr>

<p>Any element whose <span>computed value</span> of <span>'display'</span> is 'list-item' has a
<dfn>list owner</dfn>, which is determined as follows:</p>

<ol>
<li><p>If the element is not <span>being rendered</span>, return null; the element has no
<span>list owner</span>.</p>

<li><p>Let <var>ancestor</var> be the element's parent.</p></li>

<li><p>If the element has an <code>ol</code>, <code>ul</code>, or <code>menu</code> ancestor, set
<var>ancestor</var> to the closest such ancestor element.</p></li>

<li><p>Return the closest inclusive ancestor of <var>ancestor</var> that produces a CSS box, if
any. If no such inclusive ancestor exists, then return null; the element has no <span>list
owner</span>.</p></li>
</ol>

<p>To determine the <dfn>ordinal value</dfn> of each element owned by a given <span>list
owner</span> <var>owner</var>, perform the following steps:</p>

<ol>
<li><p>Let <var>i</var> be 1.</p></li>

<li><p>If <var>owner</var> is an <code>ol</code> element, let <var>numbering</var> be
<var>owner</var>'s <span data-x="concept-ol-start">starting value</span>. Otherwise, let
<var>numbering</var> be 1.</p></li>

<li><p><i>Loop:</i> If <var>i</var> is greater than the number of <span
data-x="list owner">list items that <var>owner</var> owns</span>, then abort this algorithm; all
of <var>owner</var>'s <span data-x="list owner">owned list items</span> have been assigned <span
data-x="ordinal value">ordinal values</span>.</p></li>

<li><p>Let <var>item</var> be the <var>i</var>th of <var>owner</var>'s <span data-x="list
owner">owned list items</span>, in <span>tree order</span>.</p>

<li>
<p>If the <code>li</code> element has a <code data-x="attr-li-value">value</code> attribute,
then:</p>
<p>If <var>item</var> is an <code>li</code> element that 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>
<li><p>If <var>parsed</var> is not an error, then set <var>numbering</var> to
<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>The <span>ordinal value</span> of <var>item</var> is <var>numbering</var>.</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 <var>owner</var> is an <code>ol</code> element, and <var>owner</var> has a <code
data-x="attr-ol-reversed">reversed</code> attribute, decrement <var>numbering</var> by 1;
otherwise, increment <var>numbering</var> by 1.</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>Increment <var>i</var> by 1.</p></li>

<li><p>Return <var>previous</var> + 1.</p></li>
<li><p>Go to the step labeled <i>loop</i>.</p>
</ol>

<p>The <span>ordinal value</span> of any element with a <span>list owner</span> of null is 0.</p>

<p class="note">This can only impact the rendered counter when all of the element's ancestors do
not produce CSS boxes, such as if they are all styled with <code data-x="">display:
contents</code>.</p>

<hr>

<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>

0 comments on commit fd726b0

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