-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gdef.R
34 lines (28 loc) · 896 Bytes
/
gdef.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
#' Generate anchor tag for a given term in HTML
#'
#' @param term Look-up key
#' @param text Text to display
#'
#' @return string containing link
#'
#' @export
gdef <- function(term, text){
if (!isTRUE(getOption('knitr.in.progress'))){
stop('This function only runs on RMarkdown Documents')
}
glosario_data <- rmarkdown::metadata[['glosario']]
if (is.null(glosario_data$base_url)){
base_url <- 'https://glosario.carpentries.org'
} else {
base_url <- glosario_data$base_url
}
if (is.null(glosario_data$language)){
language <- 'en'
} else {
language <- glosario_data$language
}
# We introduce a span with class glosario_def so people can style HTML
# The link itself is a MD link so that it renders without problem in all formats.
string <- glue::glue('<span class="glosario_def">[{text}]({base_url}/{language}/#{term})</span>')
return(string)
}