Skip to content

Commit 933ff99

Browse files
committed
don't expose class and attr yet
1 parent 7be6034 commit 933ff99

File tree

3 files changed

+39
-96
lines changed

3 files changed

+39
-96
lines changed

R/table-helper.R

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
#' accessibility.
2828
#' @param use_base64 Logical, whether to base64 encode the content (recommended
2929
#' for complex content with special characters or when content includes quotes)
30-
#' @param class Optional CSS class(es) to add to the element. While this works for
31-
#' both span and div elements, it's more commonly used with div elements.
32-
#' @param attrs Named list of additional HTML attributes to add to the element.
33-
#' For example: `list(id = "my-element", title = "Tooltip text")`
3430
#'
3531
#' @return Character string containing the HTML element with appropriate data-qmd attributes
3632
#'
@@ -47,11 +43,6 @@
4743
#' tbl_qmd_span_base64("Complex $\\LaTeX$ content")
4844
#' tbl_qmd_span_raw("Simple text")
4945
#'
50-
#' # Use with custom attributes
51-
#' tbl_qmd_span("**Important note**", attrs = list(title = "Hover for more info"))
52-
#' tbl_qmd_div("Content here", class = "callout",
53-
#' attrs = list(id = "special-note", tabindex = "0"))
54-
#'
5546
#' # Use with different HTML table packages
5647
#' \dontrun{
5748
#' # With kableExtra
@@ -85,7 +76,12 @@ NULL
8576
invisible(TRUE)
8677
}
8778

88-
79+
#' @inheritParams tbl_qmd_elements
80+
#' @param class Optional CSS class(es) to add to the element. While this works for
81+
#' both span and div elements, it's more commonly used with div elements.
82+
#' @param attrs Named list of additional HTML attributes to add to the element.
83+
#' For example: `list(id = "my-element", title = "Tooltip text")`
84+
#' @noRd
8985
.tbl_qmd_element <- function(
9086
tag,
9187
content,
@@ -132,82 +128,64 @@ NULL
132128
tbl_qmd_span <- function(
133129
content,
134130
display = NULL,
135-
use_base64 = TRUE,
136-
class = NULL,
137-
attrs = NULL
131+
use_base64 = TRUE
138132
) {
139-
.tbl_qmd_element("span", content, display, use_base64, class, attrs)
133+
.tbl_qmd_element("span", content, display, use_base64)
140134
}
141135

142136
#' @rdname tbl_qmd_elements
143137
#' @export
144138
tbl_qmd_div <- function(
145139
content,
146140
display = NULL,
147-
use_base64 = TRUE,
148-
class = NULL,
149-
attrs = NULL
141+
use_base64 = TRUE
150142
) {
151-
.tbl_qmd_element("div", content, display, use_base64, class, attrs)
143+
.tbl_qmd_element("div", content, display, use_base64)
152144
}
153145
#' @rdname tbl_qmd_elements
154146
#' @export
155147
tbl_qmd_span_base64 <- function(
156148
content,
157-
display = NULL,
158-
class = NULL,
159-
attrs = NULL
149+
display = NULL
160150
) {
161151
tbl_qmd_span(
162152
content,
163153
display,
164-
use_base64 = TRUE,
165-
class = class,
166-
attrs = attrs
154+
use_base64 = TRUE
167155
)
168156
}
169157

170158
#' @rdname tbl_qmd_elements
171159
#' @export
172160
tbl_qmd_div_base64 <- function(
173161
content,
174-
display = NULL,
175-
class = NULL,
176-
attrs = NULL
162+
display = NULL
177163
) {
178-
tbl_qmd_div(content, display, use_base64 = TRUE, class = class, attrs = attrs)
164+
tbl_qmd_div(content, display, use_base64 = TRUE)
179165
}
180166

181167
#' @rdname tbl_qmd_elements
182168
#' @export
183169
tbl_qmd_span_raw <- function(
184170
content,
185-
display = NULL,
186-
class = NULL,
187-
attrs = NULL
171+
display = NULL
188172
) {
189173
tbl_qmd_span(
190174
content,
191175
display,
192-
use_base64 = FALSE,
193-
class = class,
194-
attrs = attrs
176+
use_base64 = FALSE
195177
)
196178
}
197179

198180
#' @rdname tbl_qmd_elements
199181
#' @export
200182
tbl_qmd_div_raw <- function(
201183
content,
202-
display = NULL,
203-
class = NULL,
204-
attrs = NULL
184+
display = NULL
205185
) {
206186
tbl_qmd_div(
207187
content,
208188
display,
209-
use_base64 = FALSE,
210-
class = class,
211-
attrs = attrs
189+
use_base64 = FALSE
212190
)
213191
}

man/tbl_qmd_elements.Rd

Lines changed: 6 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-table-helper.R

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@ test_that("tbl_qmd_span generates correct HTML with base64 encoding", {
99
"<span data-qmd-base64=\"JFxhbHBoYSArIFxiZXRhJA==\">Greek formula</span>",
1010
fixed = TRUE
1111
)
12-
expect_match(
13-
tbl_qmd_span("**bold text**", class = "highlight"),
14-
"<span data-qmd-base64=\"Kipib2xkIHRleHQqKg==\" class=\"highlight\">**bold text**</span>",
15-
fixed = TRUE
16-
)
17-
expect_match(
18-
tbl_qmd_span(
19-
"**Important note**",
20-
attrs = list(title = "Hover for more info")
21-
),
22-
"<span data-qmd-base64=\"KipJbXBvcnRhbnQgbm90ZSoq\" title=\"Hover for more info\">**Important note**</span>",
23-
fixed = TRUE
24-
)
2512
})
2613

2714
test_that("tbl_qmd_span_raw generates correct HTML with raw encoding", {
@@ -49,20 +36,6 @@ test_that("tbl_qmd_div generates correct HTML with base64 encoding", {
4936
"<div data-qmd-base64=\"e3s8IHZpZGVvIGh0dHBzOi8vZXhhbXBsZS5jb20gPn19\">[Video content]</div>",
5037
fixed = TRUE
5138
)
52-
53-
expect_match(
54-
tbl_qmd_div("Content here", class = "something"),
55-
"<div data-qmd-base64=\"Q29udGVudCBoZXJl\" class=\"something\">Content here</div>",
56-
fixed = TRUE
57-
)
58-
expect_match(
59-
tbl_qmd_div(
60-
"Content here",
61-
attrs = list(id = "special-note", tabindex = "0")
62-
),
63-
"<div data-qmd-base64=\"Q29udGVudCBoZXJl\" id=\"special-note\" tabindex=\"0\">Content here</div>",
64-
fixed = TRUE
65-
)
6639
})
6740

6841
test_that("tbl_qmd_div_raw generates correct HTML with raw encoding", {
@@ -109,3 +82,18 @@ test_that(".tbl_qmd_element correctly handles different tag types", {
10982
fixed = TRUE
11083
)
11184
})
85+
86+
test_that(".tbl_qmd_element handles class and additional attributes", {
87+
expect_match(
88+
.tbl_qmd_element(
89+
"span",
90+
"content",
91+
"display",
92+
TRUE,
93+
class = "test-class",
94+
attrs = list(id = "test-id", tabindex = "0")
95+
),
96+
"<span data-qmd-base64=\"Y29udGVudA==\" class=\"test-class\" id=\"test-id\" tabindex=\"0\">display</span>",
97+
fixed = TRUE
98+
)
99+
})

0 commit comments

Comments
 (0)