Skip to content

Commit

Permalink
Render gt tables (r-lib#2493)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored and SebKrantz committed Jun 1, 2024
1 parent fd509e0 commit 0b32643
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Suggests:
diffviewer,
evaluate,
gert,
gt,
htmltools,
htmlwidgets,
knitr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ S3method(as_html,tag_url)
S3method(as_html,tag_var)
S3method(as_html,tag_verb)
S3method(pkgdown_print,default)
S3method(pkgdown_print,gt_tbl)
S3method(pkgdown_print,htmlwidget)
S3method(print,pkgdown_xml)
S3method(print,print_yaml)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pkgdown (development version)

* `build_reference()` now automatically renders any tables created by gt (#2326).
* `build_articles()` now drops a section called "internal". This allows you to have articles that either aren't indexed at all or are included manually elsewhere in the navbar (#2205).
* `as.pkgdown()` will no longer prompt you to install a missing template package from CRAN, since these are almost always found in GitHub (#2076).
* `init_site()` once again describes one copy per line, and now uses a better prefix when copying assets from pkgdown itself (#2445).
Expand Down
12 changes: 12 additions & 0 deletions R/pkgdown_print.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ pkgdown_print.htmlwidget <- function(x, visible = TRUE) {
x$height <- x$height %||% (settings$fig.height * settings$dpi)
x
}

#' @export
pkgdown_print.gt_tbl <- function(x, visible = TRUE) {
if (!visible) {
return(invisible())
}

htmltools::div(
class = "gt-table",
gt::as_raw_html(x)
)
}
9 changes: 9 additions & 0 deletions R/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ NULL
#' text(2, 5, "Hello", srt = 30, cex = 2)
NULL

#' Test case: tables
#'
#' @name test-tables
#' @keywords internal
#' @family tests
#' @examples
#' gt::gt(head(mtcars))
NULL

#' Test case: don't
#'
#' @name test-dont
Expand Down
6 changes: 6 additions & 0 deletions inst/BS5/assets/pkgdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ pre {
padding: 1rem 0.5rem;
}

// Spacing tweaks for gt table
pre div.gt-table {
white-space: normal;
margin-top: 1rem;
}

// "Pop" code out of page margins on small screens to give a little more room
@include media-breakpoint-down(sm) {
// div.section div.sourceCode pre
Expand Down
1 change: 1 addition & 0 deletions man/index.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-crayon.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-dont.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-figures.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-links.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-lists.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-long-lines.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-output-styles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-params.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/test-sexpr-title.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions man/test-tables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/test-verbatim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b32643

Please sign in to comment.