add warning hook + CSS class for Rmd-based lessons (#455)
authorFrançois Michonneau <francois.michonneau@gmail.com>
Mon, 10 Feb 2020 14:35:22 +0000 (09:35 -0500)
committerGitHub <noreply@github.com>
Mon, 10 Feb 2020 14:35:22 +0000 (09:35 -0500)
assets/css/lesson.scss
bin/chunk-options.R

index cba7c429a4f46ba9674054c181fc483106454c82..472e287187b5b2e5c64ce0ca0ca810fc4871f3fd 100644 (file)
@@ -10,6 +10,7 @@ $color-brand:       #2b3990 !default;
 
 // code boxes
 $color-error:       #bd2c00 !default;
+$color-warning:     #cda01d !default;
 $color-output:      #303030 !default;
 $color-source:      #360084 !default;
 
@@ -36,9 +37,10 @@ $color-testimonial: #fc8dc1 !default;
     border-radius: 4px 0 0 4px;
 }
 
-.error  { @include cdSetup($color-error); }
-.output { @include cdSetup($color-output); }
-.source { @include cdSetup($color-source); }
+.error   { @include cdSetup($color-error); }
+.warning { @include cdSetup($color-warning); }
+.output  { @include cdSetup($color-output); }
+.source  { @include cdSetup($color-source); }
 
 .bash, .language-bash     { @include cdSetup($color-source); }
 .make, .language-make     { @include cdSetup($color-source); }
@@ -48,6 +50,7 @@ $color-testimonial: #fc8dc1 !default;
 .sql, .language-sql       { @include cdSetup($color-source); }
 
 .error::before,
+.warning:before,
 .output::before,
 .source::before,
 .bash::before, .language-bash::before,
@@ -56,13 +59,14 @@ $color-testimonial: #fc8dc1 !default;
 .python::before, .language-python::before,
 .r::before, .language-r::before,
 .sql::before, .language-sql::before {
-  background-color: #f2eff6;
-  display: block;
-  font-weight: bold;
-  padding: 5px 10px;
+    background-color: #f2eff6;
+    display: block;
+    font-weight: bold;
+    padding: 5px 10px;
 }
 
 .error::before  { background-color: #ffebe6; content: "Error"; }
+.warning:before { background-color: #f8f4e8; content:" Warning"; }
 .output::before { background-color: #efefef; content: "Output"; }
 .source::before { content: "Code"; }
 .bash::before, .language-bash::before { content: "Bash"; }
index b0559cbe8330cf8ec77ead8083f6584faed0f541..8e0d62af7eed10817d7c3c4d2bc3534a8c2a2b2b 100644 (file)
@@ -48,16 +48,23 @@ hook_in <- function(x, options) {
 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)