Skip to content

Commit ea2b1b0

Browse files
committed
rustdoc: wrap stability tags in colored spans
1 parent d30b99f commit ea2b1b0

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

src/librustdoc/html/render.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,9 +2798,13 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
27982798
fn stability_tags(item: &clean::Item) -> String {
27992799
let mut tags = String::new();
28002800

2801+
fn tag_html(class: &str, contents: &str) -> String {
2802+
format!(r#"<span class="stab {}">{}</span>"#, class, contents)
2803+
}
2804+
28012805
// The trailing space after each tag is to space it properly against the rest of the docs.
28022806
if item.deprecation().is_some() {
2803-
tags.push_str("[<div class='stab deprecated'>Deprecated</div>] ");
2807+
tags += &tag_html("deprecated", "Deprecated");
28042808
}
28052809

28062810
if let Some(stab) = item
@@ -2809,17 +2813,14 @@ fn stability_tags(item: &clean::Item) -> String {
28092813
.filter(|s| s.level == stability::Unstable)
28102814
{
28112815
if stab.feature.as_ref().map(|s| &**s) == Some("rustc_private") {
2812-
tags.push_str("[<div class='stab internal'>Internal</div>] ");
2816+
tags += &tag_html("internal", "Internal");
28132817
} else {
2814-
tags.push_str("[<div class='stab unstable'>Experimental</div>] ");
2818+
tags += &tag_html("unstable", "Experimental");
28152819
}
28162820
}
28172821

28182822
if let Some(ref cfg) = item.attrs.cfg {
2819-
tags.push_str(&format!(
2820-
"[<div class='stab portability'>{}</div>] ",
2821-
cfg.render_short_html()
2822-
));
2823+
tags += &tag_html("portability", &cfg.render_short_html());
28232824
}
28242825

28252826
tags

src/librustdoc/html/static/rustdoc.css

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,14 @@ body.blur > :not(#help) {
767767
}
768768

769769
.module-item .stab {
770-
display: inline;
771-
border-width: 0;
772-
padding: 0;
773-
margin: 0;
774-
background: inherit !important;
770+
border-radius: 3px;
771+
display: inline-block;
772+
font-size: 80%;
773+
line-height: 1.2;
774+
margin-bottom: 0;
775+
margin-right: .3em;
776+
padding: 2px;
777+
vertical-align: text-bottom;
775778
}
776779

777780
.module-item.unstable {

src/test/rustdoc/deprecated.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#![feature(deprecated)]
22

3-
// @matches deprecated/index.html '//*[@class="docblock-short"]' \
4-
// '^\[Deprecated\] Deprecated docs'
3+
// @has deprecated/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' \
4+
// 'Deprecated'
5+
// @has - '//*[@class="docblock-short"]' 'Deprecated docs'
6+
57
// @has deprecated/struct.S.html '//*[@class="stab deprecated"]' \
68
// 'Deprecated since 1.0.0: text'
79
/// Deprecated docs

src/test/rustdoc/inline_cross/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
extern crate macros;
99

10-
// @has foo/index.html '//*[@class="docblock-short"]' '[Deprecated] [Experimental]'
10+
// @has foo/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' Deprecated
11+
// @has - '//*[@class="docblock-short"]/span[@class="stab unstable"]' Experimental
1112

1213
// @has foo/macro.my_macro.html
1314
// @has - '//*[@class="docblock"]' 'docs for my_macro'

src/test/rustdoc/internal.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// compile-flags: -Z force-unstable-if-unmarked
22

3-
// @matches internal/index.html '//*[@class="docblock-short"]' \
4-
// '^\[Internal\] Docs'
3+
// @matches internal/index.html '//*[@class="docblock-short"]/span[@class="stab internal"]' \
4+
// 'Internal'
5+
// @matches - '//*[@class="docblock-short"]' 'Docs'
6+
57
// @has internal/struct.S.html '//*[@class="stab internal"]' \
68
// 'This is an internal compiler API. (rustc_private)'
79
/// Docs

src/test/rustdoc/issue-32374.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
#![unstable(feature="test", issue = "32374")]
55

6-
// @matches issue_32374/index.html '//*[@class="docblock-short"]' \
7-
// '^\[Deprecated\] \[Experimental\] Docs'
6+
// @matches issue_32374/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' \
7+
// 'Deprecated'
8+
// @matches issue_32374/index.html '//*[@class="docblock-short"]/span[@class="stab unstable"]' \
9+
// 'Experimental'
10+
// @matches issue_32374/index.html '//*[@class="docblock-short"]/text()' 'Docs'
811

912
// @has issue_32374/struct.T.html '//*[@class="stab deprecated"]' \
1013
// 'Deprecated since 1.0.0: text'

0 commit comments

Comments
 (0)