Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: wrap stability tags in colored spans #58033

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"<span class="stab {}">{}</span>"#, 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("[<div class='stab deprecated'>Deprecated</div>] ");
tags += &tag_html("deprecated", "Deprecated");
}

if let Some(stab) = item
Expand All @@ -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("[<div class='stab internal'>Internal</div>] ");
tags += &tag_html("internal", "Internal");
} else {
tags.push_str("[<div class='stab unstable'>Experimental</div>] ");
tags += &tag_html("unstable", "Experimental");
}
}

if let Some(ref cfg) = item.attrs.cfg {
tags.push_str(&format!(
"[<div class='stab portability'>{}</div>] ",
cfg.render_short_html()
));
tags += &tag_html("portability", &cfg.render_short_html());
}

tags
Expand Down
13 changes: 8 additions & 5 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/test/rustdoc/deprecated.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/test/rustdoc/inline_cross/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions src/test/rustdoc/internal.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/test/rustdoc/issue-32374.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down