user3408956
user3408956

Reputation: 53

escaping raw html in rmarkdown

In R Markdown, with html output, I want to use the following raw HTML code, together with some R Markdown code to include an image in a grid.

The HTML code starting with "<" appears to propagate to HTML output without problems. However, HTML code such as "::before" gets converted to <p>::before</p> which is not what I want.

How can I specify to R Markdown that I want to 'escape' certain pieces of code, such as "::before" and "::after", preventing the automatic encapsulation of them in <p> tags?

<div class = "row", id = "abc">
::before
<div class = "col-md-4">
![](images/logo.png){ style="height: 70px"}
</div>
::after
</div>

Upvotes: 0

Views: 704

Answers (1)

user2554330
user2554330

Reputation: 44788

You can output those parts of your code using knitr::raw_html(). For your example, the middle line is Markdown, not HTML, so you'd want:

```{r echo=FALSE}
knitr::raw_html(
'<div class = "row", id = "abc">
::before
<div class = "col-md-4">')
```
![](images/logo.png){ style="height: 70px"}
```{r echo=FALSE}
knitr::raw_html(
'</div>
::after
</div>')
```

Upvotes: 3

Related Questions