Skip to content

Commit f61a4f8

Browse files
Rollup merge of #58033 - euclio:rustdoc-tags, r=QuietMisdreavus
rustdoc: wrap stability tags in colored spans A cosmetic change to make the stability tags stand out a bit against the docs. Opening for discussion. Before: ![screen shot 2019-01-31 at 3 29 36 pm](https://user-images.githubusercontent.com/1372438/52083406-54730d80-256d-11e9-8e61-b8caff569434.png) ![screen shot 2019-01-31 at 3 31 32 pm](https://user-images.githubusercontent.com/1372438/52083408-54730d80-256d-11e9-97b7-43e808448f65.png) After: ![screen shot 2019-01-31 at 3 29 18 pm](https://user-images.githubusercontent.com/1372438/52083405-54730d80-256d-11e9-9983-19d9519b2ed8.png) ![screen shot 2019-01-31 at 3 29 46 pm](https://user-images.githubusercontent.com/1372438/52083407-54730d80-256d-11e9-8c32-11a1ad7d3f34.png) r? @QuietMisdreavus
2 parents 1a99a32 + ea2b1b0 commit f61a4f8

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
@@ -2811,9 +2811,13 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
28112811
fn stability_tags(item: &clean::Item) -> String {
28122812
let mut tags = String::new();
28132813

2814+
fn tag_html(class: &str, contents: &str) -> String {
2815+
format!(r#"<span class="stab {}">{}</span>"#, class, contents)
2816+
}
2817+
28142818
// The trailing space after each tag is to space it properly against the rest of the docs.
28152819
if item.deprecation().is_some() {
2816-
tags.push_str("[<div class='stab deprecated'>Deprecated</div>] ");
2820+
tags += &tag_html("deprecated", "Deprecated");
28172821
}
28182822

28192823
if let Some(stab) = item
@@ -2822,17 +2826,14 @@ fn stability_tags(item: &clean::Item) -> String {
28222826
.filter(|s| s.level == stability::Unstable)
28232827
{
28242828
if stab.feature.as_ref().map(|s| &**s) == Some("rustc_private") {
2825-
tags.push_str("[<div class='stab internal'>Internal</div>] ");
2829+
tags += &tag_html("internal", "Internal");
28262830
} else {
2827-
tags.push_str("[<div class='stab unstable'>Experimental</div>] ");
2831+
tags += &tag_html("unstable", "Experimental");
28282832
}
28292833
}
28302834

28312835
if let Some(ref cfg) = item.attrs.cfg {
2832-
tags.push_str(&format!(
2833-
"[<div class='stab portability'>{}</div>] ",
2834-
cfg.render_short_html()
2835-
));
2836+
tags += &tag_html("portability", &cfg.render_short_html());
28362837
}
28372838

28382839
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)