Skip to content

Instantly share code, notes, and snippets.

@cderv
Created September 14, 2020 11:44
Show Gist options
  • Save cderv/7a38b372c4a985113e2d1e4ba1e19223 to your computer and use it in GitHub Desktop.
Save cderv/7a38b372c4a985113e2d1e4ba1e19223 to your computer and use it in GitHub Desktop.
get_pandoc_metadata <- function(file, to = "html") {
template <- tempfile(fileext = ".json")
json_out <- tempfile(fileext = ".json")
xfun::write_utf8("$meta-json$", template)
template_arg <- sprintf("--template=%s", template)
rmarkdown::pandoc_convert(file, from = "markdown", to = to,
options = c(template_arg),
output = json_out)
jsonlite::fromJSON(json_out)
}
test_rmd <- tempfile(fileext = ".Rmd")
rmarkdown::draft(test_rmd, template = "html-paged", package = "pagedown", edit = FALSE)
get_pandoc_metadata(test_rmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment