cli
cli copied to clipboard
custom theme styles ignored when all styled content is interpolated
some custom theme properties seem to only take effect if there is some raw text in the rendered content, ignored otherwise.
cli::cli_div(theme = list(
".example" = list(
"background-color" = "red", # BUG?
"font-weight" = "bold", # GOOD
fmt = \(x) { cat("formatting:", x, "\n"); x }, # BUG?
transform = \(x) { cat("transforming:", x, "\n"); x } # BUG?
)
))
# GOOD: bold, background, transform, fmt
cli::cli_text("{.example abc}")
#> transforming: abc
#> formatting: abc
#> abc
# GOOD: bold, italics; BUG?: no background, transform, fmt
cli::cli_text("{.example {.emph abc}}")
#> abc
# GOOD: bold, italics, background, transform, fmt
cli::cli_text("{.example abc{.emph def}}")
#> transforming: abcdef
#> formatting: abcdef
#> abcdef
font-weight applies regardless, while the background-color, transform and fmt only apply if there exists some non-interpolated text in the span.
Unfortunately the parsing in cli is kind of ad-hoc currently, and pretty hard to improve without losing compatibility. Nevertheless I am planning on improving it the next time I work on cli.
Btw. interestingly the opposite order seems to work:
cli::cli_text("{.emph {.example abc}}")
#> transforming: abc
#> formatting: abc
#> abc