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

find_external_resources works with custom format using theme #2494

Merged
merged 2 commits into from
Jun 9, 2023

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented Jun 9, 2023

This is fixing #2493 in a quite scoped manner.

This PR account for error when resolve_theme() is used in finding resources step.
Some custom theme could use the theme configuration in other context that bslib theming detection. However, resolve_theme() is an internal function to detect if this is a bslib theme, and css should be copied as resource for rendering in another folder.

We consider that an error means theme is not what rmarkdown's format expect it to be (either a vector of string, or a non built-in boostrap 3 theme), this is indeed not a bslib and we should not copy CSS.

@yihui just adding you as reviewer, if you happen to pass around here. I'll merge it otherwise as I know you are travelling

… step

Some custom theme could use the `theme` configuration in other context that bslib theming detection.

We consider that if there is an error  (meaning `theme` are not what rmarkdown's format expect it to be), this is indeed not bslib
@cderv cderv requested review from yihui and gadenbuie June 9, 2023 10:10
Copy link
Member

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

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

This seems like a good fix to me! It's unfortunate that resolve_theme() is tightly coupled with the themes provided by html_document() (i.e. Bootstrap themes) (I'd even recommend renaming it resolve_bs_theme() or resolve_base_theme(), but understand if that's out of scope).

That said, this seems like a reasonable compromise to tryCatch(resolve_theme()) in discover_rmd_resources(), since that use of resolve_theme() part of what's pushing the function out of its original purpose.

@cderv
Copy link
Collaborator Author

cderv commented Jun 9, 2023

It's unfortunate that resolve_theme() is tightly coupled with the themes provided by html_document() (i.e. Bootstrap themes) (I'd even recommend renaming it resolve_bs_theme() or resolve_base_theme(), but understand if that's out of scope).

I am open to make adaption to this. It was introduce specifically for bslib support, but if it can be useful to different purpose we can make adaptation. I am curious of what you have in mind (is this for your theme handling in cleanrmd ?)

It is an internal function for now, so quite open to change IMO.

That said, this seems like a reasonable compromise to tryCatch(resolve_theme()) in discover_rmd_resources(), since that use of resolve_theme() part of what's pushing the function out of its original purpose.

That is exactly what I was thinking. Other idea was to add an argument in resolve_theme(..., check_supported = TRUE) than when set to FALSE not do the match.arg check that we added for more use friendly error when providing a non supported Bootstrap theme.

@gadenbuie
Copy link
Member

gadenbuie commented Jun 9, 2023

I like both ideas! After reading more about how these functions are used I think:

  1. resolve_theme() should be named resolve_bs_theme()
  2. themes() should be named bs_themes()
  3. resolve_theme() should have the check_supported argument you proposed to avoid failing in non-critical code paths, like discover_rmd_resources()

Those updates wouldn't change the behavior, but I do think it would make the code easier to read and understand in the future 😃

@cderv
Copy link
Collaborator Author

cderv commented Jun 9, 2023

I'll go with this fix for now, and think more about renaming the function. I feel tryCatch here is correctly align with what we expect when using resolve_theme() in discover_rmd_resources context.

@cderv cderv changed the title Do not error with find_external_resources on custom format using their own theme find_external_resources works with custom format using theme Jun 9, 2023
@cderv cderv merged commit e499bf7 into main Jun 9, 2023
@cderv cderv deleted the fix/find-resource-custom-formats branch June 9, 2023 14:27
jonathan-g added a commit to jonathan-g/rmarkdown that referenced this pull request Aug 16, 2023
* rstudio/main:
  start the next version
  CRAN release v2.24
  shinyrmd: Safer dependency extraction from pre-rendered HTML (rstudio#2500)
  quote the version number per CRAN's request
  Add output_format_dependency() (rstudio#2462)
  file_scope is now correctly merged when creating output_format (rstudio#2488)
  Correctly run some tests only on CI
  start the next version
  CRAN release v2.23
  remove broken links
  suggest cleanrmd for e499bf7
  add news
  comparing version numbers with numbers is no longer allowed: https://bugs.r-project.org/show_bug.cgi?id=18548
  `find_external_resources` works with custom format using `theme` (rstudio#2494)
  start the next version
  CRAN release v2.22
  S3 generic/method consistency
  Change the code-folding button text from "Code" to "Show" (rstudio#2489)
  fix: bump jquery-ui to v1.13.2 to fix multiple CVEs (rstudio#2477)
  detecting external resources needs to consider css argument (rstudio#2486)
jonathan-g added a commit to jonathan-g/rmarkdown that referenced this pull request Aug 16, 2023
Merge remote-tracking branch 'rstudio/main' into jg-devel

# By Yihui Xie (13) and others
# Via Yihui Xie
* rstudio/main:
  start the next version
  CRAN release v2.24
  shinyrmd: Safer dependency extraction from pre-rendered HTML (rstudio#2500)
  quote the version number per CRAN's request
  Add output_format_dependency() (rstudio#2462)
  file_scope is now correctly merged when creating output_format (rstudio#2488)
  Correctly run some tests only on CI
  start the next version
  CRAN release v2.23
  remove broken links
  suggest cleanrmd for e499bf7
  add news
  comparing version numbers with numbers is no longer allowed: https://bugs.r-project.org/show_bug.cgi?id=18548
  `find_external_resources` works with custom format using `theme` (rstudio#2494)
  start the next version
  CRAN release v2.22
  S3 generic/method consistency
  Change the code-folding button text from "Code" to "Show" (rstudio#2489)
  fix: bump jquery-ui to v1.13.2 to fix multiple CVEs (rstudio#2477)
  detecting external resources needs to consider css argument (rstudio#2486)

# Conflicts:
#	DESCRIPTION
jonathan-g added a commit to jonathan-g/rmarkdown that referenced this pull request Aug 16, 2023
* jg-devel: (21 commits)
  Updated NEWS. Patched `merge_output_format_dependency` to ensure that named elements remain in the correct order.
  start the next version
  CRAN release v2.24
  shinyrmd: Safer dependency extraction from pre-rendered HTML (rstudio#2500)
  quote the version number per CRAN's request
  Add output_format_dependency() (rstudio#2462)
  file_scope is now correctly merged when creating output_format (rstudio#2488)
  Correctly run some tests only on CI
  start the next version
  CRAN release v2.23
  remove broken links
  suggest cleanrmd for e499bf7
  add news
  comparing version numbers with numbers is no longer allowed: https://bugs.r-project.org/show_bug.cgi?id=18548
  `find_external_resources` works with custom format using `theme` (rstudio#2494)
  start the next version
  CRAN release v2.22
  S3 generic/method consistency
  Change the code-folding button text from "Code" to "Show" (rstudio#2489)
  fix: bump jquery-ui to v1.13.2 to fix multiple CVEs (rstudio#2477)
  ...
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource detection is broken for custom format using an overwrite of theme argument
2 participants