|
- #' Bulma Document Renderer
- #'
- #' @section YAML options:
- #' You can pass additional options to the underlying template via the `bulma`
- #' YAML item. The following options can be specified there.
- #' \itemize{
- #' \item{`hero`: Classes applied to the hero containing the title.}
- #' \item{`hero_body`: Classes applied to the hero body container.}
- #' \item{`hero_button`: Classes applied to the `header_links` buttons}
- #' \item{`hero_links`: Links that will be displayed under title as buttons.
- #' Formatted as a list, each element having entries for `name`, `url`,
- #' and `icon`. Icons use [Font Awesome](https://fontawesome.com/icons);
- #' see [fa_icon()] for help constructing the Font Awesome class. The
- #' full Font Awesome class name is required.}
- #' }
- #'
- #' ```
- #' ---
- #' bulma:
- #' hero: ["info"]
- #' hero_button: ["is-secondary", "is-outlined"]
- #' hero_links:
- #' - name: Github
- #' url: https://github.com/
- #' icon: '`r bulma::fa_icon("github")`'
- #' - name: Twitter
- #' url: https://twitter.com
- #' icon: "fab fa-twitter"
- #' ---
- #' ```
- #'
- #' @inheritParams rmarkdown::html_document_base
- #' @inheritDotParams rmarkdown::html_document_base
- #' @export
- bulma_document <- function(
- ...,
- css = NULL,
- fig_width = 10,
- fig_height = 7,
- fig_retina = 2,
- keep_md = FALSE,
- dev = "png",
- toc = FALSE,
- toc_depth = 3,
- mathjax = "default",
- pandoc_args = NULL,
- extra_dependencies = NULL
- ) {
- css_files <- c(
- "--css", bulma_file("bulma", "bulma.min.css"))
-
- if (!is.null(css)) {
- for (css_file in css) {
- css_files <- c(css_files, "--css", css_file)
- }
- }
- deps <- list(
- htmltools::htmlDependency(
- name = "bulma",
- version = "0.7.2",
- src = bulma_file("bulma"),
- stylesheet = "bulma.min.css"
- ),
- rmarkdown::html_dependency_font_awesome(),
- if (toc) htmltools::htmlDependency(
- name = "gumshoe",
- version = "3.5.1",
- src = bulma_file("bulma"),
- script = "gumshoe.min.js"
- ),
- if (toc) htmltools::htmlDependency(
- name = "vanillajs-scrollspy",
- version = "2.0.3",
- src = bulma_file("bulma"),
- script = "vanillajs-scrollspy.min.js"
- )
- )
-
- deps <- deps[!vapply(deps, is.null, logical(1))]
- extra_dependencies <- append(extra_dependencies, deps)
-
- # preprocessor ----
- pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
- # browser()
- }
-
- pandoc_args <- c(pandoc_args, rmarkdown::pandoc_toc_args(toc, toc_depth))
-
- mathjax_url <- if (mathjax %in% c("default", "local")) {
- mathjax_local <- Sys.getenv("RMARKDOWN_MATHJAX_PATH", unset = NA)
- if (mathjax == "local" && is.na(mathjax_local)) {
- rlang::warn(
- glue("Please use `Sys.setenv('RMARKDOWN_MATHJAX_PATH')` to set local mathjax location.",
- "Falling back to online mathjax from https://mathjax.rstudio.com")
- )
- }
- mathjax_path <- ifelse(mathjax == "default" || is.na(mathjax_local),
- "https://mathjax.rstudio.com/latest",
- mathjax_local)
- file.path(mathjax_path, "MathJax.js?config=TeX-AMS-MML_HTMLorMML")
- } else mathjax
-
- if (!is.null(mathjax_url)) {
- pandoc_args <- c(pandoc_args, "--mathjax", "--variable",
- paste0("mathjax-url:", mathjax_url))
- }
-
- rmarkdown::output_format(
- knitr = rmarkdown::knitr_options_html(
- fig_width, fig_height, fig_retina, keep_md, dev
- ),
- pandoc = rmarkdown::pandoc_options(
- to = "html",
- from = "markdown+ascii_identifiers+tex_math_single_backslash",
- args = c(
- css_files,
- pandoc_args,
- "--variable", "rmarkdown-will-handle-deps",
- "--template",
- bulma_file("bulma", "bulma.html")
- ),
- ),
- pre_processor = pre_processor,
- clean_supporting = TRUE,
- base_format = rmarkdown::html_document_base(
- self_contained = TRUE, template = NULL,
- # pandoc_args = pandoc_args,
- mathjax = mathjax,
- extra_dependencies = extra_dependencies
- )
- )
- }
-
-
- bulma_file <- function(...) {
- system.file(..., package = "bulma")
- }
|