From 2938a0a1d331624319d7ee8a9fef07100b2dade5 Mon Sep 17 00:00:00 2001 From: "james.balamuta@gmail.com" Date: Sat, 12 Jul 2025 23:47:12 -0700 Subject: [PATCH 1/2] Separates out the inline CSS on elements and attempts to re-use existing bootstrap styling set via pkgdown --- R/examplesWebR.R | 201 +++++++++++++++++++++++++++++++++++----- man/tag-examplesWebR.Rd | 31 ++++++- 2 files changed, 207 insertions(+), 25 deletions(-) diff --git a/R/examplesWebR.R b/R/examplesWebR.R index e0dfc64..a5a220f 100644 --- a/R/examplesWebR.R +++ b/R/examplesWebR.R @@ -30,7 +30,7 @@ #' \section{WebR}{ #' \ifelse{html}{ #' \out{ -#' \U0001F310 View in webR REPL +#'
...
#' } #' }{ #' \ifelse{latex}{ @@ -56,6 +56,32 @@ #' - **LaTeX/PDF**: Plain URL link to webR session #' - **Other formats**: Informational message about limited support #' +#' @section Styling and Theming: +#' +#' The webR Section HTML output uses Bootstrap-compatible CSS classes and custom +#' properties to link themeing to pkgdown's existing CSS themes. The styles +#' follow the CSS custom properties pattern: +#' +#' - Private variables (`--_*`): Used internally +#' - Public variables (`--rocleteer-webr-*`): For user customization +#' - Bootstrap variables (`--bs-*`): Used as fallbacks +#' +#' Main CSS classes are: +#' +#' - `.rocleteer-webr-container`: Main container +#' - `.rocleteer-webr-warning`: Experimental feature warning +#' - `.rocleteer-webr-btn`, `.rocleteer-webr-btn-primary`, etc.: Button styling +#' +#' To customize appearance in pkgdown sites, override CSS custom properties by +#' including into a file: +#' +#' ```css +#' .rocleteer-webr-container { +#' --rocleteer-webr-container-bg: #f0f8ff; +#' --rocleteer-webr-btn-primary-bg: #1976d2; +#' } +#' ``` +#' #' @section Parameters: #' #' The tag supports optional parameters (these override global `DESCRIPTION` config): @@ -326,7 +352,7 @@ encode_webr_code <- function(code, filename = "example.R", autorun = FALSE) { if (!requireNamespace("base64enc", quietly = TRUE)) { stop("Package 'base64enc' is required for @examplesWebR tag") } - + # Create the share item structure exactly as webR expects share_item <- list( list( @@ -519,6 +545,132 @@ parse_webr_params <- function(tag_line, global_config = list()) { return(params) } +#' Generate Rocleteer webR CSS styles +#' +#' Create the complete CSS for webR components as an inline style block +#' +#' @return +#' HTML string with complete CSS styles +#' +#' @noRd +webr_inline_css <- function() { + paste0( + '', + collapse = "\n" + ) +} + #' Generate webR warning HTML #' #' Create standardized warning message for webR examples @@ -529,7 +681,7 @@ parse_webr_params <- function(tag_line, global_config = list()) { #' @noRd webr_experimental_warning <- function() { paste0( - '
', + '
', '\U0001F9EA Experimental: Interactive webR examples are a new feature. ', 'Loading may take a moment, and the package version might differ from this documentation.', '
' @@ -590,15 +742,17 @@ webr_repl_href <- function(encoded_code, version = "latest", mode = "", channel webr_repl_link <- function(encoded_code, version = "latest", mode = "", channel = "") { url <- webr_repl_href(encoded_code, version, mode, channel) html <- paste0( - '
', + # Include CSS + # TODO: Figure out how to include it once? Post parser re-write? + webr_inline_css(), + + '
', # Warning message webr_experimental_warning(), # Link button - '

', + '

', '\U0001F310 View in webR REPL

', '
' @@ -622,43 +776,42 @@ webr_repl_link <- function(encoded_code, version = "latest", mode = "", channel #' @noRd webr_repl_iframe <- function(encoded_code, version = "latest", height = 300, mode = "", channel = "") { url <- webr_repl_href(encoded_code, version, mode, channel) - + # Create an ID for this iframe (based on the encoded code) hashed_id <- abs(sum(utf8ToInt(substr(encoded_code, 1, 10)))) iframe_id <- paste0("webr_iframe_", hashed_id) html <- paste0( - '
', + # Include CSS + webr_inline_css(), + + '
', # Warning message webr_experimental_warning(), # Initial buttons (before iframe loads) - '
', - '

Interactive Example Available

', + '
', + '

Interactive Example Available

', '', '', '
', # Iframe container (hidden initially) - '