Skip to content

Commit acadaaa

Browse files
committed
[css3-lists] Rewrite the counter() section.
1 parent 5a7ffb2 commit acadaaa

2 files changed

Lines changed: 165 additions & 92 deletions

File tree

css3-lists/Overview.html

Lines changed: 95 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ <h2 class="no-num no-toc" id=contents> Table of contents</h2>
196196
</ul>
197197

198198
<li><a href="#counter-function"><span class=secno>9. </span> Printing
199-
Counters: the <code class=css>counter()</code> and <code
200-
class=css>counters()</code> functions</a>
199+
Counters: the <code title=counter-function>counter()</code> and <code
200+
title=counters-function>counters()</code> functions</a>
201201

202202
<li><a href="#counter-style"><span class=secno>10. </span> Defining Custom
203203
Counter Styles: the ‘<code class=css>@counter-style</code>’ rule</a>
@@ -1560,8 +1560,10 @@ <h2 id=counter><span class=secno>8. </span> Automatic Numbering With
15601560
href="#counter-set"><code class=property>counter-set</code></a>’ and
15611561
<a href="#counter-reset"><code
15621562
class=property>counter-reset</code></a>’ properties, and used with the
1563-
<a href="#counter0"><code class=css>counter()</code></a>’ and
1564-
<code class=css>counters()</code>’ functions. Counters have an
1563+
<a href="#counter-function"><code
1564+
title=counter-function>counter()</code></a> and <a
1565+
href="#counters-function"><code
1566+
title=counters-function>counters()</code></a> functions. Counters have an
15651567
integer value, a creator element, and possibly another counter nested
15661568
inside themselves.
15671569

@@ -1927,88 +1929,107 @@ <h3 id=counters-without-boxes><span class=secno>8.4. </span> Counters in
19271929
so do not apply here.
19281930

19291931
<h2 id=counter-function><span class=secno>9. </span> Printing Counters: the
1930-
<a href="#counter0"><code class=css>counter()</code></a>’ and
1931-
<code class=css>counters()</code>’ functions</h2>
1932-
1933-
<p>Counters have no visible effect by themselves, but their values can be
1934-
used in the ‘<a href="#counter0"><code class=css>counter()</code></a>
1935-
and ‘<code class=css>counters()</code>’ functions to generate counter
1936-
representations. This happens automatically in the default contents of
1937-
<code class=css>::marker</code>’ pseudo-elements, but can be used by
1938-
an author anywhere that accepts a string. Their syntax is:
1932+
<a href="#counter-function"><code
1933+
title=counter-function>counter()</code></a> and <a
1934+
href="#counters-function"><code
1935+
title=counters-function>counters()</code></a> functions</h2>
1936+
1937+
<p> Counters have no visible effect by themselves, but their values can be
1938+
used with the <a href="#counter-function"><code
1939+
title=counter-function>counter()</code></a> and <a
1940+
href="#counters-function"><code
1941+
title=counters-function>counters()</code></a> functions. This happens
1942+
automatically in the default contents of ‘<code
1943+
class=css>::marker</code>’ pseudo-elements, but can be used by an author
1944+
anywhere that accepts a string. Their syntax is:
19391945

19401946
<pre>
1947+
<dfn id=counter-function
1948+
title=counter-function>&lt;counter-function></dfn> = counter(&lt;ident> [, [ <code>&lt;counter-style></code> | none ] ]? )
19411949
<dfn
1942-
id=ltcounter-function>&lt;counter-function></dfn> = counter(name [, [ &lt;counter-style> | none ] ]? )
1943-
<dfn
1944-
id=ltcounters-function>&lt;counters-function></dfn> = counters(name, &lt;string>[, [ &lt;counter-style> | none ] ]? )</pre>
1950+
id=counters-function
1951+
title=counters-function>&lt;counters-function></dfn> = counters(&lt;ident>, &lt;string>[, [ <code>&lt;counter-style></code> | none ] ]? )</pre>
19451952

1946-
<p>For both functions, if the <code
1947-
class=css>&lt;counter-style></code> is omitted it defaults to ‘<a
1953+
<p> For both functions, the first argument represents the name of a
1954+
counter, and if the last argument is omitted it defaults to ‘<a
19481955
href="#decimal"><code class=css>decimal</code></a>’.
19491956

