Skip to content

Commit

Permalink
Fix for pkgdown 2.1.0 adding anchors to sections
Browse files Browse the repository at this point in the history
  • Loading branch information
froggleston committed Jul 29, 2024
1 parent ca752ed commit 1b76bd7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/utils-xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,22 @@ add_anchors <- function(nodes, ids) {
anchor <- paste0(
"<a class='anchor' aria-label='", tranchor, "' href='#", ids, "'></a>"
)

for (i in seq_along(nodes)) {
heading <- nodes[[i]]

if (length(xml2::xml_contents(heading)) == 0) {
# skip empty headings
next
}

# 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>
sections <- xml2::xml_parent(heading)
xml2::xml_set_name(sections, "workbench-section")
}
}

Expand Down

0 comments on commit 1b76bd7

Please sign in to comment.