r-lib / cli

Tools for making beautiful & useful command line interfaces
https://cli.r-lib.org/
Other
655 stars 70 forks source link

Styling is preserved in HTML output, but not supported #702

Closed jonocarroll closed 4 months ago

jonocarroll commented 4 months ago

I recently noticed that the RSS feed for my (blogdown) blog was broken producing an error

XML parsing error: <unknown>:246:53: not well-formed (invalid token) 

&lt;pre class=&#34;bg-success&#34;&gt;&lt;code&gt;## ─ Session info ...

This comes from a devtools::session_info() block I include at the end of all my posts, which ended up being handy in identifying which package had changed between the last successfully rendered post and now.

In cli version 3.6.2 and prior I get

<details>
<summary>
<tt>devtools::session_info()</tt>
</summary>
<pre class="bg-success"><code>## ─ Session info ───────────────────────────────────────────────────────────────
##  setting  value
##  version  R version 4.3.3 (2024-02-29)
##  os       Pop!_OS 22.04 LTS
##  system   x86_64, linux-gnu
##  ui       X11
##  language (EN)
##  collate  en_AU.UTF-8
##  ctype    en_AU.UTF-8
##  tz       Australia/Adelaide
##  date     2024-05-29
##  pandoc   3.1.11 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/x86_64/ (via rmarkdown)
## 
## ─ Packages ───────────────────────────────────────────────────────────────────
##  package     * version date (UTC) lib source
##  blogdown      1.18    2023-06-19 [1] CRAN (R 4.3.2)
##  bookdown      0.36    2023-10-16 [1] CRAN (R 4.3.2)
##  bslib         0.6.1   2023-11-28 [3] CRAN (R 4.3.2)
##  cachem        1.0.8   2023-05-01 [3] CRAN (R 4.3.0)
##  callr         3.7.3   2022-11-02 [3] CRAN (R 4.2.2)
##  cli           3.6.2   2023-12-11 [3] CRAN (R 4.3.2)
[snip]

whereas with 3.6.3 I get

<details>
<summary>
<tt>devtools::session_info()</tt>
</summary>
<pre class="bg-success"><code>## [1m[36m─ Session info ───────────────────────────────────────────────────────────────[39m[22m
##  [3m[90msetting [39m[23m [3m[90mvalue[39m[23m
##  version  R version 4.3.3 (2024-02-29)
##  os       Pop!_OS 22.04 LTS
##  system   x86_64, linux-gnu
##  ui       X11
##  language (EN)
##  collate  en_AU.UTF-8
##  ctype    en_AU.UTF-8
##  tz       Australia/Adelaide
##  date     2024-07-05
##  pandoc   3.1.11 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/x86_64/ (via rmarkdown)
## 
## [1m[36m─ Packages ───────────────────────────────────────────────────────────────────[39m[22m
##  [3m[90mpackage    [39m[23m [3m[90m*[39m[23m [3m[90mversion[39m[23m [3m[90mdate (UTC)[39m[23m [3m[90mlib[39m[23m [3m[90msource[39m[23m
##  blogdown      1.18    [90m2023-06-19[39m [90m[1][39m [90mCRAN (R 4.3.2)[39m
##  bookdown      0.36    [90m2023-10-16[39m [90m[1][39m [90mCRAN (R 4.3.2)[39m
##  bslib         0.6.1   [90m2023-11-28[39m [90m[3][39m [90mCRAN (R 4.3.2)[39m
##  cachem        1.0.8   [90m2023-05-01[39m [90m[3][39m [90mCRAN (R 4.3.0)[39m
##  callr         3.7.3   [90m2022-11-02[39m [90m[3][39m [90mCRAN (R 4.2.2)[39m
##  cli           3.6.3   [90m2024-06-21[39m [90m[1][39m [90mCRAN (R 4.3.3)[39m
[snip]

Do I need to wrap this somehow, or is this an issue with cli?

Removing the <tt> tag around this output does not resolve the issue.

jonocarroll commented 4 months ago

On further inspection, rolling back to cli 3.6.2 did not resolve the issue, but I'm struggling to find where it came from.

gaborcsardi commented 4 months ago

This is possibly coming from something in your setup. Is it in a terminal or some editor or IDE? Check if you set some options or environment variables in your startup files.

jonocarroll commented 4 months ago

I'm building the site within RStudio, and don't think I've changed any options. I have very few set, all namespaced.

What's particularly odd is that I still get the control codes in the rendered output with

```{r sessionInfo, echo = FALSE}
withr::with_options(list(cli.num.colors=1), devtools::session_info()) 
```

despite this showing entirely unstyled output at the console. Same for cli.ansi=FALSE and NO_COLOR=1...

I may just be going insane.

gaborcsardi commented 4 months ago

The option is called cli.num_colors with an underscore. NO_COLOR is an environment variable, not an option.

jonocarroll commented 4 months ago

Facepalm on my part for those, but unfortunately even using them properly (via {withr}) didn't help. A test .Rmd seems to do the same if I knit with the button in RStudio, but not if I render() in RStudio or positron.

I have been using the RStudio daily builds, and believe it or not, updating RStudio to the latest daily fixed the issue. I have no idea what was actually wrong (an overriding env var somewhere?).

Apologies for the noise.