Remove software carpentries logo
[rnaseq-cwl-training.git] / bin / chunk-options.R
index 6bd4aefaeb72ba14d2765e8dfffc8fa5592d91c9..8e0d62af7eed10817d7c3c4d2bc3534a8c2a2b2b 100644 (file)
@@ -37,24 +37,34 @@ opts_chunk$set(tidy = FALSE, results = "markup", comment = NA,
 # are properly formatted when the site is built.
 
 hook_in <- function(x, options) {
+  lg <- tolower(options$engine)
+  style <- paste0(".language-", lg)
+
   stringr::str_c("\n\n~~~\n",
-                 paste0(x, collapse="\n"),
-                 "\n~~~\n{: .language-r}\n\n")
+    paste0(x, collapse="\n"),
+    "\n~~~\n{: ", style, "}\n\n")
 }
 
 hook_out <- function(x, options) {
   x <- gsub("\n$", "", x)
   stringr::str_c("\n\n~~~\n",
-                 paste0(x, collapse="\n"),
-                 "\n~~~\n{: .output}\n\n")
+    paste0(x, collapse="\n"),
+    "\n~~~\n{: .output}\n\n")
 }
 
 hook_error <- function(x, options) {
   x <- gsub("\n$", "", x)
   stringr::str_c("\n\n~~~\n",
-                 paste0(x, collapse="\n"),
-                 "\n~~~\n{: .error}\n\n")
+    paste0(x, collapse="\n"),
+    "\n~~~\n{: .error}\n\n")
+}
+
+hook_warning <- function(x, options) {
+  x <- gsub("\n$", "", x)
+  stringr::str_c("\n\n~~~\n",
+    paste0(x, collapse = "\n"),
+    "\n~~~\n{: .warning}\n\n")
 }
 
-knit_hooks$set(source = hook_in, output = hook_out, warning = hook_error,
-               error = hook_error, message = hook_out)
+knit_hooks$set(source = hook_in, output = hook_out, warning = hook_warning,
+  error = hook_error, message = hook_out)