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

Improve HTML5 compliance #2523

Merged
merged 7 commits into from
May 14, 2024
Merged

Improve HTML5 compliance #2523

merged 7 commits into from
May 14, 2024

Conversation

hadley
Copy link
Member

@hadley hadley commented May 9, 2024

Fixes #2369

Remaining issues:

  • No inline styles: this comes from the posit logo which has some manual margin added. If we decided to fix this, it would need to happen in tidytemplate
  • Anchor link must have text describing its purpose: this is because we explicitly ask pandoc to generate html4. Working on this now.
  • <form> element must have a submit button: would be nice to fix this, but I don't see how.

@hadley hadley requested a review from maelle May 9, 2024 13:29
Copy link

github-actions bot commented May 9, 2024

Copy link
Collaborator

@maelle maelle left a comment

Choose a reason for hiding this comment

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

🙏

inst/BS5/templates/content-title-body.html Outdated Show resolved Hide resolved
inst/BS5/templates/navbar.html Outdated Show resolved Hide resolved
@hadley hadley requested a review from maelle May 10, 2024 15:45
@hadley
Copy link
Member Author

hadley commented May 10, 2024

@maelle this needs another review because it substantially expanded in scope. I think we discussed doing this before (but I decided it would be too much work?), but we're now telling pandoc to generate html5 output. This changes the generated HTML so there's some risk that we are no longer transforming it correctly, and because our snapshot tests tend to use canned HTML, it might look like everything is ok even though it's no longer translating the new HTML. I think the biggest culprit is likely to be the change from <div class="section"> to <section>, but there might be other changes I didn't think about.

R/build-news.R Outdated Show resolved Hide resolved
R/navbar.R Show resolved Hide resolved
classes <- strsplit(x$icon, " ")[[1]]
icon_classes <- classes[grepl("-", classes)]
iconset <- purrr::map_chr(strsplit(icon_classes, "-"), 1)
class <- paste0(unique(c(iconset, classes)), collapse = " ")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why `paste0()?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just use it everywhere so I don't have to remember

R/tweak-tabset.R Outdated
@@ -81,7 +81,7 @@ tablist_title <- function(tab) {

# Add content of a tab to a tabset
tablist_content <- function(tab, content, parent_id, fade) {
id <- section_id(tab)
id <- xml2::xml_attr(tab, "id")
Copy link
Collaborator

Choose a reason for hiding this comment

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

if id is an attribute we often ask why not have a helper? today I saw https://github.com/lionel-/codegrip/blob/82d164ed91ad819587796a4053b1df5b0385c677/R/ast.R#L51, it looked nice

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO that would generally conceal the purpose of the code more than it reveals it. section_id() was only need before because it was relatively complicated to figure out the id.

@@ -20,7 +20,7 @@ <h1>{{{pagetitle}}}</h1>
</main>

<aside class="col-md-3">
<nav id="toc">
<nav id="toc" aria-label="Table of contents">
Copy link
Collaborator

Choose a reason for hiding this comment

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

when I switch from R scripts to HTML files in the diff, the first equal sign I see without space before and after makes me jump!

Copy link
Member Author

Choose a reason for hiding this comment

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

Hahaha. Also this should be translated too!

{
"path": ["/dev/index.html"],
"id": ["testpackage"],
"id": [null],
Copy link
Collaborator

Choose a reason for hiding this comment

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

why

@@ -279,12 +279,14 @@ build_article <- function(name,
# Override defaults & values supplied in metadata
options <- list(
template = template$path,
self_contained = FALSE
self_contained = FALSE,
pandoc_args = c("-t", "html5")
Copy link
Contributor

Choose a reason for hiding this comment

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

About this html5 format, doing it like this will work, but only because pandoc accept two --to arguments, and use the last one. This could be fragile.

Moreover, doing this with an argument like this does not change the internal knitr option that store the output format for some processing in knitr context (knitr::pandoc_to())

So, as you are calling

output <- rmarkdown::default_output_format(input_path) 

maybe this is safer to overwrite the to information there

output$pandoc$to <- "html5"

This way you are really overwriting the format to change the pandoc to value.

@hadley
Copy link
Member Author

hadley commented May 14, 2024

I found a bunch more code that I need to update, and I'm beginning to think that switching pandoc to produce isn't a good idea, because I think there's substantial risk of it breaking BS3 sites (I don't really want to mess with the BS3 templates, but I also don't want to maintain two versions of all the tweak scripts, and we have relatively little test coverage of BS3 now). So I'm going to roll back to just the first two commits here, and start the deprecation for BS3 sites. Then we can try again after BS3 is gone.

@hadley hadley merged commit cf719ba into main May 14, 2024
13 checks passed
@hadley hadley deleted the html5 branch May 14, 2024 20:06
SebKrantz pushed a commit to SebKrantz/pkgdown that referenced this pull request Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run html-validate on docs/ to find problems to fix?
3 participants