From 092d392f86ab0ad7653e9be773f63209646e72ae Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Fri, 10 Jan 2025 14:17:38 -0600 Subject: [PATCH] retrieve default chunk options `comment` and `attr.output` from xfun::raw_string() if possible: https://github.com/yihui/xfun/commit/f195d0ee09b92d7b6d1242190479e88f0df12898 --- DESCRIPTION | 2 +- R/fuse.R | 11 ++++++++--- R/utils.R | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c35ef1a..d4b710c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: litedown Type: Package Title: A Lightweight Version of R Markdown -Version: 0.5.3 +Version: 0.5.4 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")), person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")), diff --git a/R/fuse.R b/R/fuse.R index 192d506..60703e2 100644 --- a/R/fuse.R +++ b/R/fuse.R @@ -776,8 +776,13 @@ fuse_code = function(x, blocks) { } else { if (type == 'message') x = sub('\n$', '', x) if (!asis) { - x = split_lines(x) - x = paste0(opts$comment, x) # comment out text output + opt2 = attr(x, 'opts') + cmt = opts$comment %||% opt2$comment %||% '#> ' + if (cmt != '') { + x = split_lines(x) + x = paste0(cmt, x) # comment out text output + } + if (is.null(a)) a = opt2$attr } } if (asis) { @@ -992,7 +997,7 @@ new_opts = function() { #' ls(opts) # built-in options reactor = new_opts() reactor( - eval = TRUE, echo = TRUE, results = TRUE, comment = '#> ', + eval = TRUE, echo = TRUE, results = TRUE, comment = NULL, warning = TRUE, message = TRUE, error = NA, include = TRUE, strip.white = TRUE, collapse = FALSE, order = 0, attr.source = NULL, attr.output = NULL, attr.plot = NULL, attr.chunk = NULL, diff --git a/R/utils.R b/R/utils.R index e359066..323f4ec 100644 --- a/R/utils.R +++ b/R/utils.R @@ -16,7 +16,7 @@ counters = local({ # use PCRE by default (which seems to handle multibyte chars better) gregexpr = function(..., perl = TRUE) base::gregexpr(..., perl = perl) - +attr = function(...) base::attr(..., exact = TRUE) # exact attr() please `%|%` = function(x, y) if (length(x)) x else y if (getRversion() < '4.4.0') `%||%` = function(x, y) if (is.null(x)) y else x set_names = function(x, nm) {