From ea2b1b035b3aa2e0e464dabb0e46f6c2092d357f Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Mon, 14 Jan 2019 10:02:27 -0500 Subject: [PATCH] rustdoc: wrap stability tags in colored spans --- src/librustdoc/html/render.rs | 15 ++++++++------- src/librustdoc/html/static/rustdoc.css | 13 ++++++++----- src/test/rustdoc/deprecated.rs | 6 ++++-- src/test/rustdoc/inline_cross/macros.rs | 3 ++- src/test/rustdoc/internal.rs | 6 ++++-- src/test/rustdoc/issue-32374.rs | 7 +++++-- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 86fb51419c2..c74e4647cdb 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2798,9 +2798,13 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, fn stability_tags(item: &clean::Item) -> String { let mut tags = String::new(); + fn tag_html(class: &str, contents: &str) -> String { + format!(r#"{}"#, class, contents) + } + // The trailing space after each tag is to space it properly against the rest of the docs. if item.deprecation().is_some() { - tags.push_str("[
Deprecated
] "); + tags += &tag_html("deprecated", "Deprecated"); } if let Some(stab) = item @@ -2809,17 +2813,14 @@ fn stability_tags(item: &clean::Item) -> String { .filter(|s| s.level == stability::Unstable) { if stab.feature.as_ref().map(|s| &**s) == Some("rustc_private") { - tags.push_str("[
Internal
] "); + tags += &tag_html("internal", "Internal"); } else { - tags.push_str("[
Experimental
] "); + tags += &tag_html("unstable", "Experimental"); } } if let Some(ref cfg) = item.attrs.cfg { - tags.push_str(&format!( - "[
{}
] ", - cfg.render_short_html() - )); + tags += &tag_html("portability", &cfg.render_short_html()); } tags diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 36765496ff4..b2105860067 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -767,11 +767,14 @@ body.blur > :not(#help) { } .module-item .stab { - display: inline; - border-width: 0; - padding: 0; - margin: 0; - background: inherit !important; + border-radius: 3px; + display: inline-block; + font-size: 80%; + line-height: 1.2; + margin-bottom: 0; + margin-right: .3em; + padding: 2px; + vertical-align: text-bottom; } .module-item.unstable { diff --git a/src/test/rustdoc/deprecated.rs b/src/test/rustdoc/deprecated.rs index ca3f380ed28..74bd94548e0 100644 --- a/src/test/rustdoc/deprecated.rs +++ b/src/test/rustdoc/deprecated.rs @@ -1,7 +1,9 @@ #![feature(deprecated)] -// @matches deprecated/index.html '//*[@class="docblock-short"]' \ -// '^\[Deprecated\] Deprecated docs' +// @has deprecated/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' \ +// 'Deprecated' +// @has - '//*[@class="docblock-short"]' 'Deprecated docs' + // @has deprecated/struct.S.html '//*[@class="stab deprecated"]' \ // 'Deprecated since 1.0.0: text' /// Deprecated docs diff --git a/src/test/rustdoc/inline_cross/macros.rs b/src/test/rustdoc/inline_cross/macros.rs index 4e370062385..f9bf982659e 100644 --- a/src/test/rustdoc/inline_cross/macros.rs +++ b/src/test/rustdoc/inline_cross/macros.rs @@ -7,7 +7,8 @@ extern crate macros; -// @has foo/index.html '//*[@class="docblock-short"]' '[Deprecated] [Experimental]' +// @has foo/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' Deprecated +// @has - '//*[@class="docblock-short"]/span[@class="stab unstable"]' Experimental // @has foo/macro.my_macro.html // @has - '//*[@class="docblock"]' 'docs for my_macro' diff --git a/src/test/rustdoc/internal.rs b/src/test/rustdoc/internal.rs index ba58da138a8..2cb7c472cc8 100644 --- a/src/test/rustdoc/internal.rs +++ b/src/test/rustdoc/internal.rs @@ -1,7 +1,9 @@ // compile-flags: -Z force-unstable-if-unmarked -// @matches internal/index.html '//*[@class="docblock-short"]' \ -// '^\[Internal\] Docs' +// @matches internal/index.html '//*[@class="docblock-short"]/span[@class="stab internal"]' \ +// 'Internal' +// @matches - '//*[@class="docblock-short"]' 'Docs' + // @has internal/struct.S.html '//*[@class="stab internal"]' \ // 'This is an internal compiler API. (rustc_private)' /// Docs diff --git a/src/test/rustdoc/issue-32374.rs b/src/test/rustdoc/issue-32374.rs index 58876a1aa11..7babfaf6060 100644 --- a/src/test/rustdoc/issue-32374.rs +++ b/src/test/rustdoc/issue-32374.rs @@ -3,8 +3,11 @@ #![unstable(feature="test", issue = "32374")] -// @matches issue_32374/index.html '//*[@class="docblock-short"]' \ -// '^\[Deprecated\] \[Experimental\] Docs' +// @matches issue_32374/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' \ +// 'Deprecated' +// @matches issue_32374/index.html '//*[@class="docblock-short"]/span[@class="stab unstable"]' \ +// 'Experimental' +// @matches issue_32374/index.html '//*[@class="docblock-short"]/text()' 'Docs' // @has issue_32374/struct.T.html '//*[@class="stab deprecated"]' \ // 'Deprecated since 1.0.0: text'