bookdown icon indicating copy to clipboard operation
bookdown copied to clipboard

[FR] Add ability to run script on R files prior to sending to pandoc

Open cjdbarlow opened this issue 3 years ago • 0 comments

Problem:

  • The current before\after_chapter_script features don't allow changes to file contents
  • I would like to add a script that can edit content (but leave the underlying file unchanged)
  • I would like to do this prior to merging, so that changes can be targeted and configured at the file level
  • An example is custom shortcodes which can have dynamic elements (adjusted on a per file basis, e.g. via YAML header)
  • This means writing can remain clean and non-technical, whilst allowing more complex page elements to be created

Ideal solution:

  • Specify a script or list of scripts in the _bookdown.yml that modify file contents prior to merging

Current solution:

  • My current solution alters the merge_chapters function and runs an R script to alter the character vector (x) containing the lines of each file
  • Files can be identified (by f) so scripts can identify any relevant YAML in that file and alter their action appropriately
  • There's probably a cleaner way to do this

cjdbarlow avatar Aug 27 '21 02:08 cjdbarlow