-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathmarkdown-state.R
44 lines (35 loc) · 1.16 KB
/
markdown-state.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#' @export
roxy_tag_parse.roxy_tag_md <- function(x) tag_toggle(x)
#' @export
roxy_tag_parse.roxy_tag_noMd <- function(x) tag_toggle(x)
## Hacky global switch - this uses the fact that blocks are parsed
## one after the another, and that we set markdown on/off before each
## block
markdown_env <- new.env(parent = emptyenv())
markdown_on <- function(value = NULL) {
if (!is.null(value)) {
assign("markdown-support", isTRUE(value), envir = markdown_env)
}
return(isTRUE(markdown_env$`markdown-support`))
}
local_markdown <- function(env = parent.frame()) {
old <- markdown_env$`markdown-support`
markdown_on(TRUE)
withr::defer(markdown_on(old), envir = env)
}
markdown_activate <- function(tags) {
## markdown on/off based on global flag and presence of @md & @nomd
names <- purrr::map_chr(tags, "tag")
has_md <- "md" %in% names
has_nomd <- "noMd" %in% names
if (has_md && has_nomd) {
md_tag <- tags[names == "md"][[1]]
warn_roxy_tag(md_tag, "conflicts with @noMd; turning markdown parsing off")
md <- FALSE
} else {
md <- roxy_meta_get("markdown", FALSE)
if (has_md) md <- TRUE
if (has_nomd) md <- FALSE
}
markdown_on(md)
}