Skip to content

Commit f91944a

Browse files
authored
Fix invalid HTML5 (#894)
1 parent a1f74d8 commit f91944a

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

src/furo/navigation.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def _get_navigation_expand_image(soup: BeautifulSoup) -> Tag:
9-
retval = soup.new_tag("i", attrs={"class": "icon"})
9+
retval = soup.new_tag("span", attrs={"class": "icon"})
1010

1111
svg_element = soup.new_tag("svg")
1212
svg_use_element = soup.new_tag("use", href="#svg-arrow-right")
@@ -46,6 +46,7 @@ def get_navigation_tree(toctree_html: str) -> str:
4646
# We're gonna add a checkbox.
4747
toctree_checkbox_count += 1
4848
checkbox_name = f"toctree-checkbox-{toctree_checkbox_count}"
49+
accessible_name = f"Toggle navigation of {element.find('a').text}"
4950

5051
# Add the "label" for the checkbox which will get filled.
5152
label = soup.new_tag(
@@ -54,12 +55,6 @@ def get_navigation_tree(toctree_html: str) -> str:
5455
"for": checkbox_name,
5556
},
5657
)
57-
screen_reader_label = soup.new_tag(
58-
"div",
59-
attrs={"class": "visually-hidden"},
60-
)
61-
screen_reader_label.string = f"Toggle navigation of {element.find('a').text}"
62-
label.append(screen_reader_label)
6358
label.append(_get_navigation_expand_image(soup))
6459

6560
element.insert(1, label)
@@ -73,6 +68,7 @@ def get_navigation_tree(toctree_html: str) -> str:
7368
"id": checkbox_name,
7469
"name": checkbox_name,
7570
"role": "switch",
71+
"aria-label": accessible_name,
7672
},
7773
)
7874
# if this has a "current" class, be expanded by default (by checking the checkbox)

src/furo/theme/furo/page.html

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
{{ super() }}
55
{% include "partials/icons.html" %}
66

7-
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
8-
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
9-
<label class="overlay sidebar-overlay" for="__navigation">
10-
<div class="visually-hidden">Hide navigation sidebar</div>
11-
</label>
12-
<label class="overlay toc-overlay" for="__toc">
13-
<div class="visually-hidden">Hide table of contents sidebar</div>
14-
</label>
7+
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation" aria-label="Toggle site navigation sidebar">
8+
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc" aria-label="Toggle table of contents sidebar">
9+
<label class="overlay sidebar-overlay" for="__navigation"></label>
10+
<label class="overlay toc-overlay" for="__toc"></label>
1511

1612
<a class="skip-to-content muted-link" href="#furo-main-content">
1713
{%- trans -%}
@@ -31,26 +27,23 @@
3127
<header class="mobile-header">
3228
<div class="header-left">
3329
<label class="nav-overlay-icon" for="__navigation">
34-
<div class="visually-hidden">Toggle site navigation sidebar</div>
35-
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
30+
<span class="icon"><svg><use href="#svg-menu"></use></svg></span>
3631
</label>
3732
</div>
3833
<div class="header-center">
3934
<a href="{{ pathto(master_doc) }}"><div class="brand">{{ docstitle if docstitle else project }}</div></a>
4035
</div>
4136
<div class="header-right">
4237
<div class="theme-toggle-container theme-toggle-header">
43-
<button class="theme-toggle">
44-
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
38+
<button class="theme-toggle" aria-label="Toggle Light / Dark / Auto color theme">
4539
<svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
4640
<svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
4741
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
4842
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
4943
</button>
5044
</div>
5145
<label class="toc-overlay-icon toc-header-icon{% if furo_hide_toc %} no-toc{% endif %}" for="__toc">
52-
<div class="visually-hidden">Toggle table of contents sidebar</div>
53-
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
46+
<span class="icon"><svg><use href="#svg-toc"></use></svg></span>
5447
</label>
5548
</div>
5649
</header>
@@ -103,17 +96,15 @@
10396
{%- endfor -%}
10497
{#- Theme toggle -#}
10598
<div class="theme-toggle-container theme-toggle-content">
106-
<button class="theme-toggle">
107-
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
99+
<button class="theme-toggle" aria-label="Toggle Light / Dark / Auto color theme">
108100
<svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
109101
<svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
110102
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
111103
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
112104
</button>
113105
</div>
114106
<label class="toc-overlay-icon toc-content-icon{% if furo_hide_toc %} no-toc{% endif %}" for="__toc">
115-
<div class="visually-hidden">Toggle table of contents sidebar</div>
116-
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
107+
<span class="icon"><svg><use href="#svg-toc"></use></svg></span>
117108
</label>
118109
</div>
119110
<article role="main" id="furo-main-content">

0 commit comments

Comments
 (0)