R/bulma-content.R

Defines functions bulma_code bulma_markdown bulma_content

Documented in bulma_code bulma_content bulma_markdown

#' @title
#' Bulma Content
#'
#' @description
#' A single class to handle WYSIWYG generated content, where only HTML tags
#' are available. When you can't use the CSS classes you want, or when you
#' just want to directly use HTML tags, use this element.
#'
#' [Content](https://bulma.io/documentation/elements/content/)
#'
#' @param size (string) relative sizing for all the content
#' @param ... (tags) content
#' @param tag (fn) default HTML tag
#'
#' @family Bulma Elements
#' @export
bulma_content <- function(...,
                          size = c("small", "medium", "large", "normal"),
                          tag = tags$div) {

  size <- match_arg(size)

  tag(class = "content", ...) %>%
    bulma_size(size) %>%
    add_class("bulma_content")

}

#' @describeIn bulma_content Markdown Content in Bulma
bulma_markdown <- function(...,
                           size = c("small", "medium", "large", "normal"),
                           tag = tags$div) {

  bulma_content(
    HTML(markdown_html(str_squish(c(...)))),
    size = size,
    tag = tag
  ) %>%
    add_class("bulma_markdown")

}

#' @describeIn bulma_content code block
#' @param width (int) code width in characters, defaults to 80L.
bulma_code <- function(...,
                       width = 80,
                       size = c("small", "medium", "large", "normal"),
                       tag = tags$pre) {

  bulma_content(
    quo_text(quo(...), width = 80),
    size = size,
    tag = tag
  ) %>%
    add_class("bulma_code")

}
tjpalanca/bulma.R documentation built on Dec. 23, 2021, 10:58 a.m.