1950-
<p>A ‘<a href="#ltcounter-function"><code
1951-
class=css>&lt;counter-function></code></a>’ represents the string
1952-
obtained when one <a href="#generate-a-counter-representation"><i
1953-
title=generate-a-counter>generates a counter representation</i></a> of the
1954-
named counter's value using the function's ‘<code
1955-
class=css>&lt;counter-style></code>’. If there are multiple counters of
1956-
that name in scope, the one whose scoping element is closest in
1957-
document-order to the element on which ‘<a href="#counter0"><code
1958-
class=css>counter()</code></a>’ appears is used. If there are no
1959-
counters of that name in scope, use the value ‘<code
1960-
class=css>0</code>’ to generate the counter representation. If ‘<a
1961-
href="#list-style-type-none"><code class=css>none</code></a>’ is
1962-
provided as the second argument, the ‘<a
1963-
href="#ltcounter-function"><code
1964-
class=css>&lt;counter-function></code></a>’ instead represents the empty
1965-
string.
1957+
<p> A <a href="#counter-function"><code
1958+
title=counter-function>&lt;counter-function></code></a> represents a <code
1959+
title="">&lt;string></code>, obtained as follows:
1960+
1961+
<ul>
1962+
<li> If the second argument to the function is ‘<a
1963+
href="#list-style-type-none"><code class=css><i
1964+
title="">none</i></code></a>’, the function represents the empty
1965+
string.
1966+
1967+
<li> Otherwise, the function represents the string returned when one <a
1968+
href="#generate-a-counter-representation"><i
1969+
title=generate-a-counter>generates a counter representation</i></a> for
1970+
the value of the innermost counter of that name on the element (or
1971+
<code class=css>0</code>’ if the element has no counter of that
1972+
name) using the <code>&lt;counter-style></code> specified by the second
1973+
argument.
1974+
</ul>
19661975

19671976
<div class=example>
19681977
<pre>
1969-
H1:before { content: counter(chno, upper-latin) ". " }
1978+
H1::before { content: counter(chno, upper-latin) ". " }
19701979
/* Generates headings like "A. A History of Discontent" */
19711980

1972-
H2:before { content: counter(section, upper-roman) " - " }
1981+
H2::before { content: counter(section, upper-roman) " - " }
19731982
/* Generates headings like "II - The Discontent Part" */
19741983

1975-
BLOCKQUOTE:after { content: " [" counter(bq, decimal) "]" }
1984+
BLOCKQUOTE::after { content: " [" counter(bq, decimal) "]" }
19761985
/* Generates blockquotes that end like "... [3]" */
19771986

1978-
DIV.note:before { content: counter(notecntr, disc) " " }
1987+
DIV.note::before { content: counter(notecntr, disc) " " }
19791988
/* Simply generates a bullet before every div.note */
19801989

1981-
P:before { content: counter(p, none) }
1990+
P::before { content: counter(p, none) }
19821991
/* inserts nothing */</pre>
19831992
</div>
19841993

1985-
<p>A ‘<a href="#ltcounters-function"><code
1986-
class=css>&lt;counters-function></code></a> represents the string
1987-
obtained by the following algorithm:
1994+
<p> A <a href="#counters-function"><code
1995+
title=counters-function>&lt;counters-function></code></a> represents a
1996+
<code title="">&lt;string></code>, obtained as follows:
19881997

1989-
<ol>
1990-
<li>Collect all counters of the given name that are in scope for the
1991-
elements on which ‘<code class=css>counters()</code>’ appears, sorted
1992-
by document-order of each scope's scoping element. If there are no such
1993-
counters, run the rest of this algorithm as if there were a single
1994-
counter with the value ‘<code class=css>0</code>’.
1998+
<ul>
1999+
<li> If the third argument to the function is ‘<a
2000+
href="#list-style-type-none"><code class=css><i
2001+
title="">none</i></code></a>’, the function represents the empty
2002+
string.
19952003

1996-
<li>Render each counter as a string by <a
2004+
<li> Otherwise, if the element has no counters of that name, the function
2005+
represents the string returned when one <a
19972006
href="#generate-a-counter-representation"><i
1998-
title=generate-a-counter>generating a counter representation</i></a> of
1999-
the counter's value using the function's &lt;counter-style>. If ‘<a
2000-
href="#list-style-type-none"><code class=css>none</code></a>’ is
2001-
provided as the third argument, instead render each counter as the empty
2002-
string.
2007+
title=generate-a-counter>generates a counter representation</i></a> for
2008+
<code class=css>0</code>’ using the <code>&lt;counter-style></code>
2009+
specified by the third argument.
20032010

