pkgdown
pkgdown copied to clipboard
Add body tag when reading HTML fragment for homepage creation?
Problem: a badges paragraph right at the beginning of a README.md doesn't get recognized.
Why: in markdown_path_html(), xml2::read_html() loses the first comment as it's read as if it were outside of the body.
A fix might be to wrap the HTML string into <body></body>.
xml2::read_html(
'<!-- badges: start -->
<p><a href="https://github.com/ropensci/occCite/actions"><img src="https://github.com/ropensci/occCite/workflows/R-CMD-check/badge.svg" alt="R build status" /></a>
<!-- badges: end -->'
) |> as.character()
#> [1] "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<!-- badges: start --><html><body><p><a href=\"https://github.com/ropensci/occCite/actions\"><img src=\"https://github.com/ropensci/occCite/workflows/R-CMD-check/badge.svg\" alt=\"R build status\"></a>\n<!-- badges: end --></p></body></html>\n"
xml2::read_html(
'<body><!-- badges: start -->
<p><a href="https://github.com/ropensci/occCite/actions"><img src="https://github.com/ropensci/occCite/workflows/R-CMD-check/badge.svg" alt="R build status" /></a>
<!-- badges: end --></body>'
) |> as.character()
#> [1] "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>\n<!-- badges: start -->\n<p><a href=\"https://github.com/ropensci/occCite/actions\"><img src=\"https://github.com/ropensci/occCite/workflows/R-CMD-check/badge.svg\" alt=\"R build status\"></a>\n<!-- badges: end --></p>\n</body></html>\n"
Created on 2022-03-17 by the reprex package (v2.0.1)
(A workaround is to put the badges paragraph after the heading)
Cc @hannahlowens