Skip to content

Commit

Permalink
use knitr also for inline closes #1179
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Jan 21, 2021
1 parent f557e2c commit 194b766
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
18 changes: 9 additions & 9 deletions R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ eval_code_nodes <- function(nodes) {

eval_code_node <- function(node, env) {
if (xml_name(node) == "code") {
text <- str_replace(xml_text(node), "^r ", "")
paste(eval(parse(text = text), envir = env), collapse = "\n")

# this is for inline code
text <- paste0("`", xml_text(node), "`")
} else {
# this is for fenced code
text <- paste0("```", xml_attr(node, "info"), "\n", xml_text(node), "```\n")
opts_chunk$set(
error = FALSE,
fig.path = "man/figures/",
fig.process = function(path) basename(path)
)
knit(text = text, quiet = TRUE, envir = env)
}
opts_chunk$set(
error = FALSE,
fig.path = "man/figures/",
fig.process = function(path) basename(path)
)
knit(text = text, quiet = TRUE, envir = env)
}

str_set_all_pos <- function(text, pos, value, nodes) {
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/markdown-code-errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ Error: [<text>:3] @description in inline code: multi-line `r ` markup is not sup
> roc_proc_text(rd_roclet(),
+ "\n #' Title\n #'\n #' Description --`r 1 + 'a'`--\n #' @md\n #' @name dummy\n NULL")[[
+ 1]]


Message: Quitting from lines 1-1 ()

Error: [<text>:3] @description in inline code: non-numeric argument to binary operator

> roc_proc_text(rd_roclet(),
+ "\n #' Title\n #'\n #' Description --`r 1 + `--\n #' @md\n #' @name dummy\n NULL")[[
+ 1]]


Message: Quitting from lines 1-1 ()

Error: [<text>:3] @description in inline code: <text>:2:0: unexpected end of input
1: 1 +
^
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-markdown-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test_that("uses the same env for a block, but not across blocks", {
#' @md
#' @name dummy2
NULL")
expect_equal(out1$dummy.Rd$get_value("title"), "Title 420 420")
expect_equal(out1$dummy.Rd$get_value("title"), "Title 420")
expect_equal(out1$dummy.Rd$get_value("description"), "Description TRUE")
expect_equal(out1$dummy2.Rd$get_value("description"), "Description FALSE")
})
Expand Down Expand Up @@ -55,6 +55,7 @@ test_that("appropriate knit print method for fenced and inline is applied", {
NULL
")
expect_match(out1$bar.Rd$get_value("details"), "fenced", fixed = TRUE)
expect_match(out1$bar.Rd$get_value("title"), "inline", fixed = TRUE)
})

test_that("can create markdown markup", {
Expand Down Expand Up @@ -118,7 +119,7 @@ test_that("interleaving fences and inline code", {
out1 <- roc_proc_text(rd_roclet(), "
#' Title
#'
#' @details Details `r x <- 10`
#' @details Details `r x <- 10; x`
#'
#' ```{r}
#' y <- x + 10
Expand Down

0 comments on commit 194b766

Please sign in to comment.