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
+70-30Lines changed: 70 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -19,50 +19,90 @@ The main challenge when working with Markdown in HTML tables is that Quarto won'
19
19
20
20
See Quarto documentation about HTML tables parsing: <https://quarto.org/docs/authoring/tables.html#html-tables>.
21
21
22
+
## When to Use These Functions
23
+
24
+
Use the `tbl_qmd_*()` functions when:
25
+
26
+
-**Working with table packages that don't have built-in Quarto support** (like kableExtra)
27
+
-**You need raw HTML control** over some Markdown content that needs to be processed by Quarto
28
+
-**Migrating existing table code** to support Quarto's HTML table processing
29
+
30
+
**Don't use these functions** when:
31
+
32
+
- Your table package already has built-in Quarto support (like gt's `fmt_markdown()` or tinytable's `format_tt(quarto = TRUE)`)
33
+
- You're working outside of Quarto documents (the functions will have no effect)
34
+
- Simple formatting is easy enough to write in raw HTML and does not require Quarto Markdown processing.
35
+
22
36
## Basic Usage
23
37
24
-
The table helper functions create HTML elements (`<span>` or `<div>`) with the appropriate `data-qmd` or `qmd-base64` attributes. There are two main types of functions:
38
+
The table helper functions create HTML elements (`<span>` or `<div>`) with the appropriate `data-qmd` or `data-qmd-base64` attributes. There are two main types of functions:
25
39
26
40
1. Functions for creating `<span>` elements:
27
-
- main function is `tbl_qmd_span()`, defaulting to base64 encoding,
28
-
- Two others are explicit versions: `tbl_qmd_span_base64()`and `tbl_qmd_span_raw()`
41
+
- main function is `tbl_qmd_span()`, defaulting to base64 encoding
42
+
- Two others are explicit versions: `tbl_qmd_span_base64()` and `tbl_qmd_span_raw()`
29
43
2. Functions for creating `<div>` elements:
30
-
- main function is `tbl_qmd_div()`, defaulting to base64 encoding,
31
-
- Two others are explicit versions: `tbl_qmd_div_base64()`and `tbl_qmd_div_raw()`
44
+
- main function is `tbl_qmd_div()`, defaulting to base64 encoding
45
+
- Two others are explicit versions: `tbl_qmd_div_base64()` and `tbl_qmd_div_raw()`
32
46
33
47
Base64 encoding is useful when your Markdown content contains special characters or HTML tags, and this is used by default to avoid any escaping problems using this feature.
34
48
35
-
### Example with a Basic HTML Table
49
+
### Before and After Comparison
36
50
37
-
Here's a simple example of creating an HTML table with Markdown content:
51
+
Here's what happens when you don't use the helper functions:
38
52
39
53
```{r}
40
54
library(quarto)
41
55
42
-
# Create a simple data frame
43
-
data <- data.frame(
44
-
Column1 = c("Row 1", "Row 2", "Row 3"),
45
-
Column2 = c("Value 1", "Value 2", "Value 3")
56
+
# Without helper functions - Markdown won't be processed
Quarto sees the `data-qmd-base64` attribute and processes the base64-decoded content as Markdown.
105
+
66
106
### Using with knitr::kable()
67
107
68
108
The `knitr::kable()` function is a common way to create tables in R Markdown and Quarto. By setting `escape = FALSE`, we can include HTML in the table cells:
Some feature are Quarto features only. If your table can be used in other context than Quarto, you might want to use the `display` argument to provide a text that will be shown in the table instead of the Markdown content, as it won't be processed outside of Quarto documents.
132
+
Some features are Quarto features only. If your table can be used in other context than Quarto, you might want to use the `display` argument to provide a text that will be shown in the table instead of the Markdown content, as it won't be processed outside of Quarto documents.
93
133
94
134
For example, you might want to show a placeholder when using video shortcodes in a table, as the video player won't be rendered outside of Quarto:
95
135
@@ -133,12 +173,12 @@ Using `data-qmd` or `data-qmd-base64` attributes is a Quarto-specific feature an
133
173
134
174
## Table package integration
135
175
136
-
To summarize the question of Markdown processing in HTML tables within Quarto,
176
+
To summarize the question of Markdown processing in HTML tables within Quarto, currently, there are two ways this could be supported:
137
177
138
178
- This is possible thanks to Quarto HTML Table parsing
139
179
- This is done using some `<span>` or `<div>` elements with `data-qmd` or `data-qmd-base64` attributes
140
180
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.
181
+
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.In this case, they will create themselves the `<span>` or `<div>` elements with the `data-qmd` or `data-qmd-base64` attributes.
142
182
143
183
Currently, there is two ways this could be supported:
0 commit comments