Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace current outline algorithm with one based on heading levels #7829

Merged
merged 45 commits into from
Jul 1, 2022
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1065688
removed outline algorithm
stevefaulkner Apr 17, 2022
f86c397
clarify allowed content of hgroup
stevefaulkner Apr 17, 2022
e96100f
updated headings and sections
stevefaulkner Apr 18, 2022
7ffe0bd
removed sectioning root concept
stevefaulkner Apr 18, 2022
6b5cc4c
fixed conflict
stevefaulkner Apr 19, 2022
0d2fa7b
another fix?
stevefaulkner Apr 19, 2022
3d23dab
added return h1
stevefaulkner Apr 19, 2022
88bc37a
Fix build errors
sideshowbarker Apr 20, 2022
f5f3917
Fix markup error caught by HTML checker
sideshowbarker Apr 20, 2022
d7a8d50
Revert markup change that added p element in hgroup
sideshowbarker Apr 20, 2022
5b3e474
several clarifications
stevefaulkner Apr 21, 2022
09e8490
fix linting errors
stevefaulkner Apr 21, 2022
0327b04
Merge branch 'whatwg:main' into outline-reality-reset
stevefaulkner Apr 21, 2022
71cd1d1
remove rank in reference to headings
stevefaulkner Apr 21, 2022
cce4797
WIP Some updates based on code review
stevefaulkner Apr 27, 2022
4b5a5d3
fix linting error
stevefaulkner Apr 27, 2022
91f864c
remove mention of CSS sticky
stevefaulkner Apr 27, 2022
7ac1373
restored hr note
stevefaulkner Apr 27, 2022
0fbbc0d
removed Generic
stevefaulkner Apr 27, 2022
817c59a
replace document headings with outline
stevefaulkner Apr 27, 2022
b2207d3
fix lint error
stevefaulkner Apr 27, 2022
03d27be
added back heading content category
stevefaulkner Apr 27, 2022
b595cbd
Zap trailing whitespace (unbreak CI)
sideshowbarker Apr 28, 2022
5f7ae31
update hgroup content model
stevefaulkner Apr 28, 2022
0c07285
replaced important term
stevefaulkner May 2, 2022
e841164
Minor editorial fixes
domenic May 3, 2022
5543e9c
updated example and svg
stevefaulkner May 4, 2022
0096441
reworked hgroup definition
stevefaulkner May 5, 2022
efbe168
added back header clarification
stevefaulkner May 5, 2022
8c1cb5e
add example
stevefaulkner May 5, 2022
2242b9d
added example
stevefaulkner May 5, 2022
2d0b9bb
removed trailing whitespace
stevefaulkner May 5, 2022
5754ddd
Merge branch 'main' into outline-reality-reset
stevefaulkner May 8, 2022
045cf00
various updates
stevefaulkner May 8, 2022
d07cf54
lint fix
stevefaulkner May 8, 2022
ea5492b
typo fix
stevefaulkner May 8, 2022
559d70b
removed note
stevefaulkner May 8, 2022
052efb0
Minor fixes
domenic Jun 22, 2022
becd7b3
Attempt to fix remaining review comments
domenic Jun 23, 2022
a1b9930
This link no longer seems relevant
domenic Jun 23, 2022
9014ace
Updates from zcorpan's review
domenic Jun 29, 2022
71928c0
Remove "sectioning root" again
domenic Jun 29, 2022
de7ac7b
Add back "Exposing outlines to users"; various example tweaks
domenic Jun 29, 2022
a7004a9
Fix extra "ancestor"
domenic Jun 29, 2022
dd81361
Add missing "None" for td category
domenic Jul 1, 2022
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated headings and sections
used modified text of @annevk PR headings and sections section #3499
  • Loading branch information
