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

Vendor GitHub css #469

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions R/reprex_render.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,18 @@ reprex_render_impl <- function(input,

# heavily influenced by the post_processor() function of github_document()
preview <- function(input) {
mode <- if (is_dark_mode()) "dark" else "light"
css <- rmarkdown::pandoc_path_arg(
path_package(
"rmarkdown",
"rmarkdown/templates/github_document/resources/github.css"
"reprex",
glue("rmarkdown/templates/reprex_document/resources/github-{mode}.css")
)
)
css <- glue("github-markdown-css:{css}")
template <- rmarkdown::pandoc_path_arg(
path_package(
"rmarkdown",
"rmarkdown/templates/github_document/resources/preview.html"
"reprex",
"rmarkdown/templates/reprex_document/resources/preview.html"
)
)
args <- c(
Expand Down
9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@
is_testing <- function() {
identical(Sys.getenv("TESTTHAT"), "true")
}

is_dark_mode <- function() {
if (rstudioapi::isAvailable() && rstudioapi::hasFun("getThemeInfo")) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once posit-dev/positron#2986 is handled, the full glory of this PR will apply in Positron.

theme_info <- rstudioapi::getThemeInfo()
theme_info$dark

Check warning on line 70 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L69-L70

Added lines #L69 - L70 were not covered by tests
} else {
FALSE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until posit-dev/positron#2986 happens, Positron will always get reprex previews in light mode, but this is still an improvement over what's happening now.

Before this PR:

Screenshot 2024-09-03 at 9 47 59 PM

After this PR:

Screenshot 2024-09-03 at 9 46 47 PM

}
}
18 changes: 18 additions & 0 deletions data-raw/github-css.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# use the CSS found here:
# https://github.com/sindresorhus/github-markdown-css
# which aims to be:
# "The minimal amount of CSS to replicate the GitHub Markdown style"

library(usethis)

use_github_file(
repo_spec = "sindresorhus/github-markdown-css",
path = "github-markdown-dark.css",
save_as = "inst/rmarkdown/templates/reprex_document/resources/github-dark.css"
)

use_github_file(
repo_spec = "sindresorhus/github-markdown-css",
path = "github-markdown-light.css",
save_as = "inst/rmarkdown/templates/reprex_document/resources/github-light.css"
)
Loading
Loading