Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make kable() compatible with Quarto when outputing HTML #2289

Open
cderv opened this issue Sep 20, 2023 · 0 comments
Open

Make kable() compatible with Quarto when outputing HTML #2289

cderv opened this issue Sep 20, 2023 · 0 comments
Labels
feature Feature requests quarto Related to quarto specific usage

Comments

@cderv
Copy link
Collaborator

cderv commented Sep 20, 2023

Take this example

---
title: "Citations in tables"
format: html
keep-md: true

references:
- type: article-journal
  id: Lovelace1842
  author:
  - family: Lovelace
    given: Augusta Ada
  issued:
    date-parts:
    - - 1842
  title: >-
    Sketch of the analytical engine invented by Charles Babbage, by LF Menabrea, 
    officer of the military engineers, with notes upon the memoir by the translator
  title-short: Molecular structure of nucleic acids
  container-title: Taylor’s Scientific Memoirs
  volume: 3
  page: 666-731
  language: en-GB
---

## `gt::gt()`

```{r}
tibble::tribble(
  ~Thing, ~Citation,
  1234, "@Lovelace1842"
) |>
  knitr::kable(format = "html")
```

It produces this HTML table

<table>
 <thead>
  <tr>
   <th style="text-align:right;"> Thing </th>
   <th style="text-align:left;"> Citation </th>
  </tr>
 </thead>
<tbody>
  <tr>
   <td style="text-align:right;"> 1234 </td>
   <td style="text-align:left;"> @Lovelace1842 </td>
  </tr>
</tbody>
</table>

This part <td style="text-align:left;"> @Lovelace1842 </td> will not be parsed as Markdown and so it will not be processed as citation.

However, Quarto offers a mechanism for this described in https://quarto.org/docs/authoring/tables.html#html-tables

In addition, Quarto supports the specification of embedded Markdown content in tables. This is done by providing a data attribute qmd or qmd-base64 in an embedded span or div node. These nodes can appear anywhere that such content is allowed: table headers, footers, cells, captions, etc.

To this would work

<table>
 <thead>
  <tr>
   <th style="text-align:right;"> Thing </th>
   <th style="text-align:left;"> Citation </th>
  </tr>
 </thead>
<tbody>
  <tr>
   <td style="text-align:right;"> 1234 </td>
   <td style="text-align:left;"> <span data-qmd="@Lovelace1842"></span> </td>
  </tr>
</tbody>
</table>

gt does it with this syntax

library(gt)
tibble::tribble(
  ~Thing, ~Citation,
  1234, "@Lovelace1842"
) |>
  gt() |> fmt_markdown("Citation")

We should probably have a way to escape for Quarto some column or values.

This could also be in kableExtra directly, but I think kable() should support it directly.

More context in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature requests quarto Related to quarto specific usage
Projects
None yet
Development

No branches or pull requests

1 participant