Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom theme styles ignored when all styled content is interpolated #748

Open
dgkf opened this issue Feb 7, 2025 · 1 comment
Open

custom theme styles ignored when all styled content is interpolated #748

dgkf opened this issue Feb 7, 2025 · 1 comment
Labels
bug an unexpected problem or unintended behavior

Comments

@dgkf
Copy link

dgkf commented Feb 7, 2025

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.

@gaborcsardi
Copy link
Member

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

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants