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

fix: allows anchor links in local files (enhance regex) #61

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rfineman
Copy link

Modified the regular expression for extracting the local file path and the anchor link.
This should improve the extraction from PR #36.

modify regex extraction of file anchor suffix
@CLAassistant
Copy link

CLAassistant commented Sep 16, 2023

CLA assistant check
All committers have signed the CLA.

@gadenbuie
Copy link
Member

Thanks! Can you please give an example that motivates the change?

@rfineman
Copy link
Author

Sure thing. I'm having an issue creating a png of a leaflet map given the change. mapview::mapshot2 is having the same issue. In order to convert a leaflet map, you first need to saveWidget as a local .html and then convert that resulting file to a .png. However, the new changes to file_url in v0.1.1 provides the wrong file pathway because it's copying the file twice.

Here's an output of a small example.

Create temp file

tmp <- tempfile(fileext = ".html")
writeLines("", tmp)
print(tmp)
[1] "C:\Users\rfineman\AppData\Local\Temp\RtmpQpmNJO\file68f464236dac.html"

File path with current function

webshot_tmp <- webshot2:::file_url(filename = tmp)
print(webshot_tmp)
[1] "file:///C:\Users\rfineman\AppData\Local\Temp\RtmpQpmNJO\file68f464236dac.htmlC:\Users\rfineman\AppData\Local\Temp\RtmpQpmNJO\file68f464236dac.html"
identical(paste0("file:///", tmp), webshot_tmp)
[1] FALSE

File path with revised function

new_webshot_tmp <- new_file_url(filename = tmp)
print(new_webshot_tmp)
[1] "file:///C:\Users\rfineman\AppData\Local\Temp\RtmpQpmNJO\file68f464236dac.html"
identical(paste0("file:///", tmp), new_webshot_tmp)
[1] TRUE

Here's what it looks like with an anchor

webshot_tmp_w_anchor <- webshot2:::file_url(filename = paste0(tmp, "#anchor"))
print(webshot_tmp)
[1] "file:///C:\Users\rfineman\AppData\Local\Temp\RtmpQpmNJO\file68f464236dac.htmlC:\Users\rfineman\AppData\Local\Temp\RtmpQpmNJO\file68f464236dac.html"

new_webshot_tmp_w_anchor <- new_file_url(filename = paste0(tmp, "#anchor"))
print(new_webshot_tmp_w_anchor)
[1] "file:///C:\Users\rfineman\AppData\Local\Temp\RtmpQpmNJO\file68f464236dac.html#anchor"

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.

3 participants