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

102 lines
2.8KB

  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_button`: Classes applied to the `header_links` buttons}
  9. #' \item{`hero_links`: Links that will be displayed under title as buttons.
  10. #' Formatted as a list, each element having entries for `name`, `url`,
  11. #' and `icon`. Icons use [Font Awesome](https://fontawesome.com/icons);
  12. #' see [fa_icon()] for help constructing the Font Awesome class. The
  13. #' full Font Awesome class name is required.}
  14. #' }
  15. #'
  16. #' ```
  17. #' ---
  18. #' bulma:
  19. #' hero: ["info"]
  20. #' hero_button: ["is-secondary", "is-outlined"]
  21. #' hero_links:
  22. #' - name: Github
  23. #' url: https://github.com/
  24. #' icon: '`r bulma::fa_icon("github")`'
  25. #' - name: Twitter
  26. #' url: https://twitter.com
  27. #' icon: "fab fa-twitter"
  28. #' ---
  29. #' ```
  30. #'
  31. #' @inheritDotParams rmarkdown::html_document_base
  32. #' @export
  33. bulma_document <- function(
  34. ...,
  35. css = NULL,
  36. fig_width = 10,
  37. fig_height = 7,
  38. fig_retina = 2,
  39. keep_md = FALSE,
  40. dev = "png",
  41. pandoc_args = NULL,
  42. extra_dependencies = NULL
  43. ) {
  44. css_files <- c(
  45. "--css", bulma_file("bulma", "bulma.0.7.2.min.css"))
  46. if (!is.null(css)) {
  47. for (css_file in css) {
  48. css_files <- c(css_files, "--css", css_file)
  49. }
  50. }
  51. # rmarkdown::html_document_base(
  52. # pandoc_args = c(
  53. # css_files,
  54. # pandoc_args,
  55. # "--template",
  56. # system.file("bulma", "bulma.html", package="bulma")
  57. # ),
  58. # ...
  59. # )
  60. deps <- htmltools::htmlDependency(
  61. name = "bulma",
  62. version = "0.7.2",
  63. src = bulma_file("bulma"),
  64. stylesheet = "bulma.0.7.2.min.css"
  65. )
  66. extra_dependencies <- append(extra_dependencies, list(deps, rmarkdown::html_dependency_font_awesome()))
  67. # preprocessor ----
  68. pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
  69. # browser()
  70. }
  71. rmarkdown::output_format(
  72. knitr = rmarkdown::knitr_options_html(
  73. fig_width, fig_height, fig_retina, keep_md, dev
  74. ),
  75. pandoc = rmarkdown::pandoc_options(
  76. to = "html",
  77. from = "markdown+ascii_identifiers+tex_math_single_backslash",
  78. args = c(
  79. css_files,
  80. pandoc_args,
  81. "--template",
  82. bulma_file("bulma", "bulma.html")
  83. ),
  84. ),
  85. pre_processor = pre_processor,
  86. clean_supporting = TRUE,
  87. base_format = rmarkdown::html_document_base(
  88. self_contained = TRUE, template = NULL,
  89. pandoc_args = pandoc_args,
  90. extra_dependencies = extra_dependencies
  91. )
  92. )
  93. }
  94. bulma_file <- function(...) {
  95. system.file(..., package = "bulma")
  96. }