Rmarkdown HTML Document based on Primer CSS
Source:R/html_document_primer.R
html_document_primer.Rd
HTML documents with R Markdown.
Usage
html_document_primer(
...,
auto_theme = TRUE,
light_theme = "light",
dark_theme = "dark_dimmed",
list_style = NULL,
enable_checkboxes = FALSE,
css = NULL,
toc = FALSE,
toc_depth = 3,
header = TRUE,
mathjax = NULL,
fig_width = 10,
fig_height = 7,
fig_retina = 2,
footer = TRUE,
keep_md = FALSE,
dev = "png",
highlight = TRUE,
pandoc_args = NULL,
extra_dependencies = NULL,
md_extensions = NULL,
self_contained = TRUE
)
Arguments
- auto_theme
Indicates whether the theme should be changed based on user's system preferences
- light_theme
The light theme, e.g., "light"
- dark_theme
The dark theme, e.g., "dark", "dark_dimmed", "dark_high_contrast"
- list_style
Indicates whether list elements should use bullets or not
- enable_checkboxes
Indicates whether or not check boxes can be modified
- css
CSS and/or Sass files to include. Files with an extension of .sass or .scss are compiled to CSS via
sass::sass()
. Also, iftheme
is abslib::bs_theme()
object, Sass code may reference the relevant Bootstrap Sass variables, functions, mixins, etc.- toc
TRUE
to include a table of contents in the output- toc_depth
Depth of headers to include in table of contents
- header
Indicates whether the title should be included as a header in the output document
- mathjax
Include mathjax. The "default" option uses an https URL from a MathJax CDN. The "local" option uses a local version of MathJax (which is copied into the output directory). You can pass an alternate URL or pass
NULL
to exclude MathJax entirely.- fig_width
Default width (in inches) for figures
- fig_height
Default height (in inches) for figures
- fig_retina
Scaling to perform for retina displays (defaults to 2, which currently works for all widely used retina displays). Set to
NULL
to prevent retina scaling. Note that this will always beNULL
whenkeep_md
is specified (this is becausefig_retina
relies on outputting HTML directly into the markdown document).- footer
Indicates whether the footer should be shown
- keep_md
Keep the markdown file generated by knitting.
- dev
Graphics device to use for figure output (defaults to png)
- highlight
Indicates whether or not the code should be highlighted
- pandoc_args
Additional command line options to pass to pandoc
- extra_dependencies, ...
Additional function arguments to pass to the base R Markdown HTML output formatter
html_document_base
- md_extensions
Markdown extensions to be added or removed from the default definition of R Markdown. See the
rmarkdown_format
for additional details.- self_contained
Produce a standalone HTML file with no external dependencies, using data: URIs to incorporate the contents of linked scripts, stylesheets, images, and videos. Note that even for self contained documents MathJax is still loaded externally (this is necessary because of its size).
Value
An R Markdown output format that can be used with output:
in an
.Rmd
or for use with rmarkdown::render()
.
MathJax
Note that MathJax is disabled by default to reduce the
overall size of the final document. You can enable MathJax by setting
mathjax = "default"
, see rmarkdown::html_document()
for more options.
Examples
html_document_primer()
#> [[1]]
#> List of 10
#> $ name : chr "primermd"
#> $ version : chr "0.0.1"
#> $ src :List of 1
#> ..$ file: chr "resources/primer"
#> $ meta : NULL
#> $ script : NULL
#> $ stylesheet: chr "primer.css"
#> $ head : NULL
#> $ attachment: NULL
#> $ package : chr "primermd"
#> $ all_files : logi FALSE
#> - attr(*, "class")= chr "html_dependency"
#>
#> [[2]]
#> List of 10
#> $ name : chr "header-attrs"
#> $ version : chr "9999"
#> $ src :List of 1
#> ..$ href: chr ""
#> $ meta : NULL
#> $ script : NULL
#> $ stylesheet: NULL
#> $ head : NULL
#> $ attachment: NULL
#> $ package : NULL
#> $ all_files : logi TRUE
#> - attr(*, "class")= chr "html_dependency"
#>
#> $knitr
#> $knitr$opts_knit
#> NULL
#>
#> $knitr$opts_chunk
#> $knitr$opts_chunk$dev
#> [1] "png"
#>
#> $knitr$opts_chunk$dpi
#> [1] 96
#>
#> $knitr$opts_chunk$fig.width
#> [1] 10
#>
#> $knitr$opts_chunk$fig.height
#> [1] 7
#>
#> $knitr$opts_chunk$fig.retina
#> [1] 2
#>
#>
#> $knitr$knit_hooks
#> NULL
#>
#> $knitr$opts_hooks
#> NULL
#>
#> $knitr$opts_template
#> NULL
#>
#>
#> $pandoc
#> $pandoc$to
#> [1] "html5"
#>
#> $pandoc$from
#> [1] "markdown+autolink_bare_uris+tex_math_single_backslash"
#>
#> $pandoc$args
#> [1] "--self-contained"
#> [2] "--variable"
#> [3] "auto-theme"
#> [4] "--variable"
#> [5] "light-theme=light"
#> [6] "--variable"
#> [7] "dark-theme=dark_dimmed"
#> [8] "--variable"
#> [9] "header"
#> [10] "--variable"
#> [11] "footer"
#> [12] "--css"
#> [13] "/Users/runner/work/_temp/Library/primermd/resources/pandoc/highlight.css"
#> [14] "--template"
#> [15] "/Users/runner/work/_temp/Library/primermd/template/primermd.html"
#>
#> $pandoc$keep_tex
#> [1] FALSE
#>
#> $pandoc$latex_engine
#> [1] "pdflatex"
#>
#> $pandoc$ext
#> NULL
#>
#> $pandoc$lua_filters
#> [1] "/Users/runner/work/_temp/Library/rmarkdown/rmarkdown/lua/pagebreak.lua"
#> [2] "/Users/runner/work/_temp/Library/rmarkdown/rmarkdown/lua/latex-div.lua"
#>
#>
#> $keep_md
#> [1] FALSE
#>
#> $clean_supporting
#> [1] TRUE
#>
#> $df_print
#> NULL
#>
#> $pre_knit
#> function (input, ...)
#> {
#> if (is_bs_theme(theme)) {
#> for (f in css) theme <<- bslib::bs_add_rules(theme, xfun::read_utf8(f))
#> css <<- NULL
#> old_theme <<- bslib::bs_global_set(theme)
#> }
#> }
#> <bytecode: 0x7fc398cbee80>
#> <environment: 0x7fc398ce47a0>
#>
#> $post_knit
#> function (metadata, input_file, runtime, ...)
#> {
#> }
#> <bytecode: 0x7fc398cc1f58>
#> <environment: 0x7fc398ce47a0>
#>
#> $pre_processor
#> function (metadata, input_file, runtime, knit_meta, files_dir,
#> output_dir)
#> {
#> args <- c()
#> if (is.null(lib_dir))
#> lib_dir <<- files_dir
#> output_dir <<- output_dir
#> if (!is.null(theme)) {
#> theme_arg <- if (is.list(theme))
#> "bootstrap"
#> else theme
#> args <- c(args, pandoc_variable_arg("theme", theme_arg))
#> }
#> for (f in css) {
#> if (grepl("\\.s[ac]ss$", f)) {
#> if (!xfun::loadable("sass")) {
#> stop2("Using `.sass` or `.scss` file in `css` argument requires the sass package.")
#> }
#> f <- sass::sass(sass::sass_file(f), output = sass::output_template(basename = xfun::sans_ext(basename(f)),
#> dirname = "sass", path = lib_dir), options = sass::sass_options(output_style = "compressed"))
#> f <- normalized_relative_to(output_dir, f)
#> }
#> args <- c(args, "--css", pandoc_path_arg(f, backslash = FALSE))
#> }
#> math_support <- add_math_support(math, template, lib_dir,
#> output_dir)
#> args <- c(args, math_support$args)
#> extra_dependencies <- c(extra_dependencies, math_support$extra_dependencies)
#> format_deps <- list()
#> format_deps <- append(format_deps, html_dependency_header_attrs())
#> if (!is.null(theme)) {
#> format_deps <- append(format_deps, list(html_dependency_jquery()))
#> if (is_bs_theme(theme)) {
#> theme <- bslib::bs_global_get()
#> }
#> bootstrap_deps <- if (is_bs_theme(theme) && is_shiny(runtime,
#> metadata[["server"]])) {
#> list(shiny_bootstrap_lib(theme))
#> }
#> else {
#> bootstrap_dependencies(theme)
#> }
#> format_deps <- append(format_deps, htmltools::resolveDependencies(bootstrap_deps))
#> }
#> else if (isTRUE(bootstrap_compatible) && is_shiny(runtime,
#> metadata[["server"]])) {
#> format_deps <- append(format_deps, bootstrap_dependencies("bootstrap"))
#> }
#> format_deps <- append(format_deps, extra_dependencies)
#> extras <- html_extras_for_document(knit_meta, runtime, dependency_resolver,
#> format_deps)
#> args <- c(args, pandoc_html_extras_args(extras, self_contained,
#> lib_dir, output_dir))
#> preserved_chunks <<- extract_preserve_chunks(input_file)
#> args
#> }
#> <bytecode: 0x7fc398cc1970>
#> <environment: 0x7fc398ce47a0>
#>
#> $intermediates_generator
#> function (original_input, intermediates_dir)
#> {
#> copy_render_intermediates(original_input, intermediates_dir,
#> !self_contained)
#> }
#> <bytecode: 0x7fc398ccee00>
#> <environment: 0x7fc398ce47a0>
#>
#> $post_processor
#> function (metadata, input_file, output_file, clean, verbose)
#> {
#> if (identical(math_method, "r-katex") && xfun::pkg_available("katex",
#> "1.4.0")) {
#> katex::render_math_in_html(output_file, output = output_file)
#> }
#> output_str <- read_utf8(output_file)
#> s1 <- "<span class=\"sc\">|</span><span class=\"er\">></span>"
#> s2 <- "<span class=\"ot\">=</span><span class=\"er\">></span>"
#> if ((length(preserved_chunks) == 0 && !isTRUE(copy_resources) &&
#> self_contained) && !length(c(grep(s1, output_str, fixed = TRUE),
#> grep(s2, output_str, fixed = TRUE))))
#> return(output_file)
#> if (length(preserved_chunks) > 0) {
#> for (i in names(preserved_chunks)) {
#> output_str <- gsub(paste0("<p>", i, "</p>"), i, output_str,
#> fixed = TRUE, useBytes = TRUE)
#> output_str <- gsub(paste0(" id=\"[^\"]*?", i, "[^\"]*?\" "),
#> " ", output_str, useBytes = TRUE)
#> }
#> output_str <- restorePreserveChunks(output_str, preserved_chunks)
#> }
#> if (copy_resources) {
#> output_str <- copy_html_resources(one_string(output_str),
#> lib_dir, output_dir)
#> }
#> else if (!self_contained) {
#> image_relative <- function(img_src, src) {
#> in_file <- utils::URLdecode(src)
#> if (grepl("^[.][.]", in_file))
#> return(img_src)
#> if (length(in_file) && file.exists(in_file)) {
#> img_src <- sub(src, utils::URLencode(normalized_relative_to(output_dir,
#> in_file)), img_src, fixed = TRUE)
#> }
#> img_src
#> }
#> output_str <- process_images(output_str, image_relative)
#> }
#> output_str <- gsub(s1, "<span class=\"sc\">|></span>",
#> output_str, fixed = TRUE)
#> output_str <- gsub(s2, "<span class=\"ot\">=></span>",
#> output_str, fixed = TRUE)
#> write_utf8(output_str, output_file)
#> output_file
#> }
#> <bytecode: 0x7fc398cce968>
#> <environment: 0x7fc398ce47a0>
#>
#> $on_exit
#> function ()
#> {
#> if (is.function(base))
#> base()
#> if (is.function(overlay))
#> overlay()
#> }
#> <bytecode: 0x7fc398dcaee8>
#> <environment: 0x7fc398dca9a8>
#>
#> attr(,"class")
#> [1] "rmarkdown_output_format"
if (FALSE) {
rmarkdown::render("input.Rmd", html_document_primer())
}