Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vignette engines for Quarto #146

Merged
merged 30 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a1dbd20
Correctly handle null value
cderv Jan 30, 2024
17ae138
Vignette engines for Quarto (#57)
dcnorris Nov 3, 2023
2ff3300
Refactor a little
cderv Nov 3, 2023
0498b13
Refactor the vignette engine code
cderv Nov 3, 2023
d89a064
embed the resource for HTML vignettes
cderv Nov 3, 2023
ddc41d4
devtools::build_vignettes
cderv Nov 3, 2023
fe9374f
Add system_file from staticimports
cderv Nov 7, 2023
587183c
Set some meta for html vignette to enforce lightweight html for CRAN
cderv Nov 7, 2023
6c490d2
USe html vignette in the package
cderv Dec 22, 2023
007b953
typo
cderv Jan 30, 2024
54401e5
Same entry index as Title
cderv Jan 30, 2024
31c1eb9
Explain in demo vignette the HTML quarto engine
cderv Jan 30, 2024
c9c2c7a
Typo
cderv Jan 30, 2024
c88a0e3
Handle NULL in format
cderv Jan 30, 2024
00baa22
Add mention of quarto::pdf engine
cderv Jan 30, 2024
c2b5eec
Split HTML and PDF vignette
cderv Jan 30, 2024
37e8df1
Correct vignette format
cderv Jan 30, 2024
be0d20b
Update doc regarding maintainer change
cderv Jan 30, 2024
df248ac
install the package itself as we register vignette engine
cderv Jan 30, 2024
1990405
Add LaTeX install
cderv Jan 30, 2024
d3ca56e
Ignore intermediate directories that would be produced by a author mo…
cderv Jan 30, 2024
edf2f4c
Remove knitr as vignettebuilder dependency
cderv Jan 30, 2024
636324d
Use include to share doc
cderv Jan 30, 2024
3c58e07
Add toc to publishing
cderv Jan 30, 2024
d2b0ed9
Remove extra characters
cderv Jan 30, 2024
5c64a1d
Register a generic engine that will use whatever is defined in format…
cderv Jan 30, 2024
5e3c222
Remove usage of staticimport system_files
cderv Jan 31, 2024
0c6e443
Add NEWS bullet
cderv Jan 31, 2024
6ccc3b1
Go back to v2.6.7 for now as there is conflict in naming follwing update
cderv Jan 31, 2024
e6c7360
Bump version
cderv Jan 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
^\.github$
^\.vscode$
^\.quarto$
^doc$
^Meta$

^vignettes/*_files$
13 changes: 8 additions & 5 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,24 @@ jobs:
- uses: quarto-dev/quarto-actions/setup@v2
with:
version: ${{ matrix.config.quarto || 'release' }}
tinytex: true


# replace with setting up QUARTO Pandoc for rmarkdown
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-pandoc@v2.6.5

- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r@v2.6.5
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
- uses: r-lib/actions/setup-r-dependencies@v2.6.5
with:
extra-packages: any::rcmdcheck
# install the package itself as we register vignette engine
extra-packages: any::rcmdcheck, local::.
needs: check

- uses: r-lib/actions/check-r-package@v2
- uses: r-lib/actions/check-r-package@v2.6.5
with:
upload-snapshots: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ inst/doc
docs

/.quarto/
/doc/
/Meta/
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: quarto
Title: R Interface to 'Quarto' Markdown Publishing System
Version: 1.3.11
Version: 1.3.12
Authors@R: c(
person("JJ", "Allaire", , "jj@posit.co", role = "aut",
comment = c(ORCID = "0000-0003-0174-9868")),
Expand All @@ -21,17 +21,18 @@ Imports:
rlang,
rmarkdown,
rstudioapi,
tools,
utils,
yaml
Suggests:
curl,
knitr,
rsconnect (>= 0.8.26),
testthat (>= 3.1.0),
testthat (>= 3.1.7),
withr,
xfun
VignetteBuilder:
knitr
quarto
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# quarto (development version)

- Add registration of vignette engine to use `quarto` as a vignette builder, and use `.qmd` file as vignette. See `vignette("hello", package = "quarto")`. (thanks, @dcnorris, #57).

- Add `quarto_binary_sitrep()` to check possible difference in Quarto binary used by this package, and the one used by RStudio IDE (thanks, @jthomasmock, #12).

- Add `quarto_create_project()` function that calls `quarto create project <type> <name>` (thanks, @maelle, #87).
Expand Down
1 change: 1 addition & 0 deletions R/quarto-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
## usethis namespace: start
#' @import rlang
#' @importFrom cli cli_inform
#' @importFrom tools vignetteEngine
## usethis namespace: end
NULL
4 changes: 3 additions & 1 deletion R/quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ check_quarto_version <- function(ver, what, url) {
#' @export
quarto_binary_sitrep <- function(verbose = TRUE, debug = FALSE) {

quarto_found <- normalizePath(quarto_path(), mustWork = FALSE)
quarto_found <- quarto_path()
if (is.null(quarto_found)) {
if (verbose) {
cli::cli_alert_danger(quarto_not_found_msg)
}
return(FALSE)
}

quarto_found <- normalizePath(quarto_found, mustWork = FALSE)

same_config <- TRUE
if (debug) verbose <- TRUE

Expand Down
2 changes: 1 addition & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#' This will be merged over `metadata-file` options if both are
#' specified.
#' @param metadata_file A yaml file passed to `--metadata-file` CLI flags to
#' overrite metadata. This will be merged with `metadata` if both are
#' override metadata. This will be merged with `metadata` if both are
#' specified, with low precedence on `metadata` options.
#' @param debug Leave intermediate files in place after render.
#' @param quiet Suppress warning and other messages.
Expand Down
47 changes: 47 additions & 0 deletions R/utils-vignettes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
register_vignette_engines <- function(pkg) {
vig_engine("html", quarto_format = "html")
vig_engine("pdf", quarto_format = "pdf")
vig_engine("format", quarto_format = NULL)
}


vig_engine <- function(..., quarto_format) {
rmd_eng <- tools::vignetteEngine('rmarkdown', package = 'knitr')
tools::vignetteEngine(
...,
weave = vweave_quarto(quarto_format),
tangle = rmd_eng$tangle,
pattern = "[.]qmd$",
package = "quarto",
aspell = rmd_eng$aspell
)
}

vweave_quarto <- function(format) {
meta <- get_meta(format)
function(file, driver, syntax, encoding, quiet = FALSE, ...) {
quarto_render(file, ..., output_format = format, metadata = meta)
}
}

get_meta <- function(format) {
if (is.null(format)) return(NULL)
if (format == "html") {
return(get_meta_for_html())
}
}

get_meta_for_html <- function() {

css <- system.file("rmarkdown", "template", "quarto_vignette", "resources",
"vignette.css", package = "quarto")
meta <- list()
meta$format$html <-
list(
`embed-resources` = TRUE,
minimal = TRUE,
theme = "none",
css = css
)
meta
}
1 change: 0 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


relative_to_wd <- function(path) {
relative_to(getwd(), path)
}
Expand Down
4 changes: 4 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Register engines to support Quarto vignettes
.onLoad <- function(lib, pkg) {
register_vignette_engines(pkg)
}
158 changes: 158 additions & 0 deletions inst/rmarkdown/template/quarto_vignette/resources/vignette.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
body {
background-color: #fff;
margin: 1em auto;
max-width: 700px;
overflow: visible;
padding-left: 2em;
padding-right: 2em;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.35;
}



table {
margin: 1em auto;
border-width: 1px;
border-color: #DDDDDD;
border-style: outset;
border-collapse: collapse;
}
table th {
border-width: 2px;
padding: 5px;
border-style: inset;
}
table td {
border-width: 1px;
border-style: inset;
line-height: 18px;
padding: 5px 5px;
}
table, table th, table td {
border-left-style: none;
border-right-style: none;
}
table thead, table tr.even {
background-color: #f7f7f7;
}

p {
margin: 0.5em 0;
}

blockquote {
background-color: #f6f6f6;
padding: 0.25em 0.75em;
}

hr {
border-style: solid;
border: none;
border-top: 1px solid #777;
margin: 28px 0;
}

dl {
margin-left: 0;
}
dl dd {
margin-bottom: 13px;
margin-left: 13px;
}
dl dt {
font-weight: bold;
}

ul {
margin-top: 0;
}
ul li {
list-style: circle outside;
}
ul ul {
margin-bottom: 0;
}

pre, code {
background-color: #f7f7f7;
border-radius: 3px;
color: #333;
white-space: pre-wrap; /* Wrap long lines */
}
pre {
border-radius: 3px;
margin: 5px 0px 10px 0px;
padding: 10px;
}
pre:not([class]) {
background-color: #f7f7f7;
}

