rstudio / bookdown

Authoring Books and Technical Documents with R Markdown
https://pkgs.rstudio.com/bookdown/
GNU General Public License v3.0
3.74k stars 1.26k forks source link

header-include, include-before, and include-after variables to be passed to Pandoc default template are lost #725

Closed joshuaborn closed 5 years ago

joshuaborn commented 5 years ago

In Section D.8 The default HTML template of Creating Websites with R Markdown, all of $header-includes$, $css$, $include-before$, $toc$, and $include-after$ are supposed to be available for customization of the Pandoc output of R Markdown posts, but only $css$ and $toc$ appear to work. Any values passed to the $header-includes$, $include-before$, and $include-after$ variables disappear without an error message.

Steps to reproduce:

  1. In RStudio, select File > New Project...
  2. Select New Directory.
  3. Select Website using blogdown.
  4. Provide a directory name, use the default yihui/hugo-lithium Hugo theme, leave Add sample blog posts, Add the example site of the theme, and Convert all metadata to YAML checked, and then create project.
  5. Addins > Serve Site
  6. Open the file content/post/2015-07-23-r-markdown.html in the editor, confirm it has been rendered, and close the editor pane.
  7. Open the file content/post/2015-07-23-r-markdown.Rmd in the editor. Add the below to the front matter of the file and save it:
    output:
    blogdown::html_page:
    toc: true
    css: "/css/my-style.css"
  8. Open content/post/2015-07-23-r-markdown.html in the editor again, confirm a CSS tag and table of contents have been added, and close the editor pane.
  9. In content/post/2015-07-23-r-markdown.Rmd, add the below options to blogdown::html_page: in the front matter:
    header-includes: "This is a header include."
    include-before: "This is a before include."
    include-after: "This is an after include."
  10. Open content/post/2015-07-23-r-markdown.html in the editor again and confirm none of these were included.
  11. In content/post/2015-07-23-r-markdown.Rmd, change the options to blogdown::html_page: in the front matter to be arrays, as in the below:
    header-includes: ["This is a header include.", "This is another example include."]
    include-before: ["This is a before include.", "This is another example include."]
    include-after: ["This is an after include.", "This is another example include."]
  12. Open content/post/2015-07-23-r-markdown.html in the editor again and confirm there are still no inclusions.

This is what the final front matter looks like for content/post/2015-07-23-r-markdown.Rmd:

---
title: "Hello R Markdown"
author: "Frida Gomam"
date: 2015-07-23T21:13:14-05:00
categories: ["R"]
tags: ["R Markdown", "plot", "regression"]
output:
  blogdown::html_page:
    toc: true
    css: "/css/my-style.css"
    header-includes: ["This is a header include.", "This is another example include."]
    include-before: ["This is a before include.", "This is another example include."]
    include-after: ["This is an after include.", "This is another example include."]
---

Environment

I am using RStudio Version 1.2.1335, which I have confirmed is the latest.

I am using the latest version of R and have updated libraries. See xfun::session_info() results below:

R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763), RStudio 1.2.1335

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
  LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
  LC_TIME=English_United States.1252    

Package version:
  base64enc_0.1.3 BH_1.69.0.1     blogdown_0.12   bookdown_0.11   compiler_3.6.0  digest_0.6.19  
  evaluate_0.14   glue_1.3.1      graphics_3.6.0  grDevices_3.6.0 highr_0.8       htmltools_0.3.6
  httpuv_1.5.1    jsonlite_1.6    knitr_1.23      later_0.8.0     magrittr_1.5    markdown_0.9   
  methods_3.6.0   mime_0.6        promises_1.0.1  R6_2.4.0        Rcpp_1.0.1      rlang_0.3.4    
  rmarkdown_1.13  rstudioapi_0.10 servr_0.13      stats_3.6.0     stringi_1.4.3   stringr_1.4.0  
  tinytex_0.13    tools_3.6.0     utils_3.6.0     xfun_0.7        yaml_2.2.0 

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

yihui commented 5 years ago

First, this is the bookdown repo, and I think you meant to post it to the blogdown repo instead.

Second, the fields header-includes, etc are supposed to be top-level fields in the YAML frontmatter, instead of sub-options of blogdown::html_page. See Pandoc's Manual: https://pandoc.org/MANUAL.html#structural-variables

joshuaborn commented 5 years ago

I see. Thank you.

(And, yes, I did mean to open this in the blogdown repo. My mistake.)

github-actions[bot] commented 3 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.