Skip to content

Commit d51521e

Browse files
Add warning block support in rustdoc
1 parent 3071e0a commit d51521e

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/librustdoc/html/static/css/rustdoc.css

+23-3
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,15 @@ ul ul, ol ul, ul ol, ol ol {
270270
margin-bottom: .625em;
271271
}
272272

273-
p {
273+
p, .docblock > .warning {
274274
/* Paragraph spacing at least 1.5 times line spacing per Web Content Accessibility Guidelines.
275275
Line-height is 1.5rem, so line spacing is .5rem; .75em is 1.5 times that.
276276
https://www.w3.org/WAI/WCAG21/Understanding/visual-presentation.html */
277277
margin: 0 0 .75em 0;
278278
}
279279
/* For the last child of a div, the margin will be taken care of
280280
by the margin-top of the next item. */
281-
p:last-child {
281+
p:last-child, .docblock > .warning:last-child {
282282
margin: 0;
283283
}
284284

@@ -1096,7 +1096,7 @@ pre.rust .doccomment {
10961096
}
10971097

10981098
.example-wrap.ignore .tooltip {
1099-
color: var(--codeblock-ignore-color);
1099+
color: var(--codeblock-ignore-color);
11001100
}
11011101

11021102
.example-wrap.compile_fail:hover .tooltip,
@@ -1124,6 +1124,26 @@ pre.rust .doccomment {
11241124
font-size: 1.25rem;
11251125
}
11261126

1127+
/* This class only exists for users who want to draw attention to a particular element in their
1128+
documentation. */
1129+
.content .docblock .warning {
1130+
border-left: 2px solid var(--warning-border-color);
1131+
padding: 14px;
1132+
position: relative;
1133+
/* The "!important" part is required because the rule is otherwise overruled in this CSS
1134+
selector: ".docblock > :not(.more-examples-toggle):not(.example-wrap)" */
1135+
overflow-x: visible !important;
1136+
}
1137+
.content .docblock .warning::before {
1138+
color: var(--warning-border-color);
1139+
content: "ⓘ";
1140+
position: absolute;
1141+
left: -25px;
1142+
top: 5px;
1143+
font-weight: bold;
1144+
font-size: 1.25rem;
1145+
}
1146+
11271147
a.test-arrow {
11281148
visibility: hidden;
11291149
position: absolute;

src/librustdoc/html/static/css/themes/ayu.css

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
3131
--codeblock-error-color: rgba(255, 0, 0, .5);
3232
--codeblock-ignore-hover-color: rgb(255, 142, 0);
3333
--codeblock-ignore-color: rgba(255, 142, 0, .6);
34+
--warning-border-color: rgb(255, 142, 0);
3435
--type-link-color: #ffa0a5;
3536
--trait-link-color: #39afd7;
3637
--assoc-item-link-color: #39afd7;

src/librustdoc/html/static/css/themes/dark.css

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
--codeblock-error-color: rgba(255, 0, 0, .5);
2727
--codeblock-ignore-hover-color: rgb(255, 142, 0);
2828
--codeblock-ignore-color: rgba(255, 142, 0, .6);
29+
--warning-border-color: rgb(255, 142, 0);
2930
--type-link-color: #2dbfb8;
3031
--trait-link-color: #b78cf2;
3132
--assoc-item-link-color: #d2991d;

src/librustdoc/html/static/css/themes/light.css

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
--codeblock-error-color: rgba(255, 0, 0, .5);
2727
--codeblock-ignore-hover-color: rgb(255, 142, 0);
2828
--codeblock-ignore-color: rgba(255, 142, 0, .6);
29+
--warning-border-color: rgb(255, 142, 0);
2930
--type-link-color: #ad378a;
3031
--trait-link-color: #6e4fc9;
3132
--assoc-item-link-color: #3873ad;

0 commit comments

Comments
 (0)