inline-markup: CLI inline markup

Description Command substitution Classes Examples

Description

CLI inline markup

Command substitution

All text emitted by cliapp supports glue interpolation. Expressions enclosed by braces will be evaluated as R code. See glue::glue() for details.

In addition to regular glue interpolation, cliapp can also add classes to parts of the text, and these classes can be used in themes. For example

1
cli_text("This is {emph important}.")

adds a class to the "important" word, class "emph". Note that in this cases the string within the braces is not a valid R expression. If you want to mix classes with interpolation, add another pair of braces:

1
2
adjective <- "great"
cli_text("This is {emph {adjective}}.")

An inline class will always create a span element internally. So in themes, you can use the span.emph CSS selector to change how inline text is emphasized:

1
2
3
cli_div(theme = list(span.emph = list(color = "red")))
adjective <- "nice and red"
cli_text("This is {emph {adjective}}.")

Classes

The default theme defines the following inline classes:

See examples below.

You can simply add new classes by defining them in the theme, and then using them, see the example below.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Some inline markup examples
cli_ul()
cli_it("{emph Emphasized} text")
cli_it("{strong Strong} importance")
cli_it("A piece of code: {code sum(a) / length(a)}")
cli_it("A package name: {pkg cliapp}")
cli_it("A function name: {fun cli_text}")
cli_it("A function argument: {arg text}")
cli_it("A keyboard key: press {key ENTER}")
cli_it("A file name: {file /usr/bin/env}")
cli_it("An email address: {email bugs.bunny@acme.com}")
cli_it("A URL: {url https://acme.com}")
cli_it("A variable name: {var mtcars}")
cli_it("An environment variable: {envvar R_LIBS}")
cli_end()

## Adding a new class
cli_div(theme = list(
  span.myclass = list(color = "lightgrey"),
  "span.myclass::before" = list(content = "["),
  "span.myclass::after" = list(content = "]")))
cli_text("This is {myclass in brackets}.")
cli_end()

cliapp documentation built on Oct. 23, 2020, 6:36 p.m.