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

Add lua_filters to pandoc_options to expose them in the output_format #1899

Merged
merged 28 commits into from
Sep 22, 2020

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented Sep 14, 2020

This will partly resolves #1897 and this is needed for rstudio/bookdown#940 where we add a lua filter in bookdown.

Adding lua_filters to pandoc_options allows exposes the filters in the output format and that will allow to manipulate them to change the order or even remove some if a format use another as its base.

We need this in bookdown because we want to be sure to run the bookdown lua filter first.

Currenlty, the PR assumes lua filters are appended by default, i.e if a format depend on an other, the lua filter from the former will execute after the latter. We could consider to inverse this maybe: always run lua filter of a format before the filters of its base format.

With this change, the addition of the filters at the pandoc command line append in render directly and will be always put at the end of the command line.

I have changed the helpers function for lua but they where not exposed, only accessible by :::. I wonder if that is fine. I can do otherwise but it seems better this way.

@atusy
Copy link
Collaborator

atusy commented Sep 14, 2020

If we export pkg_file_lua, I would ask for adding package argument.
In this way, pkg_file_lua('foo.lua', package = 'mypkg') is possible, and downstream packages do not have to reinvent a similar function.
Also, this encourages consistent directory structures for R Markdown related package.

@cderv
Copy link
Collaborator Author

cderv commented Sep 14, 2020

If we export pkg_file_lua, I would ask for adding package argument.
In this way, pkg_file_lua('foo.lua', package = 'mypkg') is possible, and downstream packages do not have to reinvent a similar function.
Also, this encourages consistent directory structures for R Markdown related package.

Yes this was idea, but this means we impose the directory structure. I am more inclined to export pandoc_lua_filters_args() which IMO is closer to the other from its family pandoc_*_args and which leaves the directory structure open for 📦 developers. I don't think there is already one structure consistent for html resources and pandoc template.

But, indeed we could start suggesting some standard.

@atusy
Copy link
Collaborator

atusy commented Sep 14, 2020

I see. I am fine with not exporting pkg_file_lua, and that is because I said "if we export" rather than "I want to export".
This function is small enough to neglect the cost for reinvention.

R/render.R Outdated Show resolved Hide resolved
@cderv cderv marked this pull request as ready for review September 15, 2020 13:52
@cderv
Copy link
Collaborator Author

cderv commented Sep 15, 2020

This is ready I think. I'll test it with bookdown now.

Copy link
Member

@yihui yihui left a comment

Choose a reason for hiding this comment

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

Looks perfect! You are all set. I'll tweak the wording in NEWS and merge this PR soon. The pkg_file_lua stuff could be done in a new PR if necessary. Thanks!

R/util.R Show resolved Hide resolved
@yihui yihui merged commit 7ef641f into rstudio:master Sep 22, 2020
@cderv cderv deleted the pandoc-lua-arg branch September 22, 2020 16:10
cderv added a commit that referenced this pull request Sep 22, 2020
cderv added a commit to cderv/bookdown that referenced this pull request Sep 22, 2020
jonathan-g added a commit to jonathan-g/rmarkdown that referenced this pull request Sep 24, 2020
* 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)
jonathan-g added a commit to jonathan-g/rmarkdown that referenced this pull request Sep 24, 2020
Merge remote-tracking branch 'rstudio_origin/master' into css-slash-fix

# By Yihui Xie (12) and others
# Via GitHub
* rstudio_origin/master: (22 commits)
  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)
  tweak news
  require Pandoc >= 1.14
  xfun 0.16 is on CRAN now
  ...

# Conflicts:
#	NEWS.md
yihui pushed a commit to cderv/bookdown that referenced this pull request Oct 12, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2021
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.

Improve pandoc lua filters handling to make it more usable from other package
3 participants