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

Tweak source srcrefs #2474

Merged
merged 2 commits into from
Apr 19, 2024
Merged

Tweak source srcrefs #2474

merged 2 commits into from
Apr 19, 2024

Conversation

hadley
Copy link
Member

@hadley hadley commented Apr 18, 2024

Fixes #2402

@yjunechoe does this work for you?

@yjunechoe
Copy link

Yes - thanks for picking up on this!

I got stuck trying a harder problem narrowly targeting just the <source> siblings of the <img>s that were previously targets of url redirecting - in theory doable but I realized that there's a quirk where {xml2} does not auto close <source> (vs. <source/>) tags, which made it difficult for my particular case where this happens.

But this general solution in the PR works great!

The xml parsing behavior in question

Just for reference in case this comes up in the future:

library(xml2)

# Not self-closing source tags
x <- '
<picture>
  <source>
  <source>
  <img/>
</picture>
'

x |>
  read_html() |>
  xml_structure()
#> <html>
#>   <body>
#>     <picture>
#>       <source>
#>         <source>
#>           <img>

@hadley
Copy link
Member Author

hadley commented Apr 19, 2024

@yjunechoe that behaviour is probably because the HTML parsing code in libxml2 is out of date and doesn't know about the latest in self-closing tags 😬

@hadley hadley merged commit 53a4906 into main Apr 19, 2024
12 checks passed
@hadley hadley deleted the tweak-source-urls branch April 19, 2024 16:04
SebKrantz pushed a commit to SebKrantz/pkgdown that referenced this pull request Jun 1, 2024
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 this pull request may close these issues.

Target <source srcset="..."> for redirecting figures
2 participants