5

Using quarto's HMTL-output functionalities, I am trying to produce a kable from a data.frame that contains some Markdown-style formatting that should show up in the final document. In the actual use case, I have a number of documents already formatted this way and I would like re-use these commands for correctly rendering the output.

Here's my example.qmd:

---
title: "example"
format: 
  html
---

```{r setup}
library(kableExtra)
```

```{r}
#| echo: false
data.frame(Function = "`read_delim()`",
           Formula = "$\\leftarrow$",
           Break = "this continues on a<br>new line",
           Link = "[Google](www.google.com)") |>
  kbl(format = "html") 
```

After running the chunk, the preview in RStudio does display the arrow and line break correctly, but ` ` and the link fail to have an effect:

Screenshot from RStudio

When rendering the qmd to HTML, the result looks like this, i.e. ignores the formatting:

enter image description here

What am I missing? Is there a way to include such formatting commands into a kable when rendering a quarto document to HTML?

1 Answer 1

9

When creating a table in Quarto, you can't mix Markdown with HTML - the Markdown syntax won't be processed within the HTML table.

This R code would work

data.frame(Function = "`read_delim()`",
           Formula = "$\\leftarrow$",
           Break = "this continues on a<br>new line",
           Link = "[Google](www.google.com)") |>
  kbl(format = "markdown") 

So if you can, output only Markdown table which knitr::kable() should do by default.

If you need to output a HTML table (e.g for specific HTML features), you need to use a framework that will render the markdown for you while creating the HTML table.

This is possible that this limitation of note being able to include raw Markdown inside HTML table will be improve in the future (https://github.com/quarto-dev/quarto-cli/discussions/957#discussioncomment-2807907)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, format = "markdown" was the part I've been looking for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.