Remove the extra DOM level if there is only one child in rightside elements

This commit is contained in:
Guillaume Gomez 2022-08-24 15:33:56 +02:00
parent 097b3823dd
commit d40a18eb3d
4 changed files with 37 additions and 14 deletions

View File

@ -834,12 +834,13 @@ fn assoc_method(
/// Note that it is possible for an unstable function to be const-stable. In that case, the span
/// will include the const-stable version, but no stable version will be emitted, as a natural
/// consequence of the above rules.
fn render_stability_since_raw(
fn render_stability_since_raw_with_extra(
w: &mut Buffer,
ver: Option<Symbol>,
const_stability: Option<ConstStability>,
containing_ver: Option<Symbol>,
containing_const_ver: Option<Symbol>,
extra_class: &str,
) -> bool {
let stable_version = ver.filter(|inner| !inner.is_empty() && Some(*inner) != containing_ver);
@ -887,12 +888,30 @@ fn render_stability_since_raw(
}
if !stability.is_empty() {
write!(w, r#"<span class="since" title="{}">{}</span>"#, title, stability);
write!(w, r#"<span class="since{extra_class}" title="{title}">{stability}</span>"#);
}
!stability.is_empty()
}
#[inline]
fn render_stability_since_raw(
w: &mut Buffer,
ver: Option<Symbol>,
const_stability: Option<ConstStability>,
containing_ver: Option<Symbol>,
containing_const_ver: Option<Symbol>,
) -> bool {
render_stability_since_raw_with_extra(
w,
ver,
const_stability,
containing_ver,
containing_const_ver,
"",
)
}
fn render_assoc_item(
w: &mut Buffer,
item: &clean::Item,
@ -1675,25 +1694,29 @@ fn render_rightside(
RenderMode::Normal => (item.const_stability(tcx), containing_item.const_stable_since(tcx)),
RenderMode::ForDeref { .. } => (None, None),
};
let src_href = cx.src_href(item);
let has_src_ref = src_href.is_some();
let mut rightside = Buffer::new();
let has_stability = render_stability_since_raw(
let has_stability = render_stability_since_raw_with_extra(
&mut rightside,
item.stable_since(tcx),
const_stability,
containing_item.stable_since(tcx),
const_stable_since,
if has_src_ref { "" } else { " rightside" },
);
let mut srclink = Buffer::empty_from(w);
if let Some(l) = cx.src_href(item) {
write!(srclink, "<a class=\"srclink\" href=\"{}\">source</a>", l)
if let Some(l) = src_href {
if has_stability {
write!(rightside, " · <a class=\"srclink\" href=\"{}\">source</a>", l)
} else {
write!(rightside, "<a class=\"srclink rightside\" href=\"{}\">source</a>", l)
}
}
if has_stability && !srclink.is_empty() {
rightside.write_str(" · ");
}
rightside.push_buffer(srclink);
if !rightside.is_empty() {
if has_stability && has_src_ref {
write!(w, "<span class=\"rightside\">{}</span>", rightside.into_inner());
} else {
w.push_buffer(rightside);
}
}

View File

@ -199,7 +199,7 @@ details.rustdoc-toggle > summary::before {
background: none;
}
.rightside,
.rightside:not(a),
.out-of-band {
color: grey;
}

View File

@ -165,7 +165,7 @@ details.rustdoc-toggle > summary::before {
background: none;
}
.rightside,
.rightside:not(a),
.out-of-band {
color: grey;
}

View File

@ -148,7 +148,7 @@ details.rustdoc-toggle > summary::before {
.stab { background: #FFF5D6; border-color: #FFC600; }
.stab.portability > code { background: none; }
.rightside,
.rightside:not(a),
.out-of-band {
color: grey;
}