Skip to content

Commit 31b5d70

Browse files
committed
Improve HTML5 compliance
Fixes #2369
1 parent 3e320c8 commit 31b5d70

16 files changed

+32
-36
lines changed

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# pkgdown (development version)
22

3+
* Improve HTML5 compliance (#2369):
4+
* No longer support IE9 or earlier
5+
* Strip trailing whitespace
6+
* Label `<nav>`s and improve navbar html.
37
* `build_reference()` now supports `\Sexpr[results=verbatim]` (@bastistician, #2510).
48
* `build_home()` no longer checks if the README is missing any images. This check is now performed in `build_site()`, after `build_articles()` so you can refer to images created by vignettes with warnings (#2194).
59
* `build_home()` now includes the contents of `inst/AUTHORS` on the authors page (#2506).

R/navbar.R

+12-18
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,16 @@ bs4_navbar_links_tags <- function(links, depth = 0L, side = "left") {
272272
return(
273273
htmltools::tags$li(
274274
class = menu_class,
275-
htmltools::tags$a(
276-
href = "#", class = "nav-link dropdown-toggle",
277-
`data-bs-toggle` = "dropdown", role = "button",
278-
`aria-expanded` = "false", `aria-haspopup` = "true",
275+
htmltools::tags$button(
276+
href = "#",
277+
class = "nav-link dropdown-toggle",
278+
`data-bs-toggle` = "dropdown",
279+
type = "button",
280+
`aria-expanded` = "false",
281+
`aria-haspopup` = "true",
279282
link_text,
280283
id = paste0("dropdown-", make_slug(link_text)),
281-
"aria-label" = x$`aria-label` %||% NULL
284+
"aria-label" = x$`aria-label` %||% NULL
282285
),
283286
htmltools::tags$div(
284287
class = dropdown_class,
@@ -334,24 +337,15 @@ bs4_navbar_links_tags <- function(links, depth = 0L, side = "left") {
334337

335338
tags <- purrr::map2(links, seq_along(links), tackle_link, is_submenu = is_submenu, depth = depth)
336339
htmltools::tagList(tags)
337-
338340
}
339341

340342
bs4_navbar_link_text <- function(x, ...) {
341-
342343
if (!is.null(x$icon)) {
343-
# find the iconset
344-
split <- strsplit(x$icon, "-")
345-
if (length(split[[1]]) > 1) {
346-
iconset <- split[[1]][[1]]
347-
}
348-
else {
349-
iconset <- ""
350-
}
351-
htmltools::tagList(htmltools::tags$span(class = paste(iconset, x$icon)), " ", x$text, ...)
352-
}
353-
else
344+
text <- paste0(if (!is.null(x$text)) " ", x$text)
345+
htmltools::tagList(htmltools::tags$span(class = x$icon), text, ...)
346+
} else {
354347
htmltools::tagList(x$text, ...)
348+
}
355349
}
356350

357351
# Testing helpers ---------------------------------------------------------

R/render.R

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ render_page_html <- function(pkg, name, data = list(), depth = 0L) {
6363
template <- find_template("layout", name, pkg = pkg)
6464
rendered <- render_template(template, components)
6565

66+
# Strip trailing whitespace
67+
rendered <- gsub("\\s+\n", "\n", rendered, perl = TRUE)
68+
6669
xml2::read_html(rendered, encoding = "UTF-8")
6770
}
6871

inst/BS5/templates/content-article-index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h3>{{{title}}}</h3>
2121
</main>
2222

2323
<aside class="col-md-3">
24-
<nav id="toc">
24+
<nav id="toc" aria-label="Table of contents">
2525
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
2626
</nav>
2727
</aside>

inst/BS5/templates/content-article.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h4 data-toc-skip class="date">$date$</h4>
4848
</main>
4949
{{#toc}}
5050
<aside class="col-md-3">
51-
<nav id="toc">
51+
<nav id="toc" aria-label="Table of contents">
5252
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
5353
</nav>
5454
</aside>

inst/BS5/templates/content-authors.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h1>{{{pagetitle}}}</h1>
2020
</main>
2121

2222
<aside class="col-md-3">
23-
<nav id="toc">
23+
<nav id="toc" aria-label="Table of contents">
2424
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
2525
</nav>
2626
</aside>

inst/BS5/templates/content-citation-authors.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h2>{{#translate}}{{author_details}}{{/translate}}</h2>
3838
</main>
3939

4040
<aside class="col-md-3">
41-
<nav id="toc">
41+
<nav id="toc" aria-label="Table of contents">
4242
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
4343
</nav>
4444
</aside>

inst/BS5/templates/content-news-index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h1>{{{pagetitle}}}</h1>
1212
</main>
1313

1414
<aside class="col-md-3">
15-
<nav id="toc">
15+
<nav id="toc" aria-label="Table of contents">
1616
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
1717
</nav>
1818
</aside>

inst/BS5/templates/content-news.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h1>{{{pagetitle}}}</h1>
1212
</main>
1313

1414
<aside class="col-md-3">
15-
<nav id="toc">
15+
<nav id="toc" aria-label="Table of contents">
1616
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
1717
</nav>
1818
</aside>

inst/BS5/templates/content-reference-index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h1>{{{pagetitle}}}</h1>
66
</div>
77

8-
{{#rows}}<div id="{{slug}}" class="section level2">
8+
{{#rows}}<div {{#slug}}id="{{.}}"{{/slug}} class="section level2">
99
{{#title}}<h2>{{{.}}}</h2>{{/title}}
1010
{{#subtitle}}<h3>{{{.}}}</h3>{{/subtitle}}
1111
{{#desc}}<div class="section-desc">{{{desc}}}</div>{{/desc}}
@@ -21,7 +21,7 @@ <h1>{{{pagetitle}}}</h1>
2121
</main>
2222

2323
<aside class="col-md-3">
24-
<nav id="toc">
24+
<nav id="toc" aria-label="Table of contents">
2525
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
2626
</nav>
2727
</aside>

inst/BS5/templates/content-reference-topic.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h2>{{#translate}}{{examples}}{{/translate}}</h2>
4141
{{/examples}}
4242
</main>
4343
<aside class="col-md-3">
44-
<nav id="toc">
44+
<nav id="toc" aria-label="Table of contents">
4545
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
4646
</nav>
4747
</aside>

inst/BS5/templates/content-title-body.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1>{{pagetitle}}</h1>
1111
</main>
1212

1313
<aside class="col-md-3">
14-
<nav id="toc">
14+
<nav id="toc" aria-label="Table of contents">
1515
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
1616
</nav>
1717
</aside>

inst/BS5/templates/content-tutorial-index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h1>{{{pagetitle}}}</h1>
1313
</main>
1414

1515
<aside class="col-md-3">
16-
<nav id="toc">
16+
<nav id="toc" aria-label="Table of contents">
1717
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
1818
</nav>
1919
</aside>

inst/BS5/templates/content-tutorial.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h1>{{pagetitle}}</h1>
55
</div>
66
</main>
77
<aside class="col-md-3">
8-
<nav id="toc">
8+
<nav id="toc" aria-label="Table of contents">
99
<h2>{{#translate}}{{on_this_page}}{{/translate}}</h2>
1010
</nav>
1111
</aside>

inst/BS5/templates/head.html

-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@
8484
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
8585
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
8686

87-
<!--[if lt IE 9]>
88-
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
89-
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
90-
<![endif]-->
91-
9287
{{#yaml}}{{#ganalytics}}
9388
<!-- Global site tag (gtag.js) - Google Analytics -->
9489
<script async src="https://www.googletagmanager.com/gtag/js?id={{.}}"></script>

inst/BS5/templates/navbar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{#navbar}}
2-
<nav class="navbar fixed-top navbar-{{{type}}} navbar-expand-lg bg-{{{bg}}}" data-bs-theme="{{{type}}}">
2+
<nav class="navbar fixed-top navbar-{{{type}}} navbar-expand-lg bg-{{{bg}}}" data-bs-theme="{{{type}}}" aria-label="Site navigation">
33
<div class="container">
44
{{#includes}}{{{before_title}}}{{/includes}}
55
<a class="navbar-brand me-2" href="{{#site}}{{root}}{{/site}}index.html">{{#site}}{{title}}{{/site}}</a>

0 commit comments

Comments
 (0)