Kable table with links showing raw markdown code in quarto file

I have a chunk of code that creates a table containing file links based on files that's in a specific directory.
This knits fine in RMD, but not in in the quarto version.

Working Posit Cloud project example

Code:

knitr::opts_chunk$set(echo=FALSE, message=FALSE, warning=FALSE)
library(stringr); library(dplyr); library(readxl)
library(knitr); library(kableExtra); library(tidyr)
options(knitr.kable.NA = '')

hw   <- data.frame(filenames = paste0('hw/', list.files("hw", pattern='template|*.pdf|*.html|*.docx')))

out.hw <- hw %>% mutate(name = gsub("hw/|_template",  "", filenames), 
                          type = str_extract(hw$filenames,".{3}$"),
                          type = ifelse(type=="tml", "html", type),
                          type = ifelse(type=="ocx", "docx", type),
                          nam = gsub(".html|.pdf|.Rmd|.docx", "", name), 
                          link = sprintf("[%s](%s)",type, filenames))
x = out.hw %>% select(link, type, nam) %>% 
    reshape2::dcast(nam~type, value.var="link") %>% 
    kable(format="html") %>%
    kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive" ,"bordered"), 
                  full_width=FALSE,  position = "left")
gsub("<thead>.*</thead>", "", x)

Rmarkdown
image

Quarto:

Here's another view with sessionInfo

Working RMD page

Not working QMD page

The code is identical. so why won't one render links?

I believe this is currently a limitation of Quarto and a difference with R Markdown due to better feature for table in Quarto that contraint the way HTML tables are working.

kableExtra will produce HTML table. Within Quarto, HTML can't contain Markdown code as the HTML table table will be considered HTML only. It is marked as raw HTML. This is needed I believe for caption processing and cross reference feature.
With R Markdown you don't encounter that because HTML code is not marked as raw HTML for Pandoc, and
markdown_in_html_blocks extension is activated.

With Quarto, if you want formatting within the cell, it will be better to not use markdown when you are producing HTML table. You can use some function to format content, like within gt and the fmt_markdown or its other helper function

Other package like flextable and ftextra may have the same.

We'll probably try to improve that in Quarto on in kable() somehow, but for now markdown should not be used in HTML table. I'll look into this on the Quarto side to understand if we can remove the raw HTML attributes.

Hope it helps understand. Thanks for the rstudio cloud project by the way, this is really good to have to understand what you did!

1 Like