I would like to include content with line breaks in html tables produced by knitr::kable()
. All works well with the default format="markdown"
parameter:
> x <- data.frame(a = "No line break", b = "With line<br>break")
> knitr::kable(x)
|a |b |
|:-------------|:------------------|
|No line break |With line<br>break |
The above correctly appears as a line break in the rendered html
document.
But with format="html"
--which I would prefer to use for other reasons--the <br>
tag is converted to <br>
and then renders in html
as <br>
rather than an actual line break. Is there anything I can do to make it behave as it does with the default format="markdown"
?
> knitr::kable(x, format="html")
<table>
<thead>
<tr>
<th style="text-align:left;"> a </th>
<th style="text-align:left;"> b </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> No line break </td>
<td style="text-align:left;"> With line<br>break </td>
</tr>
</tbody>
</table>
So after being stuck on this for a long time, I discovered just after posting this that the solution is simply to add escape=FALSE
to the example with format="html"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.