Skip to content

Commit 65dae11

Browse files
committed
Add .warning class for doc author use
This is designed to be compatible with rustdoc's version, in rust-lang/rust#106561
1 parent d5b1676 commit 65dae11

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

guide/src/format/mdbook.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,29 @@ contents (sidebar) by including a `\{{#title ...}}` near the top of the page.
314314
```hbs
315315
\{{#title My Title}}
316316
```
317+
318+
## HTML classes provided by mdBook
319+
320+
The `class="warning"` can be applied to make a warning, or similar note, stand out.
321+
322+
```html
323+
<div class="warning">
324+
325+
This is a bad thing that you should pay attention to.
326+
327+
Warning blocks should be used sparingly in documentation, to avoid "warning
328+
fatique," where people are trained to ignore them because they usually don't
329+
matter for what they're doing.
330+
331+
</div>
332+
```
333+
334+
<div class="warning">
335+
336+
This is a bad thing that you should pay attention to.
337+
338+
Warning blocks should be used sparingly in documentation, to avoid "warning
339+
fatique," where people are trained to ignore them because they usually don't
340+
matter for what they're doing.
341+
342+
</div>

src/theme/css/general.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,29 @@ blockquote {
156156
border-block-end: .1em solid var(--quote-border);
157157
}
158158

159+
.warning {
160+
margin: 20px;
161+
padding: 0 20px;
162+
border-inline-start: 2px solid var(--warning-border);
163+
}
164+
165+
.warning:before {
166+
position: absolute;
167+
width: 3rem;
168+
height: 3rem;
169+
margin-inline-start: calc(-1.5rem - 21px);
170+
content: "ⓘ";
171+
text-align: center;
172+
background-color: var(--bg);
173+
color: var(--warning-border);
174+
font-weight: bold;
175+
font-size: 2rem;
176+
}
177+
178+
blockquote .warning:before {
179+
background-color: var(--quote-bg);
180+
}
181+
159182
kbd {
160183
background-color: var(--table-border-color);
161184
border-radius: 4px;

src/theme/css/variables.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
--quote-bg: hsl(226, 15%, 17%);
3939
--quote-border: hsl(226, 15%, 22%);
4040

41+
--warning-border: #ff8e00;
42+
4143
--table-border-color: hsl(210, 25%, 13%);
4244
--table-header-bg: hsl(210, 25%, 28%);
4345
--table-alternate-bg: hsl(210, 25%, 11%);
@@ -80,6 +82,8 @@
8082
--quote-bg: hsl(234, 21%, 18%);
8183
--quote-border: hsl(234, 21%, 23%);
8284

85+
--warning-border: #ff8e00;
86+
8387
--table-border-color: hsl(200, 7%, 13%);
8488
--table-header-bg: hsl(200, 7%, 28%);
8589
--table-alternate-bg: hsl(200, 7%, 11%);
@@ -122,6 +126,8 @@
122126
--quote-bg: hsl(197, 37%, 96%);
123127
--quote-border: hsl(197, 37%, 91%);
124128

129+
--warning-border: #ff8e00;
130+
125131
--table-border-color: hsl(0, 0%, 95%);
126132
--table-header-bg: hsl(0, 0%, 80%);
127133
--table-alternate-bg: hsl(0, 0%, 97%);
@@ -164,6 +170,8 @@
164170
--quote-bg: hsl(226, 15%, 17%);
165171
--quote-border: hsl(226, 15%, 22%);
166172

173+
--warning-border: #ff8e00;
174+
167175
--table-border-color: hsl(226, 23%, 16%);
168176
--table-header-bg: hsl(226, 23%, 31%);
169177
--table-alternate-bg: hsl(226, 23%, 14%);
@@ -206,6 +214,8 @@
206214
--quote-bg: hsl(60, 5%, 75%);
207215
--quote-border: hsl(60, 5%, 70%);
208216

217+
--warning-border: #ff8e00;
218+
209219
--table-border-color: hsl(60, 9%, 82%);
210220
--table-header-bg: #b3a497;
211221
--table-alternate-bg: hsl(60, 9%, 84%);
@@ -249,6 +259,8 @@
249259
--quote-bg: hsl(234, 21%, 18%);
250260
--quote-border: hsl(234, 21%, 23%);
251261

262+
--warning-border: #ff8e00;
263+
252264
--table-border-color: hsl(200, 7%, 13%);
253265
--table-header-bg: hsl(200, 7%, 28%);
254266
--table-alternate-bg: hsl(200, 7%, 11%);

0 commit comments

Comments
 (0)