Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

107 lines
2.9KB

  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. #' @inheritDotParams rmarkdown::html_document_base
  33. #' @export
  34. bulma_document <- function(
  35. ...,
  36. css = NULL,
  37. fig_width = 10,
  38. fig_height = 7,
  39. fig_retina = 2,
  40. keep_md = FALSE,
  41. dev = "png",
  42. toc = FALSE,
  43. toc_depth = 3,
  44. pandoc_args = NULL,
  45. extra_dependencies = NULL
  46. ) {
  47. css_files <- c(
  48. "--css", bulma_file("bulma", "bulma.0.7.2.min.css"))
  49. if (!is.null(css)) {
  50. for (css_file in css) {
  51. css_files <- c(css_files, "--css", css_file)
  52. }
  53. }
  54. # rmarkdown::html_document_base(
  55. # pandoc_args = c(
  56. # css_files,
  57. # pandoc_args,
  58. # "--template",
  59. # system.file("bulma", "bulma.html", package="bulma")
  60. # ),
  61. # ...
  62. # )
  63. deps <- htmltools::htmlDependency(
  64. name = "bulma",
  65. version = "0.7.2",
  66. src = bulma_file("bulma"),
  67. stylesheet = "bulma.0.7.2.min.css"
  68. )
  69. extra_dependencies <- append(extra_dependencies, list(deps, rmarkdown::html_dependency_font_awesome()))
  70. # preprocessor ----
  71. pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
  72. # browser()
  73. }
  74. pandoc_args <- c(pandoc_args, rmarkdown::pandoc_toc_args(toc, toc_depth))
  75. rmarkdown::output_format(
  76. knitr = rmarkdown::knitr_options_html(
  77. fig_width, fig_height, fig_retina, keep_md, dev
  78. ),
  79. pandoc = rmarkdown::pandoc_options(
  80. to = "html",
  81. from = "markdown+ascii_identifiers+tex_math_single_backslash",
  82. args = c(
  83. css_files,
  84. pandoc_args,
  85. "--template",
  86. bulma_file("bulma", "bulma.html")
  87. ),
  88. ),
  89. pre_processor = pre_processor,
  90. clean_supporting = TRUE,
  91. base_format = rmarkdown::html_document_base(
  92. self_contained = TRUE, template = NULL,
  93. pandoc_args = pandoc_args,
  94. extra_dependencies = extra_dependencies
  95. )
  96. )
  97. }
  98. bulma_file <- function(...) {
  99. system.file(..., package = "bulma")
  100. }