From 17ae1386529adcac0c058cff87005bf0c0dc7859 Mon Sep 17 00:00:00 2001 From: "David C. Norris" Date: Fri, 3 Nov 2023 06:58:57 -0400 Subject: [PATCH] Vignette engines for Quarto (#57) --- DESCRIPTION | 3 ++- NAMESPACE | 1 + R/zzz.R | 24 ++++++++++++++++++++++++ vignettes/hello.qmd | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 R/zzz.R create mode 100644 vignettes/hello.qmd diff --git a/DESCRIPTION b/DESCRIPTION index 8d1aee1..6d35140 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,7 @@ Imports: rmarkdown, rstudioapi, utils, + tools, yaml Suggests: curl, @@ -31,7 +32,7 @@ Suggests: withr, xfun VignetteBuilder: - knitr + knitr, quarto Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 1c1fcb6..9e9fa9f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,5 +26,6 @@ importFrom(rlang,is_interactive) importFrom(rmarkdown,relative_to) importFrom(rstudioapi,isAvailable) importFrom(rstudioapi,viewer) +importFrom(tools,vignetteEngine) importFrom(utils,browseURL) importFrom(yaml,write_yaml) diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..ea3fc46 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,24 @@ + +#' Register engines to support Quarto vignettes +#' @importFrom tools vignetteEngine +#' @noRd +.onLoad <- function(libname, pkgname) { # args ignored + vignetteEngine(name = "pdf", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "pdf") + }, + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell + ) + vignetteEngine(name = "html", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "html") + }, + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell + ) +} diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd new file mode 100644 index 0000000..bd4a093 --- /dev/null +++ b/vignettes/hello.qmd @@ -0,0 +1,36 @@ +--- +title: "Quarto Vignettes" +format: + pdf: + toc: false + html: + toc: true +vignette: > + %\VignetteIndexEntry{Vignettes} + %\VignetteEngine{quarto::pdf} + %\VignetteEncoding{UTF-8} +--- + +## Hello Vignette World! + +This is an example Quarto vignette, demonstrating how the **quarto** package can let you write package vignettes in Quarto. + +## Two Vignette Engines + +The **quarto** package registers 2 vignette engines, `quarto::pdf` and `quarto::html`. Either of these may be selected in a Quarto vignette's YAML header. For example, this vignette's header reads: +```yaml +--- +title: "Quarto Vignettes" +format: + pdf: + toc: false + html: + toc: true +vignette: > + %\VignetteIndexEntry{Vignettes} + %\VignetteEngine{quarto::pdf} + %\VignetteEncoding{UTF-8} +--- +``` + +Consequently, a PDF version of this vignette is built.