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

simplify_image_links() fails to simplify because of unexpected html comment strings #473

Open
mrcaseb opened this issue Nov 19, 2024 · 0 comments · May be fixed by #474
Open

simplify_image_links() fails to simplify because of unexpected html comment strings #473

mrcaseb opened this issue Nov 19, 2024 · 0 comments · May be fixed by #474

Comments

@mrcaseb
Copy link

mrcaseb commented Nov 19, 2024

The function that is supposed to simplify the image strings expects strings of the form ![](https://i.imgur.com/woc4vHs.png).

reprex/R/reprex_render.R

Lines 335 to 339 in 07cd5d7

# input: ![](https://i.imgur.com/woc4vHs.png)
# output: https://i.imgur.com/woc4vHs.png
simplify_image_links <- function(x) {
sub("(^!\\[\\]\\()(.+)(\\)$)", "\\2", x, perl = TRUE)
}

If this was the input, the code would work fine

x <- "![](https://i.imgur.com/woc4vHs.png)"
sub("(^!\\[\\]\\()(.+)(\\)$)", "\\2", x, perl = TRUE)
#> [1] "https://i.imgur.com/woc4vHs.png"

However, the actual input includes empty html strings and has the form ![](https://i.imgur.com/woc4vHs.png)<!-- -->

In this case, the function fails to simplify the link

x <- "![](https://i.imgur.com/woc4vHs.png)<!-- -->"
sub("(^!\\[\\]\\()(.+)(\\)$)", "\\2", x, perl = TRUE)
#> [1] "![](https://i.imgur.com/woc4vHs.png)<!-- -->"

The result is that links aren't simplified when doing reprex(venue = "slack") as the below example shows (I put the image link in backticks)

library(ggplot2)
ggplot(mtcars, aes(disp, qsec)) +
  geom_point()

![](https://i.imgur.com/9hBJEWw.png)<!-- -->

mrcaseb added a commit to mrcaseb/reprex that referenced this issue Nov 19, 2024
@mrcaseb mrcaseb linked a pull request Nov 19, 2024 that will close this issue
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 a pull request may close this issue.

1 participant