How do I prevent output: asis
chunks from modifying htmltools
outputs?
#7614
-
DescriptionThis is related to #7600. I'm pretty confused why ```{r}
#| echo: false
#| output: asis
htmltools::div(
htmltools::a('Some link')
) |> as.character() |> cat(sep = "\n")
``` The output from this chunk (if executed in R in the console) is
But once I render in Quarto I get
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Can you provide a full example of your input to quarto? Thank you. |
Beta Was this translation helpful? Give feedback.
-
What's happening here is that Pandoc doesn't like
If you need your HTML output to be unprocessed by Pandoc, you need to emit a raw block. I don't know the htmltools syntax to do it, but
produces
which then is unprocessed by Pandoc. |
Beta Was this translation helpful? Give feedback.
-
This should be as simple as that to use knitr and htmltools to produce HTML content ---
title: "test"
format: html
keep-md: true
---
```{r}
#| echo: false
#| output: asis
htmltools::div(
htmltools::a('Some link')
)
```
htmltools + knitr takes care for you about all the thing you need to do to print the right markdown. ---
title: "test"
format: html
keep-md: true
---
::: {.cell-output-display}
```{=html}
<div>
<a>Some link</a>
</div>
```
:::
(and as said, the So no need of That is to me the right way to do that. Does it work for you correctly ? Did you try it ? If not working, which version of the tools are you using ? |
Beta Was this translation helpful? Give feedback.
What's happening here is that Pandoc doesn't like
<a>
elements to be directly insidedivs
, and so it inserts a paragraph. This is happening because your output (usekeep-md: true
to inspect it) doesn't bracket the content in a raw block:If you need your HTML output to be unprocessed by Pandoc, you need to emit a raw block. I don't know the htmltools syntax to do it, but
knitr::raw_html
will take a string as input and produce a raw block.produces