4

In a .rmd file (output type = html document), I'm trying to render a HTML string containing a backtick (``) in a r code block, like in the following example:

```{r}
htmltools::HTML('<b>LEFT`RIGHT</b>')
```

When I try to knit this, I get the following output: The HTML string is not rendered correctly

Instead, I want to display LEFT`RIGHT. How do I do it?

I am aware that in this simple case I could just include the HTML in the .rmd instead of passing it to htmltools::HTML inside a code block, but for my actual use case, the HTML is inside a parameter, i.e. instead of HTML('<b>LEFT``RIGHT</b>') I have the parameter params$query, which i pass to the .rmd file via rmarkdown::render. Therefore it has to be included in a r code block to be parsed.

  • 2
    Try with replacing the backtick by its HTML entity `&grave;`, i.e. `htmltools::HTML('LEFT&grave;RIGHT')`. See [How to display verbatim inline r code with backticks using Rmarkdown?](https://stackoverflow.com/questions/20409172/how-to-display-verbatim-inline-r-code-with-backticks-using-rmarkdown) – stefan Dec 28 '21 at 18:22
  • 2
    @stefan, this works. Thanks a lot! If you would be willing to reply I could accept your answer. I had seen that question but `&grave;` is only mentioned in one of the bottom answers so I missed it. – un umile appassionato Dec 28 '21 at 18:34
  • 1
    Great. I would feel bad about posting as an answer as I simply picked it from the linked post. Personally I would therefore call it a duplicate even if not a perfect one. Maybe someone else has an opinion on that. (: – stefan Dec 28 '21 at 18:43

0 Answers0