Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

146 lines
4.2KB

  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. ) {
  49. css_files <- c(
  50. "--css", bulma_file("bulma", "bulma.min.css"))
  51. if (!is.null(css)) {
  52. for (css_file in css) {
  53. css_files <- c(css_files, "--css", css_file)
  54. }
  55. }
  56. # rmarkdown::html_document_base(
  57. # pandoc_args = c(
  58. # css_files,
  59. # pandoc_args,
  60. # "--template",
  61. # system.file("bulma", "bulma.html", package="bulma")
  62. # ),
  63. # ...
  64. # )
  65. deps <- list(
  66. htmltools::htmlDependency(
  67. name = "bulma",
  68. version = "0.7.2",
  69. src = bulma_file("bulma"),
  70. stylesheet = "bulma.min.css"
  71. ),
  72. rmarkdown::html_dependency_font_awesome(),
  73. if (toc) htmltools::htmlDependency(
  74. name = "gumshoe",
  75. version = "3.5.1",
  76. src = bulma_file("bulma"),
  77. script = "gumshoe.min.js"
  78. ),
  79. if (toc) htmltools::htmlDependency(
  80. name = "vanillajs-scrollspy",
  81. version = "2.0.3",
  82. src = bulma_file("bulma"),
  83. script = "vanillajs-scrollspy.min.js"
  84. )
  85. )
  86. deps <- deps[!vapply(deps, is.null, logical(1))]
  87. extra_dependencies <- append(extra_dependencies, deps)
  88. # preprocessor ----
  89. pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
  90. # browser()
  91. }
  92. pandoc_args <- c(pandoc_args, rmarkdown::pandoc_toc_args(toc, toc_depth))
  93. mathjax_url <- if (mathjax %in% c("default", "local")) {
  94. mathjax_local <- Sys.getenv("RMARKDOWN_MATHJAX_PATH", unset = NA)
  95. if (mathjax == "local" && is.na(mathjax_local)) {
  96. rlang::warn(
  97. glue("Please use `Sys.setenv('RMARKDOWN_MATHJAX_PATH')` to set local mathjax location.",
  98. "Falling back to online mathjax from https://mathjax.rstudio.com")
  99. )
  100. }
  101. mathjax_path <- ifelse(mathjax == "default" || is.na(mathjax_local),
  102. "https://mathjax.rstudio.com/latest",
  103. mathjax_local)
  104. file.path(mathjax_path, "MathJax.js?config=TeX-AMS-MML_HTMLorMML")
  105. } else mathjax
  106. if (!is.null(mathjax_url)) {
  107. pandoc_args <- c(pandoc_args, "--mathjax", "--variable",
  108. paste0("mathjax-url:", mathjax_url))
  109. }
  110. rmarkdown::output_format(
  111. knitr = rmarkdown::knitr_options_html(
  112. fig_width, fig_height, fig_retina, keep_md, dev
  113. ),
  114. pandoc = rmarkdown::pandoc_options(
  115. to = "html",
  116. from = "markdown+ascii_identifiers+tex_math_single_backslash",
  117. args = c(
  118. css_files,
  119. pandoc_args,
  120. "--template",
  121. bulma_file("bulma", "bulma.html")
  122. ),
  123. ),
  124. pre_processor = pre_processor,
  125. clean_supporting = TRUE,
  126. base_format = rmarkdown::html_document_base(
  127. self_contained = TRUE, template = NULL,
  128. pandoc_args = pandoc_args,
  129. mathjax = mathjax,
  130. extra_dependencies = extra_dependencies
  131. )
  132. )
  133. }
  134. bulma_file <- function(...) {
  135. system.file(..., package = "bulma")
  136. }