rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.01k stars 204 forks source link

footnote/markdown combo not working (in bookdown) #129

Open r-cheologist opened 5 years ago

r-cheologist commented 5 years ago

When trying to add a footnote containing markdown, the formatting is not maintained when using bookdown. Consider:

---
title: Bug Report
subtitle: No `markdown` formatting in footnote
date: '`r format(Sys.time(), "%d %B, %Y")`'
author: r-cheologist
output:
  bookdown::pdf_document2
---

```{r prerequisites, message = FALSE}
library(magrittr)
requireNamespace('gt')
```

```{r table, results='asis'}
data.frame(
  A      = 1:5,
  B      = rep('Longer than longish group label', times = 5),
  groups = c(
    rep('Longish group label', times = 2),
    rep('Label', times = 3))) %>%
  gt::gt(groupname_col = 'groups') %>%
  gt::tab_footnote(
    footnote = gt::md("**This** ought to be bold, *that* italic & ^yonder^ superscript."),
    locations = gt::cells_column_labels(gt::vars(A))
  )
```

which (independently of whether results = 'asis' is set or not) produces this

blongworth commented 4 years ago

I just ran into something similar using gt::md() to format a title.

This:

tab_header(title = md("δ^13^C of *NOSAMS* and **external** standards"))

italicizes and bolds correctly, but the superscript is interpreted literally.

blongworth commented 4 years ago

I dug into this a little more, and my issue is not the same as the OP.

"^" is not interpreted as superscript by commonmark::markdown_html markdown converter called by {gt}. HTML tags are passed through, so the solution is to use until commonmark supports "^". This is confusing since rmarkdown::render() uses pandoc to convert markdown to HTML, which does interpret "^" as superscript.

Also worth noting that OP's footnote does get bold and italics when rendering to HTML, but not when rendering to PDF.