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

Peculiar styling of messages in example output #79

Closed
jennybc opened this issue Mar 9, 2021 · 4 comments
Closed

Peculiar styling of messages in example output #79

jennybc opened this issue Mar 9, 2021 · 4 comments

Comments

@jennybc
Copy link
Member

jennybc commented Mar 9, 2021

I can't figure out how downlit is deciding to show some messages in bold and not others.

I'm seeing this in the googlesheets4 examples. Here are few examples as of tidyverse/googlesheets4@9309c2a

Probably relevant: googlesheets4 is using cli (therefore rlang::inform()) for messages now.

The basic pattern is: the first googlesheets4 message is bold, but no others.

Messages originating elsewhere, presumably coming via message() are ?always? bold. ("Files trashed..." is always coming from googledrive, for example).

Below is a sampler.


https://googlesheets4.tidyverse.org/reference/range_read.html#examples

tidyverse/googlesheets4@9309c2a#diff-c089033b92eaa2e50242f2188feedb0d449c5fd93c1765301867ee1c9bb1ae39

Screen Shot 2021-03-08 at 4 14 09 PM


https://googlesheets4.tidyverse.org/reference/range_speedread.html#examples

tidyverse/googlesheets4@9309c2a#diff-c755ed40978311fdb955d656db19f8477496e343ec19095b0cfcf64716ca26ec

Screen Shot 2021-03-08 at 4 16 25 PM


https://googlesheets4.tidyverse.org/reference/sheet_write.html

tidyverse/googlesheets4@9309c2a#diff-19e7740a2d283dc1311c374e0bb4b937e9a904f3dbef7acb84432b9053abff3f

Screen Shot 2021-03-08 at 4 19 25 PM

@cderv
Copy link
Contributor

cderv commented Mar 9, 2021

Just sharing what I saw yesterday when the question was ask.

pkgdown is setting a CSS for not of class message: https://github.com/r-lib/pkgdown/blob/dd94073575aaee2fd480892d24dfe0be85f81a03/inst/assets/pkgdown.css#L308

.message { color: black;   font-weight: bolder;}

This seem to lead to the bold text.

About not everything is bold : downlit does not seem to produce valid HTML in this case: the closing </span> for class message is not at the right place.

See below,

  • With message we correctly get </span></div>
  • Using gs4_success, we get </div></span> which is not correct because it opens with <div class='output co'><span class='message'>.
    This could lead the browser to not auto correct the same on the first line and other lines, hence the difference seen.
> extract_output_part <- function(html) {
+     s <- stringr::str_locate(html, "<div class='output co'>")[, "start"]
+     stringr::str_sub(html, s)
+ }
> 
> html1 <- downlit::evaluate_and_highlight('message("a")')
> extract_output_part(html1)
[1] "<div class='output co'>#&gt; <span class='message'>a</span></div>"
> 
> html2 <- downlit::evaluate_and_highlight('googlesheets4:::gs4_success("a")')
> extract_output_part(html2)
[1] "<div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>v</span><span> a</span></div></span>"

I can't do a reprex above because this does not happens inside reprex::reprex() call - not interactive session ?

extract_output_part <- function(html) {
  s <- stringr::str_locate(html, "<div class='output co'>")[, "start"]
  stringr::str_sub(html, s)
}

html1 <- downlit::evaluate_and_highlight('message("a")')
extract_output_part(html1)
#> [1] "<div class='output co'>#&gt; <span class='message'>a</span></div>"

html2 <- downlit::evaluate_and_highlight('googlesheets4:::gs4_success("a")')
extract_output_part(html2)
#> [1] "<div class='output co'>#&gt; <span class='message'>v a</span></div>"

Created on 2021-03-09 by the reprex package (v1.0.0.9002)

Hope it helps.

@hadley
Copy link
Member

hadley commented Apr 27, 2021

Somewhat more minimal reprex:

library(downlit)

f <- function() cli::cli_alert_danger("x")
cat(evaluate_and_highlight("f()"))
#> <div class='input'><span class='fu'>f</span><span class='op'>(</span><span class='op'>)</span></div><div class='output co'>#&gt; <span class='message'>x x</span></div>

Created on 2021-04-27 by the reprex package (v2.0.0)

@hadley
Copy link
Member

hadley commented Apr 27, 2021

Even simpler reprex:

x <- "<div>\033[31mx\033[39m y</div>"
fansi::sgr_to_html(x)
#> [1] "<div><span style='color: #BB0000;'>x</span><span> y</div></span>"

Created on 2021-04-27 by the reprex package (v2.0.0)

@hadley hadley closed this as completed in 2513e65 Apr 27, 2021
@hadley
Copy link
Member

hadley commented Apr 27, 2021

@jennybc this makes the output consistent, but consistently bold. Removing the bold in r-lib/pkgdown#1644 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants