Skip to content

Commit

Permalink
Fix #225: use bookdown-style captions in blogdown also.
Browse files Browse the repository at this point in the history
  • Loading branch information
hughjonesd committed May 6, 2022
1 parent ceda6ca commit 1a126bf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Bugfix: infinite loop with wide characters in `to_screen()`.
* Bugfix: duplicate colnames when exporting `huxreg(..., error_pos = "right")`
to flextable.
* Bugfix: bookdown-style references weren't working in blogdown.


# huxtable 5.4.0
Expand Down
7 changes: 4 additions & 3 deletions R/bookdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Functions relating to bookdown


in_bookdown <- function () {
use_bookdown_style_captions <- function () {
if (! is.null(book_opt <- getOption("huxtable.bookdown", NULL))) return(book_opt)

if (! requireNamespace("knitr", quietly = TRUE)) return(FALSE)
Expand All @@ -11,9 +11,10 @@ in_bookdown <- function () {
if (is.null(input_path)) return(FALSE)
rmd_of <- rmarkdown::default_output_format(input_path)$name

return(grepl("bookdown", rmd_of))
return(grepl("bookdown|blogdown", rmd_of))
}


make_caption <- function(ht, label, format = c("html", "latex", "md")) {
format <- match.arg(format)

Expand All @@ -22,7 +23,7 @@ make_caption <- function(ht, label, format = c("html", "latex", "md")) {
if (is.na(label) || label == "") {
return(raw_cap)
}
if (! in_bookdown()) {
if (! use_bookdown_style_captions()) {
return(raw_cap)
}

Expand Down
1 change: 1 addition & 0 deletions man/huxtable-news.Rd

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

4 changes: 3 additions & 1 deletion tests/testthat/bookdown-test.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ library(huxtable)
if( ! ((x <- guess_knitr_output_format()) %in% c('html', 'latex'))) {
stop("guessed output is ", x)
}
if (! huxtable:::in_bookdown()) stop("huxtable:::in_bookdown() returned false")
if (! huxtable:::use_bookdown_style_captions()) {
stop("huxtable:::use_bookdown_style_captions() returned false")
}
```

My table is \@ref(tab:foo1). The other table
Expand Down

0 comments on commit 1a126bf

Please sign in to comment.