2004-
<li>Concatenate all of the counter representations in order, placing a
2005-
copy of the string provided as the second argument between each adjacent
2006-
pair, and return the resulting string.
2007-
</ol>
2011+
<li> Otherwise, if the element has a single counter of that name, the
2012+
function represents the string returned when one <a
2013+
href="#generate-a-counter-representation"><i
2014+
title=generate-a-counter>generates a counter representation</i></a> for
2015+
that counter's value using the <code>&lt;counter-style></code> specified
2016+
by the third argument.
2017+
2018+
<li> Otherwise, <a href="#generate-a-counter-representation"><i
2019+
title=generate-a-counter>generate a counter representation</i></a> for
2020+
the values of all counters of the given name on the element using the
2021+
<code>&lt;counter-style></code> specified by the third argument. Sort the
2022+
resulting strings by the nesting depth of the counters they were
2023+
generated from, with the outermost counter first and the innermost last.
2024+
Join the list into a single string, inserting the <code
2025+
title="">&lt;string></code> specified by the second argument between each
2026+
item in the list. The function represents the string thus produced.
2027+
</ul>
20082028

20092029
<div class=example>
2010-
<p>The following example shows a simple use of the ‘<code
2011-
class=css>counters()</code>’ function:
2030+
<p>The following example shows a simple use of the <a
2031+
href="#counters-function"><code
2032+
title=counters-function>counters()</code></a> function:
20122033

20132034
<pre>
20142035
&lt;ul>
@@ -2038,11 +2059,13 @@ <h2 id=counter-function><span class=secno>9. </span> Printing Counters: the
20382059
</div>
20392060

20402061
<div class=example>
2041-
<p>Because counter scopes extend to siblings as well, they can be used to
2062+
<p> Because counters inherit to siblings as well, they can be used to
20422063
number headings and subheadings, which aren't nested within each other.
2043-
Unfortunately, this precludes the use of ‘<code
2044-
class=css>counters()</code>’ as the scopes of siblings won't nest, but
2045-
one can create multiple counters and manually reference them instead:
2064+
Unfortunately, this prevents the use of <a
2065+
href="#counters-function"><code
2066+
title=counters-function>counters()</code></a> as counters from siblings
2067+
don't nest, but one can create multiple counters and manually concatenate
2068+
them instead:
20462069

20472070
<pre>
20482071
&lt;h1>First H1&lt;/h1>
@@ -2104,9 +2127,10 @@ <h2 id=counter-style><span class=secno>10. </span> Defining Custom Counter
21042127
this in an open-ended manner, by allowing the author to define their own
21052128
counter styles. These styles can then be used in the ‘<a
21062129
href="#list-style-type"><code class=property>list-style-type</code></a>
2107-
property or in the ‘<a href="#counter0"><code
2108-
class=css>counter()</code></a>’ and ‘<code
2109-
class=css>counters()</code>’ functions.
2130+
property or in the <a href="#counter-function"><code
2131+
title=counter-function>counter()</code></a> and <a
2132+
href="#counters-function"><code
2133+
title=counters-function>counters()</code></a> functions.
21102134

21112135
<p>A <dfn id=counter-style0>counter style</dfn> defines how to construct
21122136
the representation of a counter value. Counter styles are composed of:
@@ -3693,8 +3717,8 @@ <h2 class=no-num id=index>Index</h2>
36933717
<li>counter-fallback, <a href="#fallback-style"
36943718
title=counter-fallback><strong>10.</strong></a>
36953719

3696-
<li>&lt;counter-function>, <a href="#ltcounter-function"
3697-
title="&lt;counter-function>"><strong>9.</strong></a>
3720+
<li>counter-function, <a href="#counter-function"
3721+
title=counter-function><strong>9.</strong></a>
36983722

36993723
<li>counter-increment, <a href="#counter-increment"
37003724
title=counter-increment><strong>8.1.</strong></a>
@@ -3717,8 +3741,8 @@ <h2 class=no-num id=index>Index</h2>
37173741
<li>counter-set, <a href="#counter-set"
37183742
title=counter-set><strong>8.1.</strong></a>
37193743

3720-
<li>&lt;counters-function>, <a href="#ltcounters-function"
3721-
title="&lt;counters-function>"><strong>9.</strong></a>
3744+
<li>counters-function, <a href="#counters-function"
3745+
title=counters-function><strong>9.</strong></a>
37223746

37233747
<li>counter style, <a href="#counter-style0"
37243748
title="counter style"><strong>10.</strong></a>

0 commit comments

Comments
 (0)