From c49841b5bb411064e60f712b7565e1f319f125d0 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 30 Jan 2025 09:05:47 -0500 Subject: [PATCH 1/2] fix bookdown::html_document2 cross-ref --- NEWS.md | 2 ++ R/knitr-utils.R | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 0b9ffed62..0721856c6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # gt (development version) +* Fixed an issue where cross-references would fail in bookdown::html_document2 (@olivroy, #1948) + * Significantly faster rendering of certain large tables, by optimizing the internal `rownum_translation()` utility. (@magnusdv, #1924) * Interactive tables can support selection through the `ihtml.selection_mode` option. (@jonthegeek, #1909) diff --git a/R/knitr-utils.R b/R/knitr-utils.R index bf8dcbc5d..b45106902 100644 --- a/R/knitr-utils.R +++ b/R/knitr-utils.R @@ -40,7 +40,11 @@ kable_caption <- function(label, caption, format) { create_label <- function(..., latex = FALSE) { if (isTRUE(knitr::opts_knit$get("bookdown.internal.label"))) { - lab1 <- "(\\#" + if (latex) { + lab1 <- "(\\#" + } else { + lab1 <- "(#" + } lab2 <- ")" } else if (latex) { lab1 <- "\\label{" From 1e50e3cc7f402d03105b435230f74042b8cec00b Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Thu, 30 Jan 2025 09:24:18 -0500 Subject: [PATCH 2/2] Fix bookdown test expectation for html --- tests/testthat/test-utils_render_html.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-utils_render_html.R b/tests/testthat/test-utils_render_html.R index af141943b..ae89bb019 100644 --- a/tests/testthat/test-utils_render_html.R +++ b/tests/testthat/test-utils_render_html.R @@ -41,7 +41,7 @@ test_that("bookdown-style crossrefs are added when appropriate", { # If bookdown, then ref is generated knitr::opts_knit$set(bookdown.internal.label = TRUE) - expect_caption_eq("test", "(\\#tab:foo)test") + expect_caption_eq("test", "(#tab:foo)test") expect_null(create_caption_component_h(exibble %>% gt()))