Skip to content

Put footnotes on the same line with fmt_markdown() in Quarto#1860

Merged
rich-iannone merged 3 commits intorstudio:masterfrom
olivroy:fix-quarto-rendering
Aug 23, 2024
Merged

Put footnotes on the same line with fmt_markdown() in Quarto#1860
rich-iannone merged 3 commits intorstudio:masterfrom
olivroy:fix-quarto-rendering

Conversation

@olivroy
Copy link
Collaborator

@olivroy olivroy commented Aug 23, 2024

Summary

It seems that using a span instead of div seems to work!!

Sorry about the noise. I also think it is not necessary to keep the gt_from_md class?

#1605 (comment)

Related GitHub Issues and PRs

Fixes #1773

Checklist

@olivroy
Copy link
Collaborator Author

olivroy commented Aug 23, 2024

I am using the following script to compare diff

#
gt_tbl <- mtcars[1:2, 1:2] |>
  gt::gt() |>
  gt::cols_label(mpg = gt::md("**MPG**")) |>
  gt::tab_footnote(
    gt::md("_Adding footnote_"),
    locations = gt::cells_column_labels(columns = gt::everything())
  )
# inside Quarto
html_code_quarto <- withr::with_envvar(c("QUARTO_BIN_PATH" = "true"), gt:::render_as_html(gt_tbl))
# out of Quarto
html_code <- withr::with_envvar(c("QUARTO_BIN_PATH" = ""), gt:::render_as_html(gt_tbl))

waldo::compare(html_code, html_code_quarto, x_arg = "html", y_arg = "quarto")

html_file <- withr::local_tempfile(lines = html_code, pattern = "html")
quarto_file <- withr::local_tempfile(lines = html_code_quarto, pattern = "quarto")
diffviewer::visual_diff(
  html_file,
  quarto_file
)

image

The diff seems good! i.e. spans are replaced by their base64 encoding equivalent.

The following Qmd doc renders well too

---
title: "Test"
format: html
---

```{r}
#| echo: false
#| message: false
devtools::load_all()
exibble %>%
    dplyr::select(num, char, fctr) %>%
    dplyr::slice_head(n  = 5) %>%
    gt() %>%
    fmt_markdown(num) %>%
    tab_footnote(
      md("Problem because num row 1 is fmt_markdown() + also the footnote is wrapped in md."),
      locations = cells_body("num", 1)
    ) %>%
    tab_footnote(
      "A problem because fctr is labelled with md",
      locations = cells_column_labels("fctr")
    ) %>%
    tab_footnote(
      "Not a problem",
      locations = cells_column_labels("char")
    ) %>%
    cols_label(fctr = md("**Factor**")) %>%
    tab_header(md("**Title**")) %>% 
    tab_spanner(md("**Problem**"), c(2, 3))
```

image

@olivroy olivroy requested a review from rich-iannone August 23, 2024 15:28
Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rich-iannone rich-iannone merged commit 0de5b27 into rstudio:master Aug 23, 2024
@olivroy olivroy deleted the fix-quarto-rendering branch August 23, 2024 17:24
@olivroy olivroy mentioned this pull request Feb 21, 2025
3 tasks
Comment on lines -48 to +50
non_na_text,
non_na_text_processed,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bad / unnecessary change and it is reverted in #1958

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Footnote marker placement when using gt::md() in Quarto in gt v0.11.0

2 participants