Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

139 Zeilen
4.1KB

  1. #' Bulma Document Renderer
  2. #'
  3. #' @section YAML options:
  4. #' You can pass additional options to the underlying template via the `bulma`
  5. #' YAML item. The following options can be specified there.
  6. #' \itemize{
  7. #' \item{`hero`: Classes applied to the hero containing the title.}
  8. #' \item{`hero_body`: Classes applied to the hero body container.}
  9. #' \item{`hero_button`: Classes applied to the `header_links` buttons}
  10. #' \item{`hero_links`: Links that will be displayed under title as buttons.
  11. #' Formatted as a list, each element having entries for `name`, `url`,
  12. #' and `icon`. Icons use [Font Awesome](https://fontawesome.com/icons);
  13. #' see [fa_icon()] for help constructing the Font Awesome class. The
  14. #' full Font Awesome class name is required.}
  15. #' }
  16. #'
  17. #' ```
  18. #' ---
  19. #' bulma:
  20. #' hero: ["info"]
  21. #' hero_button: ["is-secondary", "is-outlined"]
  22. #' hero_links:
  23. #' - name: Github
  24. #' url: https://github.com/
  25. #' icon: '`r bulma::fa_icon("github")`'
  26. #' - name: Twitter
  27. #' url: https://twitter.com
  28. #' icon: "fab fa-twitter"
  29. #' ---
  30. #' ```
  31. #'
  32. #' @inheritParams rmarkdown::html_document_base
  33. #' @inheritDotParams rmarkdown::html_document_base
  34. #' @export
  35. bulma_document <- function(
  36. ...,
  37. css = NULL,
  38. fig_width = 10,
  39. fig_height = 7,
  40. fig_retina = 2,
  41. keep_md = FALSE,
  42. dev = "png",
  43. toc = FALSE,
  44. toc_depth = 3,
  45. mathjax = "default",
  46. pandoc_args = NULL,
  47. extra_dependencies = NULL,
  48. self_contained = TRUE
  49. ) {
  50. css_files <- c(
  51. "--css", bulma_file("bulma", "bulma.min.css"))
  52. if (!is.null(css)) {
  53. for (css_file in css) {
  54. css_files <- c(css_files, "--css", css_file)
  55. }
  56. }
  57. deps <- list(
  58. htmltools::htmlDependency(
  59. name = "bulma",
  60. version = "0.7.2",
  61. src = bulma_file("bulma"),
  62. stylesheet = "bulma.min.css"
  63. ),
  64. if (toc) htmltools::htmlDependency(
  65. name = "gumshoe",
  66. version = "3.5.1",
  67. src = bulma_file("bulma"),
  68. script = "gumshoe.min.js"
  69. ),
  70. if (toc) htmltools::htmlDependency(
  71. name = "smoothscroll",
  72. version = "0.4.0",
  73. src = bulma_file("bulma"),
  74. script = "smoothscroll.min.js"
  75. )
  76. )
  77. deps <- deps[!vapply(deps, is.null, logical(1))]
  78. extra_dependencies <- append(extra_dependencies, deps)
  79. # preprocessor ----
  80. pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
  81. # browser()
  82. }
  83. pandoc_args <- c(pandoc_args,
  84. rmarkdown::pandoc_toc_args(toc, toc_depth))
  85. mathjax_url <- if (mathjax %in% c("default", "local")) {
  86. mathjax_local <- Sys.getenv("RMARKDOWN_MATHJAX_PATH", unset = NA)
  87. if (mathjax == "local" && is.na(mathjax_local)) {
  88. rlang::warn(
  89. glue("Please use `Sys.setenv('RMARKDOWN_MATHJAX_PATH')` to set local mathjax location.",
  90. "Falling back to online mathjax from https://mathjax.rstudio.com")
  91. )
  92. }
  93. mathjax_path <- ifelse(mathjax == "default" || is.na(mathjax_local),
  94. "https://mathjax.rstudio.com/latest",
  95. mathjax_local)
  96. file.path(mathjax_path, "MathJax.js?config=TeX-AMS-MML_HTMLorMML")
  97. } else mathjax
  98. if (!is.null(mathjax_url)) {
  99. pandoc_args <- c(pandoc_args, "--mathjax", "--variable",
  100. paste0("mathjax-url:", mathjax_url))
  101. }
  102. rmarkdown::output_format(
  103. knitr = rmarkdown::knitr_options_html(
  104. fig_width, fig_height, fig_retina, keep_md, dev
  105. ),
  106. pandoc = rmarkdown::pandoc_options(
  107. to = "html5",
  108. from = "markdown+ascii_identifiers+tex_math_single_backslash",
  109. args = c(
  110. css_files,
  111. pandoc_args,
  112. "--variable", "rmarkdown-will-handle-deps",
  113. "--template",
  114. bulma_file("bulma", "bulma.html")
  115. ),
  116. ),
  117. pre_processor = pre_processor,
  118. clean_supporting = TRUE,
  119. base_format = rmarkdown::html_document_base(
  120. self_contained = self_contained, template = NULL,
  121. # pandoc_args = pandoc_args,
  122. mathjax = mathjax,
  123. extra_dependencies = extra_dependencies
  124. )
  125. )
  126. }
  127. bulma_file <- function(...) {
  128. system.file(..., package = "bulma")
  129. }