Skip to content

Commit cc1a12c

Browse files
committed
Add heading id automatically
And treat table captions as headings
1 parent 36be7a4 commit cc1a12c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

assets/js/customElements/enhanced-navigation.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ customElements.define('enhanced-navigation', class extends HTMLElement {
2323
const liTemplate = navItemsTemplates.querySelector('li');
2424

2525
const article = this.querySelector('article');
26-
const headings = article.querySelectorAll('h2');
27-
const items = Array.from(headings, (headingEl) => {
26+
const headings = article.querySelectorAll('h2, table caption');
27+
const items = Array.from(headings, (headingEl, index) => {
28+
if (!headingEl.id) {
29+
headingEl.id = article.id + "-" + index;
30+
}
2831
return El(liTemplate, {}, El(linkTemplate, { href: '#' + headingEl.id }, headingEl.innerText));
2932
});
3033

lib/components_guide_web/templates/accessibility_first/index.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="md:sticky top-0 md:h-screen pl-4 pt-16 text-white">
44
<%= render view_module(@conn), "_nav.html", conn: @conn %>
55
</div>
6-
<article class="text-white bg-gray-900 px-4 md:px-0">
6+
<article class="text-white bg-gray-900 px-4 md:px-0" id="main-article">
77
<div class="prose md:prose-xl prose-invert max-w-4xl mx-auto py-16">
88
<%= render(view_module(@conn), @article <> ".html", conn: @conn) %>
99
</div>

0 commit comments

Comments
 (0)