Skip to content

Commit

Permalink
more style_notes
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Dec 8, 2024
1 parent 84e590c commit 478c2fc
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 13 deletions.
41 changes: 29 additions & 12 deletions R/style_notes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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("<i>%s</i>", n))
}
if (isTRUE(styles[["bold"]])) {
x@notes <- lapply(x@notes, function(n) sprintf("<b>%s</b>", n))
}
x@notes <- lapply(x@notes, style_string_html, styles)
return(x)
})

Expand All @@ -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)
})

Expand Down Expand Up @@ -69,3 +59,30 @@ setMethod(

return(x)
})



style_string_html <- function(n, styles) {
if (isTRUE(styles[["italic"]])) {
n <- sprintf("<i>%s</i>", n)
}
if (isTRUE(styles[["strikeout"]])) {
n <- sprintf("<s>%s</s>", n)
}
if (isTRUE(styles[["underline"]])) {
n <- sprintf("<u>%s</u>", n)
}
if (isTRUE(styles[["bold"]])) {
n <- sprintf("<b>%s</b>", n)
}
if (isTRUE(styles[["monospace"]])) {
n <- sprintf("<code>%s</code>", n)
}
if (!is.null(styles[["color"]])) {
n <- sprintf("<span style='color:%s'>%s</span>", styles[["color"]], n)
}
if (!is.null(styles[["fontsize"]])) {
n <- sprintf("<span style='font-size:%s'>%s</span>", styles[["fontsize"]], n)
}
n
}
50 changes: 50 additions & 0 deletions R/style_string.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
style_string_html <- function(n, styles) {
if (isTRUE(styles[["italic"]])) {
n <- sprintf("<i>%s</i>", n)
}
if (isTRUE(styles[["strikeout"]])) {
n <- sprintf("<s>%s</s>", n)
}
if (isTRUE(styles[["underline"]])) {
n <- sprintf("<u>%s</u>", n)
}
if (isTRUE(styles[["bold"]])) {
n <- sprintf("<b>%s</b>", n)
}
if (isTRUE(styles[["monospace"]])) {
n <- sprintf("<code>%s</code>", n)
}
if (!is.null(styles[["color"]])) {
n <- sprintf("<span style='color:%s'>%s</span>", styles[["color"]], n)
}
if (!is.null(styles[["fontsize"]])) {
n <- sprintf("<span style='font-size:%sem'>%s</span>", 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
}
6 changes: 5 additions & 1 deletion R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 478c2fc

Please sign in to comment.