1#' @export
2roxy_tag_parse.roxy_tag_section <- function(x) {
3  tag_markdown(x)
4}
5
6#' @export
7roxy_tag_rd.roxy_tag_section <- function(x, base_path, env) {
8  pieces <- str_split(x$val, ":", n = 2)[[1]]
9  title <- str_split(pieces[1], "\n")[[1]]
10
11  if (length(title) > 1) {
12    roxy_tag_warning(x, paste0(
13      "Section title spans multiple lines.\n",
14      "Did you forget a colon (:) at the end of the title?"
15    ))
16    return()
17  }
18
19  rd_section_section(pieces[1], pieces[2])
20}
21
22rd_section_section <- function(title, content) {
23  stopifnot(is.character(title), is.character(content))
24  stopifnot(length(title) == length(content))
25
26  rd_section("section", list(title = title, content = content))
27}
28
29#' @export
30format.rd_section_section <- function(x, ...) {
31  paste0(
32    "\\section{", x$value$title, "}{\n", x$value$content, "\n}\n",
33    collapse = "\n"
34  )
35}
36
37#' @export
38merge.rd_section_section <- function(x, y, ...) {
39  stopifnot(identical(class(x), class(y)))
40
41  dedup <- collapse(
42    c(x$value$title, y$value$title),
43    c(x$value$content, y$value$content),
44    paste, collapse = "\n\n"
45  )
46  rd_section("section", list(title = dedup$key, content = unlist(dedup$value)))
47}
48