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

Allow lib_dir not to be a descendant of the base directory for documents derived from html_document_base #2199

Open
wants to merge 67 commits into
base: main
Choose a base branch
from

Conversation

jonathan-g
Copy link
Contributor

@jonathan-g jonathan-g commented Aug 7, 2021

This PR addresses the issues raised in #146 and #1859.

It's a somewhat big PR, but a lot of the changes are documentation for the new functionality and a couple of testthat tests
to make sure it works properly.

Changes introduced in this PR:

  • Introduce a new argument allow_uptree_lib_dir to html_document_base() that turns on new functionality in handling
    HTML dependencies, so lib_dir does not need to be a descendant of the base directory.
    • This can be a function argument or a parameter in the output block of the YAML header in a .md or .Rmd file.
    • This should work for any HTML format that uses html_document_base.
  • Add functions to html_dependencies.R to implement the new functionality.
  • Add documentation of the new functionality
    • The principal documentation is in a new section on directory structures in html_document.
  • Add testthat tests for new functionality.

The reason for requiring a new argument/parameter for enabling this functionality is because I'm a bit paranoid about
accidentally breaking anything that depends on the old behavior, which would throw an error if lib_dir was not a descendant
of the base direcctory.

Anyone who wants to install the rmarkdown package with this PR applied can do so by installing from my fork: remotes::install_github("jonathan-g/rmarkdown", ref="jg-tree-fix"). I try to keep my PR fork up to date with the main branch in this repository.

