Skip to content

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

Open

Description

@dgkf

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.

Activity

  1. gaborcsardi commented on Feb 10, 2025

    @gaborcsardi
    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
  2. added
    bug
    on Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions