Skip to content

detecting external resources needs to consider css argument - #2486

Merged
cderv merged 10 commits into
mainfrom
fix/resource-discovery-bslib
May 17, 2023
Merged

cderv merged 10 commits into
mainfrom
fix/resource-discovery-bslib

Conversation

@cderv

@cderv cderv commented May 17, 2023

Copy link
Copy Markdown
Collaborator

This is because css can be processed by bslib in pre_knit and/or pre_processor, including when rendering md file in temp directory

Closes #2443
Closes #2447

The real issue is not with shiny, but rather how renders and resource discovery works when intermediates_dir is passed, and when it is another directory. This happens with shiny rendering but could happen in other situations too, not even just when intermediates is a temp directory.

Error without shiny example
  • Markdown file
---
title: "Title"
output:
  html_document:
    css: styles.scss
    theme: darkly
---

### Another title

```{r}
xfun::file_string("README.md")
```
  • scss file
body {background-color: purple;}

** rendering

> tmp <- tempfile(); rmarkdown::render("test.Rmd", intermediates_dir = tmp, output_dir = tmp)
Error in `sass::sass_file()`:
! Could not find file: 'styles.scss' in dir: C:/Users/chris/AppData/Local/Temp/RtmpcPUFmU
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `sass::sass_file()`:
! Could not find file: 'styles.scss' in dir: C:/Users/chris/AppData/Local/Temp/RtmpcPUFmU
---
Backtrace:
     ▆
  1. └─rmarkdown::render("test.Rmd", intermediates_dir = tmp, output_dir = tmp)
  2.   └─output_format$intermediates_generator(original_input, intermediates_dir) at rmarkdown/R/render.R:516:4
  3.     └─rmarkdown:::copy_render_intermediates(...) at rmarkdown/R/html_document_base.R:159:4
  4.       └─rmarkdown::find_external_resources(original_input) at rmarkdown/R/html_resources.R:404:2
  5.         └─rmarkdown:::discover_rmd_resources(input_file, discover_single_resource) at rmarkdown/R/html_resources.R:108:4
  6.           └─rmarkdown::render(...) at rmarkdown/R/html_resources.R:339:2
  7.             └─output_format$pre_processor(...) at rmarkdown/R/render.R:845:6
  8.               └─rmarkdown (local) base(...) at rmarkdown/R/output_format.R:126:6
  9.                 ├─sass::sass(...) at rmarkdown/R/html_document_base.R:103:8
 10.                 │ └─sass::as_sass(input)
 11.                 │   ├─htmltools::attachDependencies(...)
 12.                 │   │ └─htmltools:::asDependencies(value)
 13.                 │   └─sass:::find_dependencies(input)
 14.                 │     └─sass:::is_sass_bundle_like(x)
 15.                 │       └─sass::is_sass_bundle(x)
 16.                 └─sass::sass_file(f)

It would happen with tmp <- "dummy" too.

This happens in our finding resources processing, because we render to an .md file in a temp directory, and we need to move the resource in this temp folder at this time. css or scss could be processed by bslib or sass in pre_knit and/or pre_processor, including when rendering md file in temp directory. We need to account for this.

@cpsievert this PR closes #2448 without merging as this is a broader fix, even when shiny is not used.

@cderv

cderv commented May 17, 2023

Copy link
Copy Markdown
Collaborator Author

Comment thread R/html_resources.R Resolved
cderv and others added 2 commits May 17, 2023 20:47
[skip ci]
@cderv cderv changed the title detecting external resources needs to consider css argument in output_format detecting external resources needs to consider css argument May 17, 2023
@cderv
cderv merged commit 58ca4df into main May 17, 2023
@cderv
cderv deleted the fix/resource-discovery-bslib branch May 17, 2023 20:56
j-magnolia pushed a commit to j-magnolia/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)
j-magnolia pushed a commit to j-magnolia/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
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Archived in project

2 participants