stevefaulkner committed Apr 18, 2022
commit e96100f86c66294f7b87432910b6ee9ed5389e10
276 changes: 215 additions & 61 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -17475,97 +17475,251 @@ interface <dfn interface>HTMLHeadingElement</dfn> : <span>HTMLElement</span> {



<h4><dfn>Headings and sections</dfn></h4>
<h4><dfn>Headings and sections</dfn></h4>

<p>The <code>h1</code>&ndash;<code>h6</code> elements are headings.</p>
<p><span>Heading content</span> elements have a <dfn>heading level</dfn>, which is
an unsigned integer. It is determined as follows for a given <span>heading content</span> element
<var>heading</var>:</p>

<p>The first element of <span>heading content</span> in an element of <span>sectioning
content</span> <span>represents</span> the heading for that section. Subsequent headings of equal
or higher <span>rank</span> start new (implied) sections, headings of lower <span>rank</span>
start implied subsections that are part of the previous one. In both cases, the element
<span>represents</span> the heading of the implied section.</p>
<ol>

domenic marked this conversation as resolved.
Show resolved Hide resolved
<li>
<p>Switch on <var>heading</var>:</p>

stevefaulkner marked this conversation as resolved.
Show resolved Hide resolved
<p>Certain elements are said to be <dfn data-x="sectioning root">sectioning roots</dfn>, including
<code>blockquote</code> and <code>td</code> elements. These elements can have their own outlines,
but the sections and headings inside these elements do not contribute to the outlines of their
ancestors.</p>
<dl class="switch">
<dt><code>h2</code></dt>
<dd>Return 2.</dd>

<!-- when updating this also update the category index -->
<ul class="brief category-list">
<li><code>blockquote</code></li>
<li><code>body</code></li>
<li><code>details</code></li>
<li><code>dialog</code></li>
<li><code>fieldset</code></li>
<li><code>figure</code></li>
<li><code>td</code></li>
</ul>
<dt><code>h3</code></dt>
<dd>Return 3.</dd>

<dt><code>h4</code></dt>
<dd>Return 4.</dd>

<dt><code>h5</code></dt>
<dd>Return 5.</dd>

<dt><code>h6</code></dt>
<dd>Return 6.</dd>
</dl>
</li>

</ol>

<p>A <span>heading content</span> element <span>represents</span> a <dfn data-x="concept-heading">heading</dfn>.
The lower a <span data-x="concept-heading">heading</span>'s <span>heading level</span> is, the more important
the <span data-x="concept-heading">heading</span> is.</p>

<p>The <dfn>document headings</dfn> are all <span data-x="concept-heading">headings</span> in a
document, in <span>tree order</span>.</p>

<div w-nodev>

<!-- a document element isn't a sectioning root. This means, for instance, that you don't get an
outline if you just have a random XML file with <html:h1> elements in it. Other vocabs need to
define what their sectioning root is. -->
<p>The <span>document headings</span> must be used for generating document outlines, for
example when generating tables of contents. When creating an interactive table of contents,
entries should jump the user to the relevant <span data-x="concept-heading">heading</span>.</p>
domenic marked this conversation as resolved.
Show resolved Hide resolved

</div>

<p>If a document has a <span data-x="concept-heading">heading</span>, at least a single <span
data-x="concept-heading">heading</span> within <span>document headings</span> must have a
<span>heading level</span> of 1.</p>

<p>Each <span data-x="concept-heading">heading</span> following another <span
data-x="concept-heading">heading</span> <var>lead</var> in <span>document headings</span> must
have a <span>heading level</span> that is less, equal, or 1 greater than <var>lead</var>'s
<span>heading level</span>.</p>
stevefaulkner marked this conversation as resolved.
Show resolved Hide resolved

domenic marked this conversation as resolved.
Show resolved Hide resolved
<p class="note">Authors are encouraged to avoid having a <span>sectioning content</span> element
<var>section</var> without a <span data-x="concept-heading">heading</span> descendant whose
nearest ancestor <span>sectioning content</span> element is not <var>section</var>. I.e., avoid
having a section without a heading.</p>

<div class="example">
<p>The following example is non-conforming:</p>

<p>A document can contain multiple top-level headings:</p>
<pre><code class="html" data-x="">&lt;body&gt;
domenic marked this conversation as resolved.
Show resolved Hide resolved
&lt;h4&gt;Apples&lt;/h4&gt;
&lt;p&gt;Apples are fruit.&lt;/p&gt;
&lt;section&gt;
&lt;h2&gt;Taste&lt;/h2&gt;
&lt;p&gt;They taste lovely.&lt;/p&gt;
&lt;/section&gt;
&lt;/body&gt;</code></pre>

<pre><code class="html">&lt;!DOCTYPE HTML>
&lt;html lang=en>
&lt;title>Alphabetic Fruit&lt;/title>
&lt;h1>Apples&lt;/h1>
&lt;p>Pomaceous.&lt;/p>
&lt;h1>Bananas&lt;/h1>
&lt;p>Edible.&lt;/p>
&lt;h1>Carambola&lt;/h1>
&lt;p>Star.&lt;/p></code></pre>
<p>It could be written as follows and then it would be conforming:</p>

<p>This would form the following simple outline consisting of three top-level sections:</p>
<pre><code class="html" data-x="">&lt;body&gt;
&lt;h1&gt;Apples&lt;/h1&gt;
&lt;p&gt;Apples are fruit.&lt;/p&gt;
&lt;section&gt;
&lt;h2&gt;Taste&lt;/h2&gt;
&lt;p&gt;They taste lovely.&lt;/p&gt;
&lt;/section&gt;
&lt;/body&gt;</code></pre>

</div>

<div class="example">
<p>The following markup fragment:</p>

<pre><code class="html" data-x="">&lt;body>
&lt;hgroup id="document-title">
&lt;h1>HTML&lt;/h1>
&lt;p>Living Standard — Last Updated 12 August 2016&lt;/p>
&lt;/hgroup>
&lt;p>Some intro to the document.&lt;/p>
&lt;h2>Table of contents&lt;/h2>
&lt;ol id=toc>...&lt;/ol>
&lt;h2>First section&lt;/h2>
&lt;p>Some intro to the first section.&lt;/p>
&lt;/body></code></pre>

<p>...results in 3 <span>document headings</span>:</p>

<ol class="brief">
<li> Apples
<li> Bananas
<li> Carambola
<li><p><code data-x="">&lt;hgroup id="document-title">...&lt;/hgroup></code> consisting of <code
data-x="">&lt;h1>HTML&lt;/h1></code> and <code
data-x="">&lt;p>Living Standard — Last Updated 12 August 2016&lt;/p></code>.</p></li>
domenic marked this conversation as resolved.
Show resolved Hide resolved

<li><p><code data-x="">&lt;h2>Table of contents&lt;/h2></code>.</p></li>

<li><p><code data-x="">&lt;h2>First section&lt;/h2></code>.</p></li>
</ol>
domenic marked this conversation as resolved.
Show resolved Hide resolved

<p>Effectively, the <code>body</code> element is split into three.</p>
<p>A rendered view of the <span>document headings</span> might look like:</p>

<p><img src="/images/outline.svg" width="465" height="120" alt="Top-level section with the
heading and associated text &quot;HTML: Living Standard — Last Updated 12 August 2016&quot; and two
subsections; &quot;Table of contents&quot; and &quot;First section&quot;."></p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "should" and not "must"? Are there any valid reasons for using headings but not using a h1?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a document is for a poem without a title and has a section where readers can post comments, than I would not have a <h1>, but use a <h2>Comments</h2> heading for the comments like I would do on any other page.

</div>

<div class="example">
<p>First, here is a document, which is a book with very short chapters and subsections:</p>

<h5>Exposing outlines to users</h5>
<pre><code class="html" data-x="">&lt;!DOCTYPE HTML>
&lt;html lang=en>
&lt;title>The Tax Book (all in one page)&lt;/title>
&lt;h1>The Tax Book&lt;/h1>
&lt;h2>Earning money&lt;/h2>
&lt;p>Earning money is good.&lt;/p>
&lt;h3>Getting a job&lt;/h3>
&lt;p>To earn money you typically need a job.&lt;/p>
&lt;h2>Spending money&lt;/h2>
&lt;p>Spending is what money is mainly used for.&lt;/p>
&lt;h3>Cheap things&lt;/h3>
&lt;p>Buying cheap things often not cost-effective.&lt;/p>
&lt;h3>Expensive things&lt;/h3>
&lt;p>The most expensive thing is often not the most cost-effective either.&lt;/p>
&lt;h2>Investing money&lt;/h2>
&lt;p>You can lend your money to other people.&lt;/p>
&lt;h2>Losing money&lt;/h2>
&lt;p>If you spend money or invest money, sooner or later you will lose money.
&lt;h3>Poor judgement&lt;/h3>
&lt;p>Usually if you lose money it's because you made a mistake.&lt;/p></code></pre>

<p>Its <span>document headings</span> could be presented as follows:</p>

<p>User agents are encouraged to expose page outlines to users to aid in navigation. This is
especially true for non-visual media, e.g. screen readers.</p>
<ol class="brief">
<li> The Tax Book
<ol class="brief">
<li> Earning money
<ol class="brief">
<li> Getting a job
</ol>
<li> Spending money
<ol class="brief">
<li> Cheap things
<li> Expensive things
</ol>
<li> Investing money
<li> Losing money
<ol class="brief">
<li> Poor judgement
</ol>
</ol>
</ol>

<p>However, to mitigate the difficulties that arise from authors misusing <span>sectioning
content</span>, user agents are also encouraged to offer a mode that navigates the page using
<span>heading content</span> alone.</p>
<p>Notice that the <code>title</code> element is not a <span
data-x="concept-heading">heading</span>.</p>
</div>

<div class="example">
<p>A document can contain multiple top-level headings:</p>

<p>For instance, a user agent could map the arrow keys as follows:</p>
<pre><code class="html" data-x="">&lt;!DOCTYPE HTML>
&lt;html lang=en>
&lt;title>Alphabetic Fruit&lt;/title>
&lt;h1>Apples&lt;/h1>
&lt;p>Pomaceous.&lt;/p>
&lt;h1>Bananas&lt;/h1>
&lt;p>Edible.&lt;/p>
&lt;h1>Carambola&lt;/h1>
&lt;p>Star.&lt;/p></code></pre>
</div>

<dl>
<dt><kbd><kbd>Shift</kbd> + <kbd>&larr; Left</kbd></kbd>
<dd>Go to previous section, including subsections of previous sections
<div class="example">
<p>The following example is non-conforming as it has no <span
data-x="concept-heading">heading</span> whose <span>heading level</span> is 1:</p>

<dt><kbd><kbd>Shift</kbd> + <kbd>&rarr; Right</kbd></kbd>
<dd>Go to next section, including subsections of the current section
<pre><code class="html" data-x="">&lt;!DOCTYPE HTML>
&lt;html lang=en>
&lt;title>Alphabetic Fruit&lt;/title>
&lt;section>
&lt;h2>Apples&lt;/h2>
&lt;p>Pomaceous.&lt;/p>
&lt;h2>Bananas&lt;/h2>
&lt;p>Edible.&lt;/p>
&lt;h2>Carambola&lt;/h2>
&lt;p>Star.&lt;/p>
&lt;/section></code></pre>
</div>

<dt><kbd><kbd>Shift</kbd> + <kbd>&uarr; Up</kbd></kbd>
<dd>Go to parent section of the current section
<div class="example">
<p>The following example is non-conforming as the first <span
data-x="concept-heading">heading</span>'s <span>heading level</span> is not 1:</p>

<dt><kbd><kbd>Shift</kbd> + <kbd>&darr; Down</kbd></kbd>
<dd>Go to next section, skipping subsections of the current section
</dl>
<pre><code class="html" data-x="">&lt;!DOCTYPE HTML>
&lt;html lang=en>
&lt;title>Feathers on The Site of Encyclopedic Knowledge&lt;/title>
&lt;h2>A plea from our caretakers&lt;/h2>
&lt;p>Please, we beg of you, send help! We're stuck in the server room!&lt;/p>
&lt;h1>Feathers&lt;/h1>
domenic marked this conversation as resolved.
Show resolved Hide resolved
&lt;p>Epidermal growths.&lt;/p></code></pre>
</div>

<p>Plus in addition, the user agent could map the <kbd><kbd>j</kbd></kbd> and
<kbd><kbd>k</kbd></kbd> keys to navigating to the previous or next element of <span>heading
content</span>, regardless of the section's outline depth and ignoring sections with no
headings.</p>
<div class="example">
<p><code>header</code> elements do not influence the <span>document headings</span> of a
document:</p>

</div>
<pre><code class="html" data-x="">&lt;!DOCTYPE HTML>
&lt;html lang="en">
&lt;title>We're adopting a child! &mdash; Ray's blog&lt;/title>
&lt;h1>Ray's blog&lt;/h1>
&lt;article>
&lt;header>
&lt;nav>
&lt;a href="?t=-1d">Yesterday&lt;/a>;
&lt;a href="?t=-7d">Last week&lt;/a>;
&lt;a href="?t=-1m">Last month&lt;/a>
&lt;/nav>
&lt;h2>We're adopting a child!&lt;/h2>
&lt;/header>
&lt;p>As of today, Janine and I have signed the papers to become
the proud parents of baby Diane! We've been looking forward to
this day for weeks.&lt;/p>
&lt;/article>
&lt;/html></code></pre>

<p>The document's <span>document headings</span> could be presented as follows:</p>

<ol class="brief">
<li> Ray's blog
<ol class="brief">
<li> We're adopting a child!
</ol>
</ol>
</div>


<h4>Usage summary</h4>
Expand Down