I am writing an R package which needs to add JavaScript functions to the <head>
of an HTML file created by Rmarkdown or Quarto. I do not have control over the YAML preamble, so I cannot use include-in-header
. I need a programmatic way to modify the HTML header.
Ideally, I would also be able to inspect the header to avoid inserting the duplicated scripts.
I tried using knitr::knit_meta_add()
but I can’t figure out how it works.
<code># This does not appear to work
k <- list("name" = "demo", src = "https://examples.org/", script = "demo.js")
knitr::knit_meta_add(list(k))
# I do not understand how this works
knitr::knit_meta_add(list(rmarkdown::html_dependency_font_awesome()))
</code>
<code># This does not appear to work
k <- list("name" = "demo", src = "https://examples.org/", script = "demo.js")
knitr::knit_meta_add(list(k))
# I do not understand how this works
knitr::knit_meta_add(list(rmarkdown::html_dependency_font_awesome()))
</code>
# This does not appear to work
k <- list("name" = "demo", src = "https://examples.org/", script = "demo.js")
knitr::knit_meta_add(list(k))
# I do not understand how this works
knitr::knit_meta_add(list(rmarkdown::html_dependency_font_awesome()))