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

Add body tag when reading HTML fragment for homepage creation? #2060

Closed
maelle opened this issue Mar 17, 2022 · 3 comments · Fixed by #2220
Closed

Add body tag when reading HTML fragment for homepage creation? #2060

maelle opened this issue Mar 17, 2022 · 3 comments · Fixed by #2220
Labels
bug an unexpected problem or unintended behavior front end 🌷 General HTML, CSS, and JS issues
Milestone

Comments

@maelle
Copy link
Collaborator

maelle commented Mar 17, 2022

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

@hadley hadley added bug an unexpected problem or unintended behavior front end 🌷 General HTML, CSS, and JS issues labels May 31, 2022
@maelle maelle modified the milestones: 2.1.0, 2.0.7 Oct 20, 2022
@maelle
Copy link
Collaborator Author

maelle commented Oct 21, 2022

Mmmh that was not the right diagnostic. Maybe more due to how comments are integrated, will try fixing the XPath.

@maelle
Copy link
Collaborator Author

maelle commented Oct 21, 2022

oh maybe I meant earlier in the build process.

@maelle
Copy link
Collaborator Author

maelle commented Oct 21, 2022

however, instead of tweaking at the stage of convert_markdown_to_html(), maybe it's best to add yet another XPath query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior front end 🌷 General HTML, CSS, and JS issues
Projects
None yet
2 participants