R/placeholders.R

Defines functions fill_placeholder placeholder_end placeholder_begin placeholder_html

placeholder_html <- function(context, ...) {
  tagList(
    HTML(placeholder_begin(context)),
    list(...),
    HTML(placeholder_end(context))
  )
}

placeholder_begin <- function(context) {
  paste0('<!--radix_placeholder_', context ,'-->')
}

placeholder_end <- function(context) {
  paste0('<!--/radix_placeholder_', context, '-->')
}

fill_placeholder <- function(html, context, content) {
  begin <- placeholder_begin(context)
  begin_pos <- regexpr(begin, html, fixed = TRUE)
  end <- placeholder_end(context)
  end_pos <- regexpr(end, html, fixed = TRUE)
  if (begin_pos >= 0 && end_pos >= 0) {
    paste0(
      substring(html, first = 1, last = begin_pos - 1),
      content,
      substring(html,
                first = end_pos + attr(end_pos, "match.length"),
                last = nchar(html))
    )
  } else {
    html
  }
}

Try the distill package in your browser

Any scripts or data that you put into this service are public.

distill documentation built on Oct. 6, 2023, 5:06 p.m.