jonathan-g and others added 30 commits January 11, 2020 20:21
Merge RStudio version into my fork.
* rstudio/master: (61 commits)
  make metadata available before running pre_knit (rstudio#1855)
  fix rstudio#1815: apply the lua filters pagebreak.lua and latex-div.lua to beamer_presentation
  require the data-latex attribute on fenced Div's again: rstudio#1779 (comment)
  start the next version
  CRAN release v2.3
  fold any code blocks with the class `foldable` for html_document output (rstudio#1835)
  fix rstudio#1828: add aria-hidden = "true" to empty <a> tags in highlighted code blocks generated by Pandoc to improve screen reader accessibility (rstudio#1833)
  add a news item for rstudio#1832
  roxygenize
  no need to turn on --file-scope or actually write the split content into files if the split content is of length < 2
  eliminate renumber_footnotes option
  only test two pandoc versions (devel and RStudio version) and upgrade default to 2.7.3 (rstudio#1846)
  close rstudio#1838: test more R versions on Travis (rstudio#1845)
  renumber_footnotes output format option
  add the <div class="kable-table"> only when the output format is HTML, otherwise the div will be converted to a LaTeX environment, leading to the bug https://stackoverflow.com/q/62340425/559676
  change name of file_scope argument to references_scope
  re-roxygenize
  Add `publish_site()` function for "one-button" publishing of R Markdown websites.
  Enable use of pandoc --file-scope for input files originating from multiple Rmds (rstudio#1837)
  Added missing lang attribute to ioslides_presentation template (rstudio#1841)
  ...
…ry in common, where shared CSS, JS, etc. are located.
Under Windows, rmarkdown sends "css" arguments from YAML front matter to pandoc using Windows-style backslashes as path separators. Pandoc then passes these backslashes to the "`href`" field in a `<link rel="stylesheet" type="text/css" />` tag. This commit fixes that behavior to use forward slashes even under Windows.
* tree-root:
  Fix incorrect version number in DESCRIPTION.
  Add a fix to header-attrs.js. It wasn't picking up on sections using a div.section selector.
  Update version to keep this distinct from the official github version.
  Add informative comment to html_document_base.R
  Passes checks with no errors, warnings, or notes.
  Remove debugging code.
  Clean up debugging code from html_dependencies.R and add some comments explaining the new functions.
  Allow multiple Rmd files in child directories to share a master library in common, where shared CSS, JS, etc. are located.
Bring up to date with RStudio version.
Merge branch 'master' into jg-devel

* master:
  tweak news
  require Pandoc >= 1.14
  xfun 0.16 is on CRAN now
  replace base64enc with xfun::base64_encode/decode()
  support number_sections for word_document() output (rstudio#1869)

# Conflicts:
#	DESCRIPTION
* master:
  Added documentationn of how the output_format argument to render() processes YAML output parameters.
Update to reference this pull request in NEWS.md
* rstudio_origin/master:
  fix rstudio#1905: a chunk with the class "fold-hide" should only hide itself (rstudio#1906)
  bump version after merging rstudio#1899
  lua filter -> Lua filter
  Add an argument `lua_filters` to pandoc_options() to store them in the output format object (rstudio#1899)
  recursve into the parent dir at the end
  also suppor dir input in proj_root()
  list.files() with full.names = TRUE (so the files could be read with corret paths), and pass down the `file`/`pattern` arguments in the recursion
  use our own proj_root() instead of introducing a dependency
  rename package_root() to proj_root()
  generalize the package_root() function to work with more types of projects
  Discover site generators in index.Rmd files in parent directories (rstudio#1898)
  only install pkgdown for website build (rstudio#1900)
  Generalize number sections (rstudio#1879)
  enable figure cropping in pdf_document() only when both pdfcrop and ghostscript are found (yihui/knitr#954), and do not limit this feature to non-Windows platforms
  add the citation entry for the R Markdown Cookbook
  add lua filter vignette to pkgdown website (rstudio#1894)
  close rstudio#1889: evaluate the output argument before changing working directory in pandoc_convert() (rstudio#1890)
Merge branch 'master' of https://github.com/rstudio/rmarkdown

* 'master' of https://github.com/rstudio/rmarkdown: (111 commits)
  get rid of names, otherwise the returned vector will have names like this:
  Only run testrmd if pandoc is available
  Warn that cropping is disabled if pdfcrop or ghostscript are not found. (rstudio#2017)
  Add shiny to remotes (rstudio#2014)
  file.path.ci is too loose with file matching (rstudio#2012)
  improve error messages for the new theme argument behavior
  Add Bootstrap 4 support (rstudio#1706)
  amend rstudio#1965: do not force `options(htmltools.preserve.raw = TRUE)` when this option has been set, otherwise it is impossible for other packages to turn this option off, e.g., yihui/xaringan#293
  htmltools 0.5.1 is on CRAN now
  remove download stats
  use on.exit to remove file (rstudio#2001)
  use only the TinyTeX-1 version in CI (rstudio#1998)
  Cache should work on Windows with recent version of R (rstudio#1997)
  exclude renv folder from render_site() copied resources (rstudio#1996)
  Update CI to last Pandoc 2.11.3.1 (rstudio#1992)
  Revert "return div not nil for non-qualifying latex div"
  Add missing NEWS item for v2.6 release
  return div not nil for non-qualifying latex div
  Add `output_format_filter` function to `default_site_generator()`. (rstudio#1989)
  Improvements to latex-div (rstudio#1984)
  ...

# Conflicts:
#	NEWS.md
#	R/render.R
#	man/render.Rd
* master: (111 commits)
  get rid of names, otherwise the returned vector will have names like this:
  Only run testrmd if pandoc is available
  Warn that cropping is disabled if pdfcrop or ghostscript are not found. (rstudio#2017)
  Add shiny to remotes (rstudio#2014)
  file.path.ci is too loose with file matching (rstudio#2012)
  improve error messages for the new theme argument behavior
  Add Bootstrap 4 support (rstudio#1706)
  amend rstudio#1965: do not force `options(htmltools.preserve.raw = TRUE)` when this option has been set, otherwise it is impossible for other packages to turn this option off, e.g., yihui/xaringan#293
  htmltools 0.5.1 is on CRAN now
  remove download stats
  use on.exit to remove file (rstudio#2001)
  use only the TinyTeX-1 version in CI (rstudio#1998)
  Cache should work on Windows with recent version of R (rstudio#1997)
  exclude renv folder from render_site() copied resources (rstudio#1996)
  Update CI to last Pandoc 2.11.3.1 (rstudio#1992)
  Revert "return div not nil for non-qualifying latex div"
  Add missing NEWS item for v2.6 release
  return div not nil for non-qualifying latex div
  Add `output_format_filter` function to `default_site_generator()`. (rstudio#1989)
  Improvements to latex-div (rstudio#1984)
  ...
Merge remote-tracking branch 'rstudio_origin/master' into jg-devel

* rstudio_origin/master: (26 commits)
  Use data-external=1 to prevent encoding by Pandoc of img src
  add `subdirs` documentation for site generator (rstudio#2058)
  fix: corrected typo in `ghostscript` (rstudio#2059)
  Add CoC contact email
  quillt has moved to rstudio/quillt
  fix invalid HTML code in shiny_prerendered documents (rstudio#1942)
  Allow pkgdown PR preview (rstudio#2055)
  Adding pkgdown site built by GHA (rstudio#1955)
  Add shiny bslib dependency inside html_document_base pre-process (rstudio#2049)
  start the next version
  CRAN release v2.7
  place <div> in \code{}
  amend 62ae2ed and rstudio#1989: make sure output_format_filter is a function; testing NULL is not enough, e.g., the radix package still calls
  use CRAN releases of shiny and bslib
  tweak news
  Only keep the first url in citation  (rstudio#2041)
  Fix for knit_print.data.frame (rstudio#2050)
  set gfm_auto_identifiers to input format if toc is TRUE (rstudio#2040)
  Enable pkgdown/downlit cross-package links to rmarkdown (rstudio#1843)
  update CONTRIBUTING.md
  ...

# Conflicts:
#	DESCRIPTION
Merge remote-tracking branch 'rstudio_origin/master' into jg-devel

* rstudio_origin/master: (64 commits)
  start the next version
  CRAN release v2.9
  fix rstudio#2163: do not normalize web paths in the css argument of html output formats (rstudio#2164)
  Add a css file for future tests
  Restore previous shiny theme when run() exits (rstudio#2160)
  Correct name in workflow file
  Add a workflow to test Pandoc nighly (rstudio#2153)
  bslib 0.2.5.1 is now on CRAN
  use `stop2()` from knitr internal instead of `stop(..., call. = FALSE)` (rstudio#2152)
  74e2f2f changed the error message, and a test relies on the content of this message (it probably shouldn't be so specific)
  tweak wording
  Support 'href' dependencies (rstudio#2151)
  Loop correctly on splitted file by file_scope function (rstudio#2150)
  update snapshot file following change in test name in a8aad75
  amend 84ff469: clarify the meaning of fig_crop = 'auto' in the doc
  Add the position of the last character (rstudio#2146)
  don't put the checklist in the comment since it is required
  Fix for lost encoding in shiny_prerendered_html. (rstudio#2140)
  Insure fontawesome V4 compatibility in navbar (rstudio#1994)
  fix rstudio#2043: replace parse(text) with xfun::parse_only() to avoid hanging the R session when the input is empty
  ...

# Conflicts:
#	DESCRIPTION
#	R/html_dependencies.R
@ma-riviere
Copy link

Is there any ETA for this (awesome) update ?

@jonathan-g
Copy link
Contributor Author

Is there any ETA for this (awesome) update ?

We must be patient, because it takes time and effort to review a PR.

This one ended up larger than I had expected: The basic code is small, but I added documentation and unit tests, and those ended up much larger than the new code. I think it's worth the extra lines to document the changes and to add tests to make sure they work and don't break other parts of rmarkdown. But this makes the PR larger, and adds to the time and effort it will take to review it, so we must be patient.

In the meantime, while we are waiting for this to be reviewed and a decision to be made about whether to accept the PR, you can always install a version of rmarkdown that includes this change via remotes::install_github("jonathan-g/rmarkdown", ref="jg-tree-fix"). I am actively keeping the PR branch of my code up to date with new commits on the main branch of rmarkdown, so it should always be approximately up to date with the latest version of rmarkdown, but with the added functionality.

@ma-riviere
Copy link

Thank you for your reply, and for your work on this issue !

I'm eagerly waiting for this update to better structure / factorize my slides & reports' code. In the meantime, I'll give your branch a try 😄

Merge remote-tracking branch 'rstudio_origin/main' into jg-tree-fix

# By Christophe Dervieux (2) and Yihui Xie (1)
# Via Christophe Dervieux
* rstudio_origin/main:
  Add class to book cover to size using CSS
  fix the syntax highlighting of |> in LaTeX/PDF output: rstudio/bookdown#1157 (rstudio#2228)
  Add an option to opt-out the header-attrs HTML dependency in `html_document_base()` (rstudio#2227)

# Conflicts:
#	NEWS.md
* rstudio_origin/main:
  Use latest Pandoc  in GHA and update workflow (rstudio#2244)
Merge remote-tracking branch 'rstudio_origin/main' into jg-tree-fix

* rstudio_origin/main:
  Add Config/Needs/website key
  Update GHA following v2 tag in r-lib/actions (rstudio#2260)

# Conflicts:
#	DESCRIPTION
@cderv cderv linked an issue Jan 7, 2022 that may be closed by this pull request
3 tasks
@cderv cderv self-assigned this Feb 11, 2022
jonathan-g and others added 9 commits March 14, 2022 00:55
Merge remote-tracking branch 'rstudio/main' into jg-tree-fix

# By Yihui Xie (5) and others
# Via Yihui Xie
* rstudio/main:
  refactor the code a little bit
  allow custom output format to define its own Markdown converting function, so that we could use other tools (not necessarily Pandoc)
  rewrap lines
  Add render() output_file argument repetition (rstudio#2422)
  start the next version
  CRAN release v2.17
  Vectorise str_replace_all() (rstudio#2416)
  Correctly load glyphicons in dropdown tabset
  add vscode lua config to gitignore
  Search also in `index.rmd` for `site:` key in YAML header (rstudio#2413)

# Conflicts:
#	NEWS.md
jonathan-g and others added 6 commits January 19, 2023 21:27
* rstudio/main:
  start the next version
  CRAN release v2.20
  make sure `ioslides_presentation` is properly self-contained when requested (rstudio#2428)
  More tests needs fixing
  Newer Pandoc (currently devel) fixes GFM toc previously written in HTML instead of Markdown
  make sure to avoid creating invalid paths when copying resources (rstudio#2429)
  Fix rstudio#1508: do not resolve input files that are symlinks (rstudio#2438)
Merge remote-tracking branch 'rstudio/main' into jg-tree-fix

* rstudio/main:
  Use the `fontawesome` package for the HTML dependency on Font Awesome (rstudio#2451)
  Ensure that rmarkdown::reneder() always returns invisibly (rstudio#2452)
  use knitr::is_latex_output() in case the output format name contains Pandoc extensions, e.g., `latex-smart`

# Conflicts:
#	NEWS.md
* rstudio/main: (25 commits)
  Add missing new param for the function collection
  re-document following fce12fb
  Remove no more needed YAML validation for ending :
  [ioslide] Only do the chcp setting with Pandoc before 2.0 (rstudio#2481)
  Add a `pandoc_metadata_file_arg` helper
  Add mention of webshot and webshot2 required for screenshot to be made
  start the next version
  CRAN release v2.21
  fix rstudio#2469: use all(is_blank()) for xfun 0.38
  Fix typo in error message
  Update CITATION.cff
  Fix GHA action regarding older pandoc (rstudio#2466)
  update citation workflow
  Update check pandoc daily
  Allow manual trigger of checks
  Bring back Pandoc version in workflow name
  Update lock workflow
  Prefer pak usage for dev version now
  Update GHA workflow
  adapt CITATION file
  ...
* 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)
* Patched `merge_output_format_dependency` to put
  named elements in the same order as the original.
@CLAassistant
Copy link

CLAassistant commented Aug 16, 2023

CLA assistant check
All committers have signed the CLA.

Merge remote-tracking branch 'rstudio/main' into jg-tree-fix

# Conflicts:
#	NEWS.md
Merge remote-tracking branch 'rstudio/main' into jg-tree-fix

* rstudio/main:
  Use new version of `has_crop_tools()` from knitr (rstudio#2532)
  some cosmetic changes
  use ignore.case = TRUE for regex functions instead of enumerating upper/lowercase letters
  Remove `stringr` dependency (rstudio#2530)
  Add a mention about required configuration when erroring about webshot and webshot2

# Conflicts:
#	NEWS.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

Enhancement: support for non-standard RMarkdown directory structures.
5 participants