Skip to content

Commit

Permalink
Merged origin/main into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jul 7, 2022
2 parents 9d84931 + 85c6e8a commit c9cffcb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 19 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Code evaluated in inline markdown code chunks and `@eval`/`@evalRd`/
`@evalNamespace` is now evaluated in an environment designed to be more
reproducible and to suppress output that won't work in Rd (e.g. turning
off colour and unicode support in cli) (#1351).
off colour and unicode support in cli) (#1351). They now also set
knitr options `comment = #>` (#1380) and `collapse = TRUE` (#1376).

# roxygen2 7.2.0

Expand Down Expand Up @@ -49,7 +50,7 @@
`\ifelse{}{}{}` tags are now inserted correctly (without additional `{}`)
(#1062).

* `@inhert` now supports inheriting "Notes" with `@inherit pkg::fun note`
* `@inherit` now supports inheriting "Notes" with `@inherit pkg::fun note`
(@pat-s, #1218)

* Automatic `@usage` now correctly wraps arguments containing syntactically
Expand Down
4 changes: 3 additions & 1 deletion R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ eval_code_node <- function(node, env) {
knitr_chunk_defaults <- list(
error = FALSE,
fig.path = "man/figures/",
fig.process = function(path) basename(path)
fig.process = function(path) basename(path),
comment = "#>",
collapse = TRUE
)

str_set_all_pos <- function(text, pos, value, nodes) {
Expand Down
12 changes: 4 additions & 8 deletions man/markdown_pass1.Rd

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

2 changes: 1 addition & 1 deletion src/parser2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ cpp11::list tokenise_block(cpp11::strings lines, std::string file,

if (!line.consumeRoxygenComment()) {
// Incremenet curRow for non-roxygen comments at start of block
if (curVal == "")
if (curVal.empty())
curRow++;
continue;
}
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/_snaps/markdown-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,28 @@
1: 1 +
^

# interleaving fences and inline code

Code
cat(out1$get_value("details"))
Output
Details 10
\if{html}{\out{<div class="sourceCode r">}}\preformatted{y <- x + 10
y
#> [1] 20
}\if{html}{\out{</div>}}

# preserves white space

Code
cat(out1$get_value("details"))
Output
\if{html}{\out{<div class="sourceCode r">}}\preformatted{a <- 1
b <- 2
}\if{html}{\out{</div>}}
\if{html}{\out{<div class="sourceCode r">}}\preformatted{c <- 3
}\if{html}{\out{</div>}}

35 changes: 28 additions & 7 deletions tests/testthat/test-markdown-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("can eval inline code", {
#' @description Description `r 2 + 2`
#' @md
foo <- function() NULL
")[[1]]
expect_equal(out1$get_value("title"), "Title 2")
expect_equal(out1$get_value("description"), "Description 4")
Expand All @@ -21,7 +21,7 @@ test_that("can eval fenced code", {
#' ```
#' @md
foo <- function() NULL
")[[1]]
expect_match(out1$get_value("details"), "2")
})
Expand All @@ -35,7 +35,7 @@ test_that("use same env within, but not across blocks", {
bar <- function() NULL
#' Title
#'
#'
#' Description `r exists('baz', inherits = FALSE)`
#' @md
zap <- function() NULL
Expand All @@ -56,7 +56,7 @@ test_that("appropriate knit print method for fenced and inline is applied", {
)
out1 <- roc_proc_text(rd_roclet(), "
#' @title Title `r structure('default', class = 'foo')`
#'
#'
#' @details Details
#'
#' ```{r}
Expand Down Expand Up @@ -153,9 +153,30 @@ test_that("interleaving fences and inline code", {
#' @name dummy
NULL")[[1]]

details <- out1$get_value("details")
expect_match(details, "Details 10", fixed = TRUE)
expect_match(details, "## [1] 20", fixed = TRUE)
expect_snapshot(cat(out1$get_value("details")))
})

test_that("preserves white space", {
out1 <- roc_proc_text(rd_roclet(), "
#' Title
#'
#' @details
#'
#' ```{r}
#' a <- 1
#'
#' b <- 2
#' ```
#'
#' ```{r}
#' c <- 3
#' ```
#'
#' @md
#' @name dummy
NULL")[[1]]

expect_snapshot(cat(out1$get_value("details")))
})

test_that("fence options are used", {
Expand Down

0 comments on commit c9cffcb

Please sign in to comment.