Skip to content

Commit

Permalink
factor out the code to divide input lines into code/text chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Apr 10, 2024
1 parent aa11db8 commit 44a7bee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down
9 changes: 7 additions & 2 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
Expand Down

0 comments on commit 44a7bee

Please sign in to comment.