diff --git a/DESCRIPTION b/DESCRIPTION index d2377a3903..a5492bcfc5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: knitr Type: Package Title: A General-Purpose Package for Dynamic Report Generation in R -Version: 1.43.6 +Version: 1.43.7 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Abhraneel", "Sarma", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index be77605d0f..d9c6d09371 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,10 @@ - Use the correct type of progress bar when rendering Quarto documents in RStudio, which takes place in RStudio's background jobs pane or build pane (thanks, @hadley, #2271). +## MAJOR CHANGES + +- Dashes (`-`) in the names of all chunk options are normalized to dots (`.`) now, e.g., `fig-height` will be converted to `fig.height`. This is to make **knitr** more compatible with Quarto since Quarto always use dashes in chunk option names (#2282). + ## MINOR CHANGES - In-body chunk options (`#|`) are now preserved when extracting code from a document via `purl()` (thanks, @LuisLauM, #2268). diff --git a/R/parser.R b/R/parser.R index 0f76ab62e1..bb78c94b63 100644 --- a/R/parser.R +++ b/R/parser.R @@ -314,8 +314,6 @@ partition_chunk = function(engine, code) { # normalize field name 'id' to 'label' if provided meta$label = unlist(meta[c('label', 'id')])[[1]] meta$id = NULL - # convert any option with fig- into fig. and out- to out. - names(meta) = sub('^(fig|out)-', '\\1.', names(meta)) # extract code if (length(code) > 0 && is_blank(code[[1]])) { diff --git a/R/utils.R b/R/utils.R index 23bd50ad92..ac2102f0b3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -247,6 +247,17 @@ tikz_dict = function(path) { # but now also place to tweak default options fix_options = function(options) { options = as.strict_list(options) + # convert dashes in option names with dots + dashes = grep('-', names(options), value = TRUE) + options[gsub('-', '.', dashes)] = options[dashes] + options[dashes] = NULL + + # normalize aliases + aliases = c(fig.format = 'dev', fig.dpi = 'dpi') + for (j in intersect(names(options), names(aliases))) { + options[[aliases[j]]] = options[[j]] + options[[j]] = NULL + } # if you want to use subfloats, fig.show must be 'hold' if (length(options$fig.subcap)) options$fig.show = 'hold' diff --git a/tests/testit/test-utils.R b/tests/testit/test-utils.R index 46e573b181..2dda254f66 100644 --- a/tests/testit/test-utils.R +++ b/tests/testit/test-utils.R @@ -238,3 +238,21 @@ assert('remove_urls() removes the link', { (remove_urls('a [b](c) d [e f+g](h) i.') %==% 'a b d e f+g i.') (remove_urls('a [b](c) `[d](e)` f.') %==% 'a b `[d](e)` f.') }) + +assert('options using `-` are converted to `.` and default value replaced', { + opts = opts_chunk$merge(list('fig-cap' = 'caption', 'out-width' = 300)) + (is.null(fix_options(opts)[['fig-cap']])) + (is.null(fix_options(opts)[['out-width']])) + (fix_options(opts)[['fig.cap']] == 'caption') + (fix_options(opts)[['out.width']] == 300) + rm(opts) +}) + +assert('fig.format and fig.dpi', { + opts = opts_chunk$merge(list('fig-format' = 'svg', 'fig-dpi' = 750)) + (is.null(fix_options(opts)[['fig-format']])) + (is.null(fix_options(opts)[['fig-dpi']])) + (fix_options(opts)[['dev']] == 'svg') + (fix_options(opts)[['dpi']] == 750) + rm(opts) +})