diff --git a/DESCRIPTION b/DESCRIPTION index f7f7b4a7dd..8e0de27f61 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.46.2 +Version: 1.46.3 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/R/parser.R b/R/parser.R index 37fa082c50..62f7f2139b 100644 --- a/R/parser.R +++ b/R/parser.R @@ -13,8 +13,7 @@ split_file = function(lines, set.preamble = TRUE, patterns = knit_patterns$get() } markdown_mode = identical(patterns, all_patterns$md) - i = group_indices(grepl(chunk.begin, lines), grepl(chunk.end, lines), lines, markdown_mode) - groups = unname(split(lines, i)) + groups = divide_chunks(lines, chunk.begin, chunk.end, markdown_mode) if (set.preamble) knit_concord$set(inlines = sapply(groups, length)) # input line numbers for concordance @@ -41,6 +40,12 @@ split_file = function(lines, set.preamble = TRUE, patterns = knit_patterns$get() }) } +# divide lines of input into code/text chunks +divide_chunks = function(x, begin, end, md = TRUE) { + i = group_indices(grepl(begin, x), grepl(end, x), x, md) + unname(split(x, i)) +} + extract_params_src = function(chunk.begin, line) { trimws(gsub(chunk.begin, '\\1', line)) }