Skip to content

Commit d18c684

Browse files
committed
Close #477. save_html() now works correctly with components and pages with non-default theme values
1 parent bee0b80 commit d18c684

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ S3method(print,bslib_fragment)
99
S3method(print,bslib_page)
1010
S3method(print,bslib_showcase_layout)
1111
S3method(print,bslib_value_box_theme)
12+
S3method(save_html,bslib_fragment)
13+
S3method(save_html,bslib_page)
1214
export(accordion)
1315
export(accordion_panel)
1416
export(accordion_panel_close)

R/print.R

+15
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,18 @@ print.bslib_page <- function(x, ...) {
3636

3737
invisible(NextMethod())
3838
}
39+
40+
#' @export
41+
save_html.bslib_fragment <- function(html, file, ...) {
42+
html <- attr(html, "bslib_page")(html)
43+
save_html(html, file, ...)
44+
}
45+
46+
#' @export
47+
save_html.bslib_page <- function(html, file, ...) {
48+
old_theme <- bs_global_get()
49+
bs_global_set(attr(html, "bs_theme", exact = TRUE))
50+
on.exit(bs_global_set(old_theme), add = TRUE)
51+
52+
NextMethod()
53+
}

0 commit comments

Comments
 (0)