1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
as_fragment <- function(x, page = page_fluid) {
stopifnot(is.function(page) && "theme" %in% names(formals(page)))
attr(x, "bslib_page") <- page
class(x) <- c("bslib_fragment", class(x))
x
}
as_page <- function(x) {
class(x) <- c("bslib_page", class(x))
x
}
#' Make HTML browsable by default
#'
#' @param x a [tag()] object.
#' @param ... passed along to an underlying print method
#' @export
#' @keywords internal
#' @rdname html-browse
print.bslib_fragment <- function(x, ...) {
x <- attr(x, "bslib_page")(x)
invisible(print(x, ...))
}
#' @rdname html-browse
#' @export
print.bslib_page <- function(x, ...) {
if (interactive()) {
x <- htmltools::browsable(x)
}
invisible(NextMethod())
}
|