From 478c2fc6e55e0d3180394349ae1fa36aa54428a0 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Sun, 8 Dec 2024 09:14:40 -0500 Subject: [PATCH] more style_notes --- R/style_notes.R | 41 +++++++++++++++++++++++++++------------ R/style_string.R | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ R/style_tt.R | 6 +++++- 3 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 R/style_string.R diff --git a/R/style_notes.R b/R/style_notes.R index d5387576..a338d494 100644 --- a/R/style_notes.R +++ b/R/style_notes.R @@ -18,12 +18,7 @@ setMethod( signature = "tinytable_bootstrap", definition = function(x, ...) { styles <- x@style_notes - if (isTRUE(styles[["italic"]])) { - x@notes <- lapply(x@notes, function(n) sprintf("%s", n)) - } - if (isTRUE(styles[["bold"]])) { - x@notes <- lapply(x@notes, function(n) sprintf("%s", n)) - } + x@notes <- lapply(x@notes, style_string_html, styles) return(x) }) @@ -34,12 +29,7 @@ setMethod( signature = "tinytable_tabularray", definition = function(x, ...) { styles <- x@style_notes - if (isTRUE(styles[["italic"]])) { - x@notes <- lapply(x@notes, function(n) sprintf("\\emph{%s}", n)) - } - if (isTRUE(styles[["bold"]])) { - x@notes <- lapply(x@notes, function(n) sprintf("\\textbf{%s}", n)) - } + x@notes <- lapply(x@notes, style_string_html, styles) return(x) }) @@ -69,3 +59,30 @@ setMethod( return(x) }) + + + +style_string_html <- function(n, styles) { + if (isTRUE(styles[["italic"]])) { + n <- sprintf("%s", n) + } + if (isTRUE(styles[["strikeout"]])) { + n <- sprintf("%s", n) + } + if (isTRUE(styles[["underline"]])) { + n <- sprintf("%s", n) + } + if (isTRUE(styles[["bold"]])) { + n <- sprintf("%s", n) + } + if (isTRUE(styles[["monospace"]])) { + n <- sprintf("%s", n) + } + if (!is.null(styles[["color"]])) { + n <- sprintf("%s", styles[["color"]], n) + } + if (!is.null(styles[["fontsize"]])) { + n <- sprintf("%s", styles[["fontsize"]], n) + } + n +} diff --git a/R/style_string.R b/R/style_string.R new file mode 100644 index 00000000..61bef358 --- /dev/null +++ b/R/style_string.R @@ -0,0 +1,50 @@ +style_string_html <- function(n, styles) { + if (isTRUE(styles[["italic"]])) { + n <- sprintf("%s", n) + } + if (isTRUE(styles[["strikeout"]])) { + n <- sprintf("%s", n) + } + if (isTRUE(styles[["underline"]])) { + n <- sprintf("%s", n) + } + if (isTRUE(styles[["bold"]])) { + n <- sprintf("%s", n) + } + if (isTRUE(styles[["monospace"]])) { + n <- sprintf("%s", n) + } + if (!is.null(styles[["color"]])) { + n <- sprintf("%s", styles[["color"]], n) + } + if (!is.null(styles[["fontsize"]])) { + n <- sprintf("%s", styles[["fontsize"]], n) + } + n +} + + +style_string_latex <- function(n, styles) { + if (isTRUE(styles[["italic"]])) { + n <- sprintf("\\textit{%s}", n) + } + if (isTRUE(styles[["strikeout"]])) { + n <- sprintf("\\sout{%s}", n) + } + if (isTRUE(styles[["underline"]])) { + n <- sprintf("\\underline{%s}", n) + } + if (isTRUE(styles[["bold"]])) { + n <- sprintf("\\textbf{%s}", n) + } + if (isTRUE(styles[["monospace"]])) { + n <- sprintf("\\texttt{%s}", n) + } + if (!is.null(styles[["color"]])) { + n <- sprintf("\\textcolor{%s}{%s}", styles[["color"]], n) + } + if (!is.null(styles[["fontsize"]])) { + n <- sprintf("{\\fontsize{%s}{%s}\\selectfont %s}", styles[["fontsize"]], styles[["fontsize"]], n) + } + n +} diff --git a/R/style_tt.R b/R/style_tt.R index 69c8784b..4c47d88a 100644 --- a/R/style_tt.R +++ b/R/style_tt.R @@ -160,8 +160,12 @@ style_tt <- function(x, if (identical(i, "notes")) { out@style_notes <- list( + color = color, + fontsize = fontsize, italic = italic, - bold = bold + monospace = monospace, + strikeout = strikeout, + underline = underline ) return(out) }