Using Markdown Formatting in Table Using Kable in Quarto

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]()") |>
  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:

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

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

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]()") |>
  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 ()

1

Your Answer

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

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest