Skip to content

Commit 22bb8c8

Browse files
committed
use knitr also for inline closes #1179
1 parent f557e2c commit 22bb8c8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

R/markdown.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ eval_code_nodes <- function(nodes) {
9898

9999
eval_code_node <- function(node, env) {
100100
if (xml_name(node) == "code") {
101-
text <- str_replace(xml_text(node), "^r ", "")
102-
paste(eval(parse(text = text), envir = env), collapse = "\n")
103-
101+
# this is for inline code
102+
text <- paste0("`", xml_text(node), "`")
104103
} else {
104+
# this is for fenced code
105105
text <- paste0("```", xml_attr(node, "info"), "\n", xml_text(node), "```\n")
106-
opts_chunk$set(
107-
error = FALSE,
108-
fig.path = "man/figures/",
109-
fig.process = function(path) basename(path)
110-
)
111-
knit(text = text, quiet = TRUE, envir = env)
112106
}
107+
opts_chunk$set(
108+
error = FALSE,
109+
fig.path = "man/figures/",
110+
fig.process = function(path) basename(path)
111+
)
112+
knit(text = text, quiet = TRUE, envir = env)
113113
}
114114

115115
str_set_all_pos <- function(text, pos, value, nodes) {

tests/testthat/test-markdown-code.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test_that("uses the same env for a block, but not across blocks", {
2525
#' @md
2626
#' @name dummy2
2727
NULL")
28-
expect_equal(out1$dummy.Rd$get_value("title"), "Title 420 420")
28+
expect_equal(out1$dummy.Rd$get_value("title"), "Title 420")
2929
expect_equal(out1$dummy.Rd$get_value("description"), "Description TRUE")
3030
expect_equal(out1$dummy2.Rd$get_value("description"), "Description FALSE")
3131
})
@@ -55,6 +55,7 @@ test_that("appropriate knit print method for fenced and inline is applied", {
5555
NULL
5656
")
5757
expect_match(out1$bar.Rd$get_value("details"), "fenced", fixed = TRUE)
58+
expect_match(out1$bar.Rd$get_value("title"), "inline", fixed = TRUE)
5859
})
5960

6061
test_that("can create markdown markup", {
@@ -118,7 +119,7 @@ test_that("interleaving fences and inline code", {
118119
out1 <- roc_proc_text(rd_roclet(), "
119120
#' Title
120121
#'
121-
#' @details Details `r x <- 10`
122+
#' @details Details `r x <- 10; x`
122123
#'
123124
#' ```{r}
124125
#' y <- x + 10

0 commit comments

Comments
 (0)