make_styles | R Documentation |
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.
make_styles(classes, rgb.mix = diag(3))
classes |
a character vector of either 16, 32, or 512 class names. The
character vectors are described in |
rgb.mix |
3 x 3 numeric matrix to remix color channels. Given a N x 3
matrix of numeric RGB colors |
A character vector that can be used as the contents of a style sheet.
Other HTML functions:
html_esc()
,
in_html()
,
to_html()
## Generate some class strings; order matters
classes <- do.call(paste, c(expand.grid(c("fg", "bg"), 0:7), sep="-"))
writeLines(classes[1:4])
## 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])
## 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)
## Combine in a page with styles and display in browser
## Not run:
in_html(html, css=c(css0, css1))
## End(Not run)
## 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
## Not run:
in_html(html, css=c(css0, css2))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.