Skip to content

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

Open
@mrcaseb

Description

@mrcaseb

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)<!-- -->

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions