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
This commit is contained in:
Guillaume Gomez 2019-02-07 14:28:34 +01:00 committed by GitHub
commit f61a4f86db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 19 deletions

View file

@ -2811,9 +2811,13 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
fn stability_tags(item: &clean::Item) -> String { fn stability_tags(item: &clean::Item) -> String {
let mut tags = String::new(); let mut tags = String::new();
fn tag_html(class: &str, contents: &str) -> String {
format!(r#"<span class="stab {}">{}</span>"#, class, contents)
}
// The trailing space after each tag is to space it properly against the rest of the docs. // The trailing space after each tag is to space it properly against the rest of the docs.
if item.deprecation().is_some() { if item.deprecation().is_some() {
tags.push_str("[<div class='stab deprecated'>Deprecated</div>] "); tags += &tag_html("deprecated", "Deprecated");
} }
if let Some(stab) = item if let Some(stab) = item
@ -2822,17 +2826,14 @@ fn stability_tags(item: &clean::Item) -> String {
.filter(|s| s.level == stability::Unstable) .filter(|s| s.level == stability::Unstable)
{ {
if stab.feature.as_ref().map(|s| &**s) == Some("rustc_private") { if stab.feature.as_ref().map(|s| &**s) == Some("rustc_private") {
tags.push_str("[<div class='stab internal'>Internal</div>] "); tags += &tag_html("internal", "Internal");
} else { } else {
tags.push_str("[<div class='stab unstable'>Experimental</div>] "); tags += &tag_html("unstable", "Experimental");
} }
} }
if let Some(ref cfg) = item.attrs.cfg { if let Some(ref cfg) = item.attrs.cfg {
tags.push_str(&format!( tags += &tag_html("portability", &cfg.render_short_html());
"[<div class='stab portability'>{}</div>] ",
cfg.render_short_html()
));
} }
tags tags

View file

@ -767,11 +767,14 @@ body.blur > :not(#help) {
} }
.module-item .stab { .module-item .stab {
display: inline; border-radius: 3px;
border-width: 0; display: inline-block;
padding: 0; font-size: 80%;
margin: 0; line-height: 1.2;
background: inherit !important; margin-bottom: 0;
margin-right: .3em;
padding: 2px;
vertical-align: text-bottom;
} }
.module-item.unstable { .module-item.unstable {

View file

@ -1,7 +1,9 @@
#![feature(deprecated)] #![feature(deprecated)]
// @matches deprecated/index.html '//*[@class="docblock-short"]' \ // @has deprecated/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' \
// '^\[Deprecated\] Deprecated docs' // 'Deprecated'
// @has - '//*[@class="docblock-short"]' 'Deprecated docs'
// @has deprecated/struct.S.html '//*[@class="stab deprecated"]' \ // @has deprecated/struct.S.html '//*[@class="stab deprecated"]' \
// 'Deprecated since 1.0.0: text' // 'Deprecated since 1.0.0: text'
/// Deprecated docs /// Deprecated docs

View file

@ -7,7 +7,8 @@
extern crate macros; 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 foo/macro.my_macro.html
// @has - '//*[@class="docblock"]' 'docs for my_macro' // @has - '//*[@class="docblock"]' 'docs for my_macro'

View file

@ -1,7 +1,9 @@
// compile-flags: -Z force-unstable-if-unmarked // compile-flags: -Z force-unstable-if-unmarked
// @matches internal/index.html '//*[@class="docblock-short"]' \ // @matches internal/index.html '//*[@class="docblock-short"]/span[@class="stab internal"]' \
// '^\[Internal\] Docs' // 'Internal'
// @matches - '//*[@class="docblock-short"]' 'Docs'
// @has internal/struct.S.html '//*[@class="stab internal"]' \ // @has internal/struct.S.html '//*[@class="stab internal"]' \
// 'This is an internal compiler API. (rustc_private)' // 'This is an internal compiler API. (rustc_private)'
/// Docs /// Docs

View file

@ -3,8 +3,11 @@
#![unstable(feature="test", issue = "32374")] #![unstable(feature="test", issue = "32374")]
// @matches issue_32374/index.html '//*[@class="docblock-short"]' \ // @matches issue_32374/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' \
// '^\[Deprecated\] \[Experimental\] Docs' // '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"]' \ // @has issue_32374/struct.T.html '//*[@class="stab deprecated"]' \
// 'Deprecated since 1.0.0: text' // 'Deprecated since 1.0.0: text'