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

setup links with fragments do not point to correct fragments in website #521

Closed
zkamvar opened this issue Sep 22, 2023 · 0 comments · Fixed by #522
Closed

setup links with fragments do not point to correct fragments in website #521

zkamvar opened this issue Sep 22, 2023 · 0 comments · Fixed by #522

Comments

@zkamvar
Copy link
Contributor

zkamvar commented Sep 22, 2023

N.B. this comes from carpentries/sandpaper-docs#164, where it has the best examples.

I was a bit confused by what this meant, but I think @fnattino gave a good description in carpentries/sandpaper-docs#164, and it's definitely a bug (you would, as the author, expect to be able to link to a subsection of the setup)

I believe this is coming from fix_setup_link() in R/utils-xml.R

The function replaces any occurance of setup.html with index.html#setup, but neglects the fragment (everything after the #). It could be modified like so:

 fix_setup_link <- function(nodes = NULL) {
   if (length(nodes) == 0) return(nodes)
   links <- xml2::xml_find_all(nodes, ".//a")
   hrefs <- xml2::url_parse(xml2::xml_attr(links, "href"))
   setup_links <- hrefs$scheme == "" &
     hrefs$server == "" &
     hrefs$path == "setup.html"
+  section_ids <- hrefs$fragment[setup_links] 
+  section_ids[section_ids == ""] <- "setup"
+  replacement <- paste0("index.html#", section_ids)
+  xml2::xml_set_attr(links[setup_links], "href", replacement)
-  xml2::xml_set_attr(links[setup_links], "href", "index.html#setup")
   invisible(nodes)
}

Originally posted by @zkamvar in carpentries/workbench#70 (comment)

@zkamvar zkamvar transferred this issue from carpentries/workbench Sep 22, 2023
zkamvar added a commit that referenced this issue Sep 22, 2023
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 a pull request may close this issue.

1 participant