rr-markdownhugoblogdownhugo-shortcode

Image via shortcode in RMarkdown using blogdown not showing up


I want to display images via shortcode in a RMarkdown file using blogdown. I use the code:

```{r echo=FALSE}
blogdown::shortcode("figure", src = "/img/to/path/my-picture.png", alt = "Some alt text")
```

I get no error message, just an empty space on the website. The picture is not displayed. Shortcode is generally working, I tried it with a twitter card.

The path is correct as the same picture is displayed with knitr. (The path also works as shortcode in a normal .md document.) If I do not use the alt parameter in my .Rmd file, then the code of the shortcode command is displayed on the website -- Not only for this command but for all other (formerly working) shortcodes as well. I got, for instance, the following web page snippet:

{{% figure src=/img/to/path/my-picture.png %}}
But shortcode works, here is a tweet card: {{% tweet 852205086956818432 %}}

Another issue related to figures: If I am using the standard command:

![some alt text](/img/to/path/my-picture.png)

the web page displays the alt text "some alt text" under the picture.

I am using the hugo-academic theme and here is my session info:

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12    bookdown_0.5    digest_0.6.12   rprojroot_1.2   mime_0.5        backports_1.1.0
 [7] magrittr_1.5    evaluate_0.10.1 blogdown_0.1    stringi_1.1.5   rmarkdown_1.6   tools_3.4.1    
[13] servr_0.7       stringr_1.2.0   httpuv_1.3.5    yaml_2.1.14     compiler_3.4.1  htmltools_0.3.6
[19] knitr_1.17 

Solution

  • I was able to recreate this issue with a different theme (Beautiful Hugo). It looked like the blogdown function was stripping the quotes from the src. I was able to fix it by enclosing the quotes in single quotes.

    blogdown::shortcode("figure", src = '"/img/to/path/my-picture.png"', alt = "Some alt text")