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

"source_code: embed" produces error when concatening strings containing html code #227

Closed
Psqrt opened this issue Jul 27, 2019 · 1 comment · Fixed by #228
Closed

"source_code: embed" produces error when concatening strings containing html code #227

Psqrt opened this issue Jul 27, 2019 · 1 comment · Fixed by #228

Comments

@Psqrt
Copy link

Psqrt commented Jul 27, 2019

Hello,

The following code doesn't work when knitting the dashboard:

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    source_code: embed
---



```{r}
img_url = "https://i.creativecommons.org/l/by-sa/4.0/88x31.png"

img_url_html = paste0("<img src='", img_url, "' height='76'></img>", sep = "")
```

`r img_url_html`

It produces a pandoc error:

File ", img_url, " not found in resource path
Error : pandoc document conversion failed with error 99

However, when I remove source_code: embed, it works fine. The workaround to keep source_code: embed and knit correctly, is to deliberately make a typo in the paste() function so it doesn't recognize html code then fix the typo with some string manipulation functions.

@cderv
Copy link
Collaborator

cderv commented Jul 28, 2019

Hi,

This is an issue because currently html entities from the code are not escaped when inserted inside
<pre class="line-numbers"><code class="language-r">
That is why pandoc interprets <img as an incomplete image tag.

As a workaround you can use R code to create html instead of pasting strings

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    source_code: embed
---



```{r}
img_url = "https://i.creativecommons.org/l/by-sa/4.0/88x31.png"

img_url_html <- htmltools::img(
  src = img_url,
  height = 76
)
```

`r img_url_html`

I will propose a PR to fix as it seems easy.

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.

2 participants