code {
font-family: Consolas, Monaco, 'Courier New', monospace;
font-size: 85%;
}
p > code, li > code {
padding: 2px 0px;
}

div.figure {
text-align: center;
}
img {
background-color: #FFFFFF;
padding: 2px;
border: 1px solid #DDDDDD;
border-radius: 3px;
border: 1px solid #CCCCCC;
margin: 0 5px;
}

h1 {
margin-top: 0;
font-size: 35px;
line-height: 40px;
}

h2 {
border-bottom: 4px solid #f7f7f7;
padding-top: 10px;
padding-bottom: 2px;
font-size: 145%;
}

h3 {
border-bottom: 2px solid #f7f7f7;
padding-top: 10px;
font-size: 120%;
}

h4 {
border-bottom: 1px solid #f7f7f7;
margin-left: 8px;
font-size: 105%;
}

h5, h6 {
border-bottom: 1px solid #ccc;
font-size: 105%;
}

a {
color: #0033dd;
text-decoration: none;
}
a:hover {
color: #6666ff; }
a:visited {
color: #800080; }
a:visited:hover {
color: #BB00BB; }
a[href^="http:"] {
text-decoration: underline; }
a[href^="https:"] {
text-decoration: underline; }


4 changes: 2 additions & 2 deletions man/quarto-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/quarto_render.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/_snaps/quarto.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@
Output
[1] TRUE

---

Code
quarto_binary_sitrep(debug = TRUE)
Message
x Quarto command-line tools path not found! Please make sure you have installed and added Quarto to your PATH or set the QUARTO_PATH environment variable.
Output
[1] FALSE

8 changes: 8 additions & 0 deletions tests/testthat/test-quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ test_that("quarto CLI sitrep", {
transform = transform_quarto_cli_in_output(full_path = TRUE, normalize_path = TRUE)
)
)

# Mock no quarto found
with_mocked_bindings(
quarto_path = function(...) NULL,
expect_snapshot(
quarto_binary_sitrep(debug = TRUE)
)
)
})
1 change: 1 addition & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.html
*.R
*_files
1 change: 1 addition & 0 deletions vignettes/.install_extras
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include
Loading