From c3750da35cfa88a09ce83ca36b2b25942d124c4f Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 11 Jun 2021 10:38:15 -0400 Subject: [PATCH] Add the `whitespace` arg to `cell_text()` --- R/helpers.R | 27 +++++++++++++++++++-------- man/cell_text.Rd | 21 +++++++++++++-------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index c27a8fc2c..8d05fd45a 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -1717,14 +1717,17 @@ currency <- function(..., #' `"expanded"`, `"extra-expanded"`, or `"ultra-expanded"`. Alternatively, we #' can supply percentage values from `0\%` to `200\%`, inclusive. Negative #' percentage values are not allowed. +#' @param decorate Allows for text decoration effect to be applied. Here, we can +#' use `"overline"`, `"line-through"`, or `"underline"`. +#' @param transform Allows for the transformation of text. Options are +#' `"uppercase"`, `"lowercase"`, or `"capitalize"`. +#' @param whitespace A whitespace preservation option. By default, runs of +#' whitespace will be collapsed into single spaces. If we use `"pre"` here, +#' all whitespace will be preserved. #' @param indent The indentation of the text. Can be provided as a number that #' is assumed to represent `px` values (or could be wrapped in the [px()]) #' helper function. Alternatively, this can be given as a percentage (easily #' constructed with [pct()]). -#' @param decorate allows for text decoration effect to be applied. Here, we can -#' use `"overline"`, `"line-through"`, or `"underline"`. -#' @param transform Allows for the transformation of text. Options are -#' `"uppercase"`, `"lowercase"`, or `"capitalize"`. #' #' @return A list object of class `cell_styles`. #' @@ -1770,9 +1773,10 @@ cell_text <- function(color = NULL, style = NULL, weight = NULL, stretch = NULL, - indent = NULL, decorate = NULL, - transform = NULL) { + transform = NULL, + whitespace = NULL, + indent = NULL) { # Get all assigned values for the functions' arguments style_names <- formals(cell_text) %>% names() @@ -1836,6 +1840,12 @@ cell_text <- function(color = NULL, in_vector = c("uppercase", "lowercase", "capitalize") ) + validate_style_in( + style_vals, style_names, + arg_name = "whitespace", + in_vector = "pre" + ) + cell_style_structure(name = "cell_text", obj = style_vals) } @@ -1852,9 +1862,10 @@ cell_style_to_html.cell_text <- function(style) { style = "font-style", weight = "font-weight", stretch = "font-stretch", - indent = "text-indent", decorate = "text-decoration", - transform = "text-transform" + transform = "text-transform", + whitespace = "white-space", + indent = "text-indent" ) html_names <- css_names[names(css)] diff --git a/man/cell_text.Rd b/man/cell_text.Rd index 74c616a71..11273e760 100644 --- a/man/cell_text.Rd +++ b/man/cell_text.Rd @@ -13,9 +13,10 @@ cell_text( style = NULL, weight = NULL, stretch = NULL, - indent = NULL, decorate = NULL, - transform = NULL + transform = NULL, + whitespace = NULL, + indent = NULL ) } \arguments{ @@ -52,16 +53,20 @@ condensation/expansion: \code{"ultra-condensed"}, \code{"extra-condensed"}, can supply percentage values from \verb{0\\\%} to \verb{200\\\%}, inclusive. Negative percentage values are not allowed.} -\item{indent}{The indentation of the text. Can be provided as a number that -is assumed to represent \code{px} values (or could be wrapped in the \code{\link[=px]{px()}}) -helper function. Alternatively, this can be given as a percentage (easily -constructed with \code{\link[=pct]{pct()}}).} - -\item{decorate}{allows for text decoration effect to be applied. Here, we can +\item{decorate}{Allows for text decoration effect to be applied. Here, we can use \code{"overline"}, \code{"line-through"}, or \code{"underline"}.} \item{transform}{Allows for the transformation of text. Options are \code{"uppercase"}, \code{"lowercase"}, or \code{"capitalize"}.} + +\item{whitespace}{A whitespace preservation option. By default, runs of +whitespace will be collapsed into single spaces. If we use \code{"pre"} here, +all whitespace will be preserved.} + +\item{indent}{The indentation of the text. Can be provided as a number that +is assumed to represent \code{px} values (or could be wrapped in the \code{\link[=px]{px()}}) +helper function. Alternatively, this can be given as a percentage (easily +constructed with \code{\link[=pct]{pct()}}).} } \value{ A list object of class \code{cell_styles}.