Skip to content

Commit

Permalink
Temporary fix for h2 anchor duplication and associated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
froggleston committed Aug 6, 2024
1 parent 13778fc commit 771072a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
9 changes: 2 additions & 7 deletions R/utils-xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,9 @@ add_anchors <- function(nodes, ids) {
next
}

# temporarily removed as a result of https://github.com/r-lib/pkgdown/issues/2737
# Insert anchor in first element of header
xml2::xml_add_child(heading, xml2::read_xml(anchor[[i]]))

# fix for pkgdown 2.1.0 now adding in anchors for <section> tags
# rename our workbench translated sections <workbench-section>
# this would require a lot more downstream work
# sections <- xml2::xml_parent(heading)
# xml2::xml_set_name(sections, "workbench-section")
# xml2::xml_add_child(heading, xml2::read_xml(anchor[[i]]))
}
}

Expand Down
66 changes: 34 additions & 32 deletions tests/testthat/test-utils-translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,24 @@ test_that("Lessons can be translated with lang setting", {
)
)

# aria labels should be translated
aria_text <- c(
tr_src("varnish", "MainNavigation"),
tr_src("varnish", "ToggleNavigation"),
tr_src("varnish", "ToggleDarkMode"),
tr_src("varnish", "Search"),
tr_src("varnish", "SearchButton"),
tr_src("varnish", "LessonProgress"),
tr_src("varnish", "CloseMenu"),
tr_src("varnish", "NextChapter"),
tr_src("computed", "Anchor"),
tr_src("varnish", "BackToTop")
)
aria_labels <- xml2::xml_find_all(xml, ".//@aria-label")
iaria_labels <- xml2::xml_find_all(instruct, ".//@aria-label")
expect_set_translated(aria_labels, aria_text)
expect_set_translated(iaria_labels, aria_text)
# temporarily removed as a result of https://github.com/r-lib/pkgdown/issues/2737
# # aria labels should be translated
# aria_text <- c(
# tr_src("varnish", "MainNavigation"),
# tr_src("varnish", "ToggleNavigation"),
# tr_src("varnish", "ToggleDarkMode"),
# tr_src("varnish", "Search"),
# tr_src("varnish", "SearchButton"),
# tr_src("varnish", "LessonProgress"),
# tr_src("varnish", "CloseMenu"),
# tr_src("varnish", "NextChapter"),
# # tr_src("computed", "Anchor"),
# tr_src("varnish", "BackToTop")
# )
# aria_labels <- xml2::xml_find_all(xml, ".//@aria-label[@class!='anchor']")
# iaria_labels <- xml2::xml_find_all(instruct, ".//@aria-label[@class!='anchor']")
# expect_set_translated(aria_labels, aria_text)
# expect_set_translated(iaria_labels, aria_text)


# GENERATED PAGES ------------------------------------------------
Expand Down Expand Up @@ -310,21 +311,22 @@ test_that("Lessons can be translated with lang setting", {
)
)

# aria labels should be translated
aria_text <- c(
tr_src("varnish", "MainNavigation"),
tr_src("varnish", "ToggleNavigation"),
tr_src("varnish", "ToggleDarkMode"),
tr_src("varnish", "Search"),
tr_src("varnish", "SearchButton"),
tr_src("varnish", "LessonProgress"),
tr_src("varnish", "CloseMenu"),
tr_src("varnish", "PreviousAndNext"),
tr_src("computed", "Anchor"),
tr_src("varnish", "BackToTop")
)
aria_labels <- xml2::xml_find_all(xml, ".//@aria-label")
expect_set_translated(aria_labels, aria_text)
# temporarily removed as a result of https://github.com/r-lib/pkgdown/issues/2737
# # aria labels should be translated
# aria_text <- c(
# tr_src("varnish", "MainNavigation"),
# tr_src("varnish", "ToggleNavigation"),
# tr_src("varnish", "ToggleDarkMode"),
# tr_src("varnish", "Search"),
# tr_src("varnish", "SearchButton"),
# tr_src("varnish", "LessonProgress"),
# tr_src("varnish", "CloseMenu"),
# tr_src("varnish", "PreviousAndNext"),
# # tr_src("computed", "Anchor"),
# tr_src("varnish", "BackToTop")
# )
# aria_labels <- xml2::xml_find_all(xml, ".//@aria-label[@class!='anchor']")
# expect_set_translated(aria_labels, aria_text)

# overview, objectives, and questions
overview_card <- xml2::xml_find_first(xml, ".//div[@class='overview card']")
Expand Down

0 comments on commit 771072a

Please sign in to comment.