-
I am writing a function that can be called several times within one code chunk. It takes constructed HTML and wraps it in
These extra lines are appearing verbatim in the finished 🆕 I think the constructed HTML that triggers the problem contains Any ideas what is causing this and how to prevent it? Thanks in advance. The little function that calls
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Those lines are not yaml. That's a markdown div, and it's generated (on purpose) if your cell doesn't contain That markdown div should be getting converted to a div by Pandoc. Have you tried wrapping your raw HTML in
instead of simply emitting the HTML output? |
Beta Was this translation helpful? Give feedback.
-
I am adding context based on the discussion and solution I am seing above. You shared your function was rendHTML <- function(x) {
x <- paste0('\n', paste(x, collapse='\n'), '\n')
if(length(getOption('knitr.in.progress'))) {
return(knitr::asis_output(x))
}
print(htmltools::browsable(htmltools::HTML(x)))
} I believe the existing HTML and R Markdown toolchain can do the right think for you without needing to add the raw attribute yourself and all like solution above. Doing the following should work ok in knitr rendHTML <- function(x) {
x <- paste0('\n', paste(x, collapse='\n'), '\n')
htmltools::browsable(htmltools::HTML(x))
} When a code is run in knitting, the output will be processed by some specific htmltools defines a
So you should not need anything specific than using htmltools . Also FWIW, there is a Try that ---
title: raw HTML
format: html
---
```{r}
rendHTML <- function(x) {
x <- paste0('\n', paste(x, collapse='\n'), '\n')
htmltools::browsable(htmltools::HTML(x))
}
```
```{r}
rendHTML("<div>\ncontent\n</div>")
``` Hope it helps understand how this works |
Beta Was this translation helpful? Give feedback.
Those lines are not yaml. That's a markdown div, and it's generated (on purpose) if your cell doesn't contain
results='asis'
.That markdown div should be getting converted to a div by Pandoc. Have you tried wrapping your raw HTML in
instead of simply emitting the HTML output?