rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.74k stars 331 forks source link

shortcode doesn't display with leaflet map in the same post #759

Closed Redcozmo closed 10 months ago

Redcozmo commented 10 months ago

Hi and thanks for blogdown !

My problem is that Hugo shortcodes or theme shortcodes does not execute when leaflet chunk is execute in the same .Rmd file.

I'm using hugo-coder theme : https://github.com/luizdepra/hugo-coder/

In fact, in the above example, when the chunk leaflet is with parameter results='hide', there is no leaflet map (that's ok) and the notice and the shortcode vimeo are well displayed.

But when parameter results='hide' is deleted, the leaflet map is well displayed but the notice and shortcode aren't. They appears exactly as in code.

Reproducible example

---
title: "test-notice-with-leaflet-or-tmap"
---

```{r load_libraries, message=FALSE, results='hide'}
library(sf)
library(dplyr)
library(tmap)
library(leaflet)
library(widgetframe)

A notice from theme hugo-coder

{{< notice warning >}} Test shortcode notice {{< /notice >}}

Shortcode hugo vimeo

{{< vimeo 55073825 >}}

Leaflet...

leaflet() %>%
  addTiles()

### Session info
output from `xfun::session_info('blogdown')`

R version 4.3.2 (2023-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.3 LTS, RStudio 2023.12.0.369

Locale: LC_CTYPE=fr_BE.UTF-8 LC_NUMERIC=C LC_TIME=fr_BE.UTF-8 LC_COLLATE=fr_BE.UTF-8 LC_MONETARY=fr_BE.UTF-8
LC_MESSAGES=fr_BE.UTF-8 LC_PAPER=fr_BE.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
LC_MEASUREMENT=fr_BE.UTF-8 LC_IDENTIFICATION=C

Package version: base64enc_0.1.3 blogdown_1.18 bookdown_0.37 bslib_0.6.1 cachem_1.0.8 cli_3.6.2 digest_0.6.34
ellipsis_0.3.2 evaluate_0.23 fastmap_1.1.1 fontawesome_0.5.2 fs_1.6.3 glue_1.7.0 graphics_4.3.2
grDevices_4.3.2 highr_0.10 htmltools_0.5.7 httpuv_1.6.13 jquerylib_0.1.4 jsonlite_1.8.8 knitr_1.45
later_1.3.2 lifecycle_1.0.4 magrittr_2.0.3 memoise_2.0.1 methods_4.3.2 mime_0.12 promises_1.2.1
R6_2.5.1 rappdirs_0.3.3 Rcpp_1.0.12 rlang_1.1.3 rmarkdown_2.25 sass_0.4.8 servr_0.28
stats_4.3.2 stringi_1.8.3 stringr_1.5.1 tinytex_0.49 tools_4.3.2 utils_4.3.2 vctrs_0.6.5
xfun_0.41 yaml_2.3.8

Hugo version: 0.119.0



### Check site

`[TODO] Set "ignoreFiles" to ["\\.Rmd$", "\\.Rmarkdown$", "_cache$"]`
--> I have exactly this line in `hugo.toml` but comment still remain

`[TODO] Found 6 files marked as drafts. To un-draft, run the command:`
--> I think I can keep it like that...

`[TODO] Found 1 R Markdown file to update by re-rendering:`
--> I execute `blogdown::build_site(build_rmd = 'timestamp')` but comment still remain

Thanks !!
yihui commented 10 months ago

This is a bug of blogdown. Thanks for the report! I'll see what I can do.

A further minimized reprex is:

---
title: "Short code"
---

# A notice

{{< notice warning >}}
Test shortcode notice
{{< /notice >}}

# Shortcode hugo vimeo

{{< vimeo 55073825 >}}

# Raw HTML

```{=html}
<p>a</p>


It's the raw HTML block that caused the problem (HTML widgets like leaflet will generate raw HTML blocks).
yihui commented 10 months ago

Should be fixed now. Thanks! You can install the development version via

remotes::install_github('rstudio/blogdown')
Redcozmo commented 10 months ago

I've try with development version and it's working. Thanks a lot !!

I had solved the problem with this encaption solution (your comment in another issue) : r htmltools::HTML("{{< vimeo 55073825 >}}")

But it's better like that !

yihui commented 10 months ago

Actually you can also wrap the shortcode in a raw HTML block ```{=html}, which should work with any version of blogdown, e.g.,

```{=html}
{{< vimeo 55073825 >}}


This requires extra typing but is a little safer (the shortcode will be preserved when the Markdown file is processed by Pandoc---the Pandoc processing could mangle certain characters in the shortcode).