Skip to content

Commit ac1503a

Browse files
authored
don't set vheight/vwidth for webshot when out.height/width.px is a percentage (#2400)
fix rstudio/rmarkdown#2460
1 parent 390ad60 commit ac1503a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: knitr
22
Type: Package
33
Title: A General-Purpose Package for Dynamic Report Generation in R
4-
Version: 1.50.3
4+
Version: 1.50.4
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
77
person("Abhraneel", "Sarma", role = "ctb"),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
- `hook_optipng()` now uses the `-quiet` argument of `optipng` to suppress the messages by default.
1010

11+
- Don't set `vheight` or `vwidth` for `webshot2::webshot()` when the chunk option `out.height` or `out.width` is a percentage (%). Setting `screenshot.opts` chunk option is still a way to specify `vheight` or `vwidth` specifically for `webshot()`, e.g., `screenshot.opts = list(vwidth = 6 * 72, vheight = 6 * 72 * 0.618)` for the width of 6 inches size with 72 dpi and 0.618 of aspect ratio.
12+
1113
# CHANGES IN knitr VERSION 1.50
1214

1315
## NEW FEATURES

R/plot.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ html_screenshot = function(x, options = opts_current$get(), ...) {
595595
switch(options$dev[1], pdf = '.pdf', jpeg = '.jpeg', '.png')
596596
} else '.png'
597597
wargs = options$screenshot.opts %n% list()
598-
if (is.null(wargs$vwidth)) wargs$vwidth = options$out.width.px
599-
if (is.null(wargs$vheight)) wargs$vheight = options$out.height.px
598+
if (is.null(wargs$vwidth) && !grepl("%$", W <- options$out.width.px)) wargs$vwidth = W
599+
if (is.null(wargs$vheight) && !grepl("%$", H <- options$out.height.px)) wargs$vheight = H
600600
if (is.null(wargs$delay)) wargs$delay = if (i1) 0.2 else 1
601601
d = tempfile()
602602
dir.create(d); on.exit(unlink(d, recursive = TRUE), add = TRUE)
@@ -609,6 +609,8 @@ html_screenshot = function(x, options = opts_current$get(), ...) {
609609
if (is_quarto()) "fig-format" else "dev", "' to 'png'). ",
610610
"See https://github.com/yihui/knitr/issues/2276 for more information."
611611
)
612+
# set quiet opions for webshot2::webshot()
613+
local_options(list(webshot.quiet = getOption('webshot.quiet', TRUE)))
612614
f = in_dir(d, {
613615
if (i1 || i3) {
614616
if (i1) {

0 commit comments

Comments
 (0)