Skip to content

Commit 2f07ce1

Browse files
authored
add warning hook + CSS class for Rmd-based lessons (#455)
1 parent b5c2878 commit 2f07ce1

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

assets/css/lesson.scss

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $color-brand: #2b3990 !default;
1010

1111
// code boxes
1212
$color-error: #bd2c00 !default;
13+
$color-warning: #cda01d !default;
1314
$color-output: #303030 !default;
1415
$color-source: #360084 !default;
1516

@@ -36,9 +37,10 @@ $color-testimonial: #fc8dc1 !default;
3637
border-radius: 4px 0 0 4px;
3738
}
3839

39-
.error { @include cdSetup($color-error); }
40-
.output { @include cdSetup($color-output); }
41-
.source { @include cdSetup($color-source); }
40+
.error { @include cdSetup($color-error); }
41+
.warning { @include cdSetup($color-warning); }
42+
.output { @include cdSetup($color-output); }
43+
.source { @include cdSetup($color-source); }
4244

4345
.bash, .language-bash { @include cdSetup($color-source); }
4446
.make, .language-make { @include cdSetup($color-source); }
@@ -48,6 +50,7 @@ $color-testimonial: #fc8dc1 !default;
4850
.sql, .language-sql { @include cdSetup($color-source); }
4951

5052
.error::before,
53+
.warning:before,
5154
.output::before,
5255
.source::before,
5356
.bash::before, .language-bash::before,
@@ -56,13 +59,14 @@ $color-testimonial: #fc8dc1 !default;
5659
.python::before, .language-python::before,
5760
.r::before, .language-r::before,
5861
.sql::before, .language-sql::before {
59-
background-color: #f2eff6;
60-
display: block;
61-
font-weight: bold;
62-
padding: 5px 10px;
62+
background-color: #f2eff6;
63+
display: block;
64+
font-weight: bold;
65+
padding: 5px 10px;
6366
}
6467

6568
.error::before { background-color: #ffebe6; content: "Error"; }
69+
.warning:before { background-color: #f8f4e8; content:" Warning"; }
6670
.output::before { background-color: #efefef; content: "Output"; }
6771
.source::before { content: "Code"; }
6872
.bash::before, .language-bash::before { content: "Bash"; }

bin/chunk-options.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,23 @@ hook_in <- function(x, options) {
4848
hook_out <- function(x, options) {
4949
x <- gsub("\n$", "", x)
5050
stringr::str_c("\n\n~~~\n",
51-
paste0(x, collapse="\n"),
52-
"\n~~~\n{: .output}\n\n")
51+
paste0(x, collapse="\n"),
52+
"\n~~~\n{: .output}\n\n")
5353
}
5454

5555
hook_error <- function(x, options) {
5656
x <- gsub("\n$", "", x)
5757
stringr::str_c("\n\n~~~\n",
58-
paste0(x, collapse="\n"),
59-
"\n~~~\n{: .error}\n\n")
58+
paste0(x, collapse="\n"),
59+
"\n~~~\n{: .error}\n\n")
60+
}
61+
62+
hook_warning <- function(x, options) {
63+
x <- gsub("\n$", "", x)
64+
stringr::str_c("\n\n~~~\n",
65+
paste0(x, collapse = "\n"),
66+
"\n~~~\n{: .warning}\n\n")
6067
}
6168

62-
knit_hooks$set(source = hook_in, output = hook_out, warning = hook_error,
63-
error = hook_error, message = hook_out)
69+
knit_hooks$set(source = hook_in, output = hook_out, warning = hook_warning,
70+
error = hook_error, message = hook_out)

0 commit comments

Comments
 (0)