Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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