Given a set of class names, produce the CSS that maps them to the default
8-bit colors. This is a helper function to generate style sheets for use
in examples with either default or remixed fansi colors. In practice users
will create their own style sheets mapping their classes to their preferred
styles.
Usage
make_styles(classes, rgb.mix = diag(3))Arguments
- classes
a character vector of either 16, 32, or 512 class names. The character vectors are described in
to_html.- rgb.mix
3 x 3 numeric matrix to remix color channels. Given a N x 3 matrix of numeric RGB colors
rgb, the colors used in the style sheet will bergb %*% rgb.mix. Out of range values are clipped to the nearest bound of the range.
See also
Other HTML functions:
html_esc(),
in_html(),
to_html()
Examples
## Generate some class strings; order matters
classes <- do.call(paste, c(expand.grid(c("fg", "bg"), 0:7), sep="-"))
writeLines(classes[1:4])
#> fg-0
#> bg-0
#> fg-1
#> bg-1
## Some Default CSS
css0 <- "span {font-size: 60pt; padding: 10px; display: inline-block}"
## Associated class strings to styles
css1 <- make_styles(classes)
writeLines(css1[1:4])
#> .fg-0 {color: #000000;}
#> .bg-0 {background-color: #000000;}
#> .fg-1 {color: #800000;}
#> .bg-1 {background-color: #800000;}
## Generate SGR-derived HTML, mapping to classes
string <- "\033[43mYellow\033[m\n\033[45mMagenta\033[m\n\033[46mCyan\033[m"
html <- to_html(string, classes=classes)
writeLines(html)
#> <span class='bg-3'>Yellow</span>
#> <span class='bg-5'>Magenta</span>
#> <span class='bg-6'>Cyan</span>
## Combine in a page with styles and display in browser
if (FALSE) { # \dontrun{
in_html(html, css=c(css0, css1))
} # }
## Change CSS by remixing colors, and apply to exact same HTML
mix <- matrix(
c(
0, 1, 0, # red output is green input
0, 0, 1, # green output is blue input
1, 0, 0 # blue output is red input
),
nrow=3, byrow=TRUE
)
css2 <- make_styles(classes, rgb.mix=mix)
## Display in browser: same HTML but colors changed by CSS
if (FALSE) { # \dontrun{
in_html(html, css=c(css0, css2))
} # }