You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/markdown-html-tables.qmd
+79-7Lines changed: 79 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -133,9 +133,26 @@ Using `data-qmd` or `data-qmd-base64` attributes is a Quarto-specific feature an
133
133
134
134
## Table package integration
135
135
136
+
To summarize the question of Markdown processing in HTML tables within Quarto,
137
+
138
+
- This is possible thanks to Quarto HTML Table parsing
139
+
- This is done using some `<span>` or `<div>` elements with `data-qmd` or `data-qmd-base64` attributes
140
+
141
+
Any R package for producing tables and providing raw HTML as output needs to support this Quarto feature to allow Markdown content in HTML tables.
142
+
143
+
Currently, there is two ways this could be supported:
144
+
145
+
- Either the package already supports Quarto HTML table parsing, and offer a way to mark the cells as to be processed by Quarto when in Quarto context. In this case, they will create themself the `<span>` or `<div>` elements with the `data-qmd` or `data-qmd-base64` attributes.
146
+
147
+
- Either the package does not support Quarto HTML table parsing directly, and offers a way to insert raw HTML content in the table cells. In this case, you can use the helper functions provided by this package to create the `<span>` or `<div>` elements with the appropriate attributes.
148
+
149
+
Below will show how this works with some popular R packages for creating tables.
150
+
136
151
### Using with kableExtra
137
152
138
-
Here's a more complex example that combines all these features to create a complete HTML table with Markdown content:
153
+
**kableExtra** is a popular package for creating and styling tables in R. It produces raw HTML but does not have yet specific support for Quarto's HTML table parsing. However, you can use the helper functions to insert Markdown content into the cells, as it allows to insert raw HTML content in the table cells (by setting `escape = FALSE` to keep the raw HTML as-is).
154
+
155
+
So here is a more complex example that combines all these features to create a complete HTML table with Markdown content:
By design, **flextable** does not support inserting raw HTML content into its cells. Using the `tbl_qmd_span()` or `tbl_qmd_div()` functions directly in a flextable will not work as expected.
173
191
174
-
By design, flextable does not support inserting raw HTML content into its cells. Using the `tbl_qmd_span()` or `tbl_qmd_div()` functions directly in a flextable will not work as expected.
192
+
Unfortunately, **flextable** does not yet integrate with Quarto's HTML table parsing features, and does not allow to mark cell content as Markdown to be processed by Quarto.
175
193
176
-
Quarto team will be working with flextable developers to find a way to support this in the future.
194
+
The Quarto team will be working with **flextable** developers to find a way to support this in the future.
177
195
178
196
### Using with **gt**
179
197
180
-
The **gt** package provides a way to create tables with rich formatting. **gt** already has built-in support for rendering Markdown content, so you can use it directly without needing the `tbl_qmd_span()` or `tbl_qmd_div()` functions.
198
+
The **gt** package provides a way to create tables with rich formatting.
199
+
200
+
**gt** allows to insert raw HTML content in the table cells, and it has built-in support for Quarto's HTML table parsing. It uses the `data-qmd` attribute internally to mark cells that contain Markdown content.
181
201
182
-
Here is the same example as above, but using **gt** with **quarto** R package functions
202
+
Here is the same table example as above, using **gt** with **quarto** R package functions. `fmt_passthrough()` is used to allow raw HTML content in the table cells, and `escape = FALSE` is set to avoid escaping the HTML content:
However, **gt** already has built-in support for rendering Markdown content, so you can use it directly without needing the `tbl_qmd_span()` or `tbl_qmd_div()` functions.
190
211
Here is the example with built-in support for Markdown content in **gt**:
191
212
192
213
```{r}
@@ -212,8 +233,59 @@ data.frame(
212
233
213
234
`gt::fmt_markdown()` is aware of Quarto context and it will internally use the `data-qmd` attribute to render Markdown content correctly when Quarto processes the document.
214
235
236
+
### Using with **tinytable**
237
+
238
+
From the **tinytable** package website (<https://vincentarelbundock.github.io/tinytable/>):
239
+
> `tinytable` is a small but powerful R package to draw beautiful tables in a variety of formats: HTML, LaTeX, Word1, PDF, PNG, Markdown, and Typst.
240
+
241
+
By default, `tinytable` does deactivate Quarto HTML table processing. It is a design choice so that **tinytable** formatting is not affected by Quarto's HTML table processing. So, our previous table would look like this:
242
+
243
+
```{r}
244
+
library(tinytable)
245
+
246
+
tt(complex_table)
247
+
```
248
+
249
+
Note that display value for video shortcode is used, as the shortcode is not processed by Quarto in this case.
250
+
251
+
Quarto HTML table processing can be re-enabled in **tinytable**, and in that case, they will handle the `data-qmd` attribute internally, and functions `tbl_qmd_span()` and `tbl_qmd_div()` will not be needed.
Setting the option will opt-in the Quarto HTML table processing for all tables created with **tinytable**. This allows a table using `tbl_qmd_span()` or `tbl_qmd_div()` to be processed correctly by Quarto.
Note that **tinytable** does support `data-qmd` attributes internally, so functions `tbl_qmd_span()` and `tbl_qmd_div()` are not needed when using **tinytable**. You can use `tt()` function directly with Markdown content in the table cells, and marking the cells as using Quarto Markdown processing.
"{{< video https://www.youtube.com/embed/wo9vZccmqwc >}}"
275
+
),
276
+
Notes = c(
277
+
"Basic markdown formatting",
278
+
"LaTeX math expressions",
279
+
"Cross-references to other document elements",
280
+
"Embedded media using shortcodes"
281
+
)
282
+
) |>
283
+
tt() |>
284
+
format_tt(j = "Example", quarto = TRUE)
285
+
```
286
+
215
287
## Conclusion
216
288
217
-
The table helper functions in this package make it easy to include Markdown content in HTML tables when working with Quarto documents. They will be useful to users to get unblocked when using package that provide HTML tables. Hopefully, developers will also find them useful to simplify the process for users of creating tables with rich content.
289
+
The table helper functions in this package make it easy to include Markdown content in HTML tables when working with Quarto documents. They will be useful to users to get unblocked when using a package that provide HTML tables, and does already support Quarto processing. Hopefully, developers will also find them useful to simplify the process for users of creating tables with rich content. This is already happening with **gt** and **tinytable** packages, which have built-in support for Markdown content in tables by marking the cells with the `data-qmd` attribute, internally for the user.
218
290
219
291
For more information about tables in Quarto, see the [Quarto documentation on tables](https://quarto.org/docs/authoring/tables.html#html-tables).
0 commit comments