1
Fork 0

Rollup merge of #92602 - jsha:source-link-2, r=GuillaumeGomez

Make source links look cleaner

Change from syntaxy-looking [src] to the plain word "source".

Change the syntaxy-looking `[-]` at the top of the page to say "collapse".

Reduce opacity of rightside content.

Part of #59851

r? `@GuillaumeGomez`

Demo: https://rustdoc.crud.net/jsha/source-link-2/std/string/struct.String.html

[Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/display.20of.20source.20link).
This commit is contained in:
Matthias Krüger 2022-01-10 11:03:06 +01:00 committed by GitHub
commit a4ac4fae41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 96 additions and 79 deletions

View file

@ -35,8 +35,8 @@
//! development you may want to press the `[-]` button near the top of the //! development you may want to press the `[-]` button near the top of the
//! page to collapse it into a more skimmable view. //! page to collapse it into a more skimmable view.
//! //!
//! While you are looking at that `[-]` button also notice the `[src]` //! While you are looking at that `[-]` button also notice the `source`
//! button. Rust's API documentation comes with the source code and you are //! link. Rust's API documentation comes with the source code and you are
//! encouraged to read it. The standard library source is generally high //! encouraged to read it. The standard library source is generally high
//! quality and a peek behind the curtains is often enlightening. //! quality and a peek behind the curtains is often enlightening.
//! //!

View file

@ -65,7 +65,7 @@ crate struct Context<'tcx> {
/// ///
/// [#82381]: https://github.com/rust-lang/rust/issues/82381 /// [#82381]: https://github.com/rust-lang/rust/issues/82381
crate shared: Rc<SharedContext<'tcx>>, crate shared: Rc<SharedContext<'tcx>>,
/// This flag indicates whether `[src]` links should be generated or not. If /// This flag indicates whether source links should be generated or not. If
/// the source files are present in the html rendering, then this will be /// the source files are present in the html rendering, then this will be
/// `true`. /// `true`.
crate include_sources: bool, crate include_sources: bool,

View file

@ -182,7 +182,7 @@ impl StylePath {
fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) { fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) {
if let Some(l) = cx.src_href(item) { if let Some(l) = cx.src_href(item) {
write!(buf, "<a class=\"srclink\" href=\"{}\" title=\"goto source code\">[src]</a>", l) write!(buf, "<a class=\"srclink\" href=\"{}\" title=\"goto source code\">source</a>", l)
} }
} }
@ -799,7 +799,7 @@ fn render_stability_since_raw(
const_stability: Option<ConstStability>, const_stability: Option<ConstStability>,
containing_ver: Option<Symbol>, containing_ver: Option<Symbol>,
containing_const_ver: Option<Symbol>, containing_const_ver: Option<Symbol>,
) { ) -> bool {
let ver = ver.filter(|inner| !inner.is_empty()); let ver = ver.filter(|inner| !inner.is_empty());
match (ver, const_stability) { match (ver, const_stability) {
@ -842,8 +842,9 @@ fn render_stability_since_raw(
v v
); );
} }
_ => {} _ => return false,
} }
true
} }
fn render_assoc_item( fn render_assoc_item(
@ -1632,7 +1633,7 @@ fn render_impl(
} }
// Render the items that appear on the right side of methods, impls, and // Render the items that appear on the right side of methods, impls, and
// associated types. For example "1.0.0 (const: 1.39.0) [src]". // associated types. For example "1.0.0 (const: 1.39.0) · source".
fn render_rightside( fn render_rightside(
w: &mut Buffer, w: &mut Buffer,
cx: &Context<'_>, cx: &Context<'_>,
@ -1650,13 +1651,16 @@ fn render_rightside(
}; };
write!(w, "<div class=\"rightside\">"); write!(w, "<div class=\"rightside\">");
render_stability_since_raw( let has_stability = render_stability_since_raw(
w, w,
item.stable_since(tcx), item.stable_since(tcx),
const_stability, const_stability,
containing_item.stable_since(tcx), containing_item.stable_since(tcx),
const_stable_since, const_stable_since,
); );
if has_stability {
w.write_str(" · ");
}
write_srclink(cx, item, w); write_srclink(cx, item, w);
w.write_str("</div>"); w.write_str("</div>");

View file

@ -108,10 +108,10 @@ pub(super) fn print_item(
); );
let stability_since_raw: String = stability_since_raw.into_inner(); let stability_since_raw: String = stability_since_raw.into_inner();
// Write `src` tag // Write source tag
// //
// When this item is part of a `crate use` in a downstream crate, the // When this item is part of a `crate use` in a downstream crate, the
// [src] link in the downstream documentation will actually come back to // source link in the downstream documentation will actually come back to
// this page, and this link will be auto-clicked. The `id` attribute is // this page, and this link will be auto-clicked. The `id` attribute is
// used to find the link to auto-click. // used to find the link to auto-click.
let src_href = let src_href =
@ -1467,7 +1467,7 @@ fn render_stability_since(
item.const_stability(tcx), item.const_stability(tcx),
containing_item.stable_since(tcx), containing_item.stable_since(tcx),
containing_item.const_stable_since(tcx), containing_item.const_stable_since(tcx),
) );
} }
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering { fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering {

View file

@ -137,17 +137,25 @@ h1, h2, h3, h4 {
margin: 15px 0 5px 0; margin: 15px 0 5px 0;
} }
h1.fqn { h1.fqn {
margin: 0;
padding: 0;
}
.main-heading {
display: flex; display: flex;
border-bottom: 1px dashed; border-bottom: 1px dashed #DDDDDD;
margin-top: 0; padding-bottom: 6px;
margin-bottom: 15px;
/* workaround to keep flex from breaking below 700 px width due to the float: right on the nav /* workaround to keep flex from breaking below 700 px width due to the float: right on the nav
above the h1 */ above the h1 */
padding-left: 1px; padding-left: 1px;
} }
h1.fqn > .in-band > a:hover { .main-heading a:hover {
text-decoration: underline; text-decoration: underline;
} }
#toggle-all-docs {
text-decoration: none;
}
/* The only headings that get underlines are: /* The only headings that get underlines are:
Markdown-generated headings within the top-doc Markdown-generated headings within the top-doc
Rustdoc-generated h2 section headings (e.g. "Implementations", "Required Methods", etc) Rustdoc-generated h2 section headings (e.g. "Implementations", "Required Methods", etc)
@ -195,11 +203,13 @@ h1, h2, h3, h4, h5, h6,
.sidebar, a.source, .search-input, .search-results .result-name, .sidebar, a.source, .search-input, .search-results .result-name,
.content table td:first-child > a, .content table td:first-child > a,
.item-left > a, .item-left > a,
div.item-list .out-of-band, span.since, .out-of-band,
span.since,
#source-sidebar, #sidebar-toggle, #source-sidebar, #sidebar-toggle,
details.rustdoc-toggle > summary::before, details.rustdoc-toggle > summary::before,
div.impl-items > div:not(.docblock):not(.item-info), div.impl-items > div:not(.docblock):not(.item-info),
.content ul.crate a.crate, a.srclink, .content ul.crate a.crate,
a.srclink,
/* This selector is for the items listed in the "all items" page. */ /* This selector is for the items listed in the "all items" page. */
#main-content > ul.docblock > li > a { #main-content > ul.docblock > li > a {
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif; font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
@ -609,10 +619,12 @@ nav.sub {
.content .out-of-band { .content .out-of-band {
flex-grow: 0; flex-grow: 0;
text-align: right; text-align: right;
font-size: 1.4375rem; margin-left: auto;
margin: 0px; margin-right: 0;
font-size: 1.15rem;
padding: 0 0 0 12px; padding: 0 0 0 12px;
font-weight: normal; font-weight: normal;
float: right;
} }
.method > .code-header, .trait-impl > .code-header, .invisible > .code-header { .method > .code-header, .trait-impl > .code-header, .invisible > .code-header {
@ -1082,7 +1094,7 @@ body.blur > :not(#help) {
font-size: initial; font-size: initial;
} }
.impl-items .since, .impl .since, .methods .since { .rightside {
padding-left: 12px; padding-left: 12px;
padding-right: 2px; padding-right: 2px;
position: initial; position: initial;
@ -1160,10 +1172,6 @@ a.test-arrow:hover{
font-weight: 300; font-weight: 300;
} }
.since + .srclink {
padding-left: 10px;
}
.item-spacer { .item-spacer {
width: 100%; width: 100%;
height: 12px; height: 12px;

View file

@ -222,7 +222,7 @@ nav.main .separator {
a { a {
color: #39AFD7; color: #39AFD7;
} }
a.srclink,
a#toggle-all-docs, a#toggle-all-docs,
a.anchor, a.anchor,
.small-section-header a, .small-section-header a,

View file

@ -180,7 +180,7 @@ nav.main .separator {
a { a {
color: #D2991D; color: #D2991D;
} }
a.srclink,
a#toggle-all-docs, a#toggle-all-docs,
a.anchor, a.anchor,
.small-section-header a, .small-section-header a,

View file

@ -177,7 +177,7 @@ nav.main .separator {
a { a {
color: #3873AD; color: #3873AD;
} }
a.srclink,
a#toggle-all-docs, a#toggle-all-docs,
a.anchor, a.anchor,
.small-section-header a, .small-section-header a,
@ -243,10 +243,6 @@ details.undocumented > summary::before {
border-color: #bfbfbf; border-color: #bfbfbf;
} }
.since {
color: grey;
}
.result-name .primitive > i, .result-name .keyword > i { .result-name .primitive > i, .result-name .keyword > i {
color: black; color: black;
} }

View file

@ -1,26 +1,28 @@
<h1 class="fqn"> {#- -#} <div class="main-heading">
<span class="in-band"> {#- -#} <h1 class="fqn"> {#- -#}
{{-typ-}} <span class="in-band"> {#- -#}
{#- The breadcrumbs of the item path, like std::string -#} {{-typ-}}
{%- for component in path_components -%} {#- The breadcrumbs of the item path, like std::string -#}
<a href="{{component.path | safe}}index.html">{{component.name}}</a>::<wbr> {%- for component in path_components -%}
{%- endfor -%} <a href="{{component.path | safe}}index.html">{{component.name}}</a>::<wbr>
<a class="{{item_type}}" href="#">{{name}}</a> {#- -#} {%- endfor -%}
<button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"> {#- -#} <a class="{{item_type}}" href="#">{{name}}</a> {#- -#}
<img src="{{static_root_path | safe}}clipboard{{page.resource_suffix}}.svg" {# -#} <button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"> {#- -#}
width="19" height="18" {# -#} <img src="{{static_root_path | safe}}clipboard{{page.resource_suffix}}.svg" {# -#}
alt="Copy item path"> {#- -#} width="19" height="18" {# -#}
</button> {#- -#} alt="Copy item path"> {#- -#}
</span> {#- -#} </button> {#- -#}
<span class="out-of-band"> {#- -#}
{{- stability_since_raw | safe -}}
<span id="render-detail"> {#- -#}
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> {#- -#}
[<span class="inner">&#x2212;</span>] {#- -#}
</a> {#- -#}
</span> {#- -#} </span> {#- -#}
{%- if src_href -%} </h1> {#- -#}
<a class="srclink" href="{{src_href | safe}}" title="goto source code">[src]</a> <span class="out-of-band"> {#- -#}
{%- endif -%} {% if stability_since_raw %}
{{- stability_since_raw | safe -}} ·
{% endif %}
{%- if src_href %}
<a class="srclink" href="{{src_href | safe}}" title="goto source code">source</a> ·
{% endif -%}
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> {#- -#}
[<span class="inner">&#x2212;</span>] {#- -#}
</a> {#- -#}
</span> {#- -#} </span> {#- -#}
</h1> {#- -#} </div>

View file

@ -13,8 +13,10 @@ reload:
assert-css: ("#toggle-all-docs", {"color": "rgb(0, 0, 0)"}) assert-css: ("#toggle-all-docs", {"color": "rgb(0, 0, 0)"})
assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(0, 0, 0)"}) assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(0, 0, 0)"})
assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(173, 55, 138)"}) assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(173, 55, 138)"})
assert-css: (".srclink", {"color": "rgb(0, 0, 0)"}) assert-css: (".srclink", {"color": "rgb(56, 115, 173)"})
assert-css: (".srclink", {"color": "rgb(0, 0, 0)"})
move-cursor-to: ".main-heading .srclink"
assert-css: (".srclink", {"text-decoration": "underline solid rgb(56, 115, 173)"})
assert-css: ("#top-doc-prose-title", {"color": "rgb(0, 0, 0)"}) assert-css: ("#top-doc-prose-title", {"color": "rgb(0, 0, 0)"})

View file

@ -15,7 +15,7 @@
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
assert-css: ("h1.fqn", {"font-size": "24px"}) assert-css: ("h1.fqn", {"font-size": "24px"})
assert-css: ("h1.fqn", {"border-bottom-width": "1px"}) assert-css: (".main-heading", {"border-bottom-width": "1px"})
assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"}) assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"})
assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"}) assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})
@ -55,7 +55,7 @@ assert-css: ("h6#sub-sub-heading-for-struct-impl-item-doc", {"font-size": "15.2p
goto: file://|DOC_PATH|/test_docs/enum.HeavilyDocumentedEnum.html goto: file://|DOC_PATH|/test_docs/enum.HeavilyDocumentedEnum.html
assert-css: ("h1.fqn", {"font-size": "24px"}) assert-css: ("h1.fqn", {"font-size": "24px"})
assert-css: ("h1.fqn", {"border-bottom-width": "1px"}) assert-css: (".main-heading", {"border-bottom-width": "1px"})
assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"}) assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"})
assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"}) assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})
@ -115,7 +115,7 @@ assert-css: (".sidebar .others h3", {"border-bottom-width": "1px"}, ALL)
goto: file://|DOC_PATH|/test_docs/union.HeavilyDocumentedUnion.html goto: file://|DOC_PATH|/test_docs/union.HeavilyDocumentedUnion.html
assert-css: ("h1.fqn", {"font-size": "24px"}) assert-css: ("h1.fqn", {"font-size": "24px"})
assert-css: ("h1.fqn", {"border-bottom-width": "1px"}) assert-css: (".main-heading", {"border-bottom-width": "1px"})
assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"}) assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"})
assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"}) assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})
@ -148,7 +148,7 @@ assert-css: ("h6#sub-heading-for-union-impl-item-doc", {"border-bottom-width": "
goto: file://|DOC_PATH|/test_docs/macro.heavily_documented_macro.html goto: file://|DOC_PATH|/test_docs/macro.heavily_documented_macro.html
assert-css: ("h1.fqn", {"font-size": "24px"}) assert-css: ("h1.fqn", {"font-size": "24px"})
assert-css: ("h1.fqn", {"border-bottom-width": "1px"}) assert-css: (".main-heading", {"border-bottom-width": "1px"})
assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"}) assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"})
assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"}) assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})

View file

@ -1,10 +1,13 @@
goto: file://|DOC_PATH|/test_docs/index.html goto: file://|DOC_PATH|/test_docs/index.html
assert-attribute: ("#main-content > details.top-doc", {"open": ""}) assert-attribute: ("#main-content > details.top-doc", {"open": ""})
assert-text: ("#toggle-all-docs", "[]")
click: "#toggle-all-docs" click: "#toggle-all-docs"
wait-for: 1000 wait-for: 1000
// This is now collapsed so there shouldn't be the "open" attribute on details. // This is now collapsed so there shouldn't be the "open" attribute on details.
assert-attribute-false: ("#main-content > details.top-doc", {"open": ""}) assert-attribute-false: ("#main-content > details.top-doc", {"open": ""})
assert-text: ("#toggle-all-docs", "[+]")
click: "#toggle-all-docs" click: "#toggle-all-docs"
wait-for: 1000 wait-for: 1000
// Not collapsed anymore so the "open" attribute should be back. // Not collapsed anymore so the "open" attribute should be back.
assert-attribute: ("#main-content > details.top-doc", {"open": ""}) assert-attribute: ("#main-content > details.top-doc", {"open": ""})
assert-text: ("#toggle-all-docs", "[]")

View file

@ -2,5 +2,5 @@
// This test ensures that the [src] link is present on traits items. // This test ensures that the [src] link is present on traits items.
// @has foo/trait.Iterator.html '//div[@id="method.zip"]//a[@class="srclink"]' "[src]" // @has foo/trait.Iterator.html '//div[@id="method.zip"]//a[@class="srclink"]' "source"
pub use std::iter::Iterator; pub use std::iter::Iterator;

View file

@ -5,8 +5,8 @@
#[macro_use] #[macro_use]
extern crate external_macro_src; extern crate external_macro_src;
// @has foo/index.html '//a[@href="../src/foo/external-macro-src.rs.html#3-12"]' '[src]' // @has foo/index.html '//a[@href="../src/foo/external-macro-src.rs.html#3-12"]' 'source'
// @has foo/struct.Foo.html // @has foo/struct.Foo.html
// @has - '//a[@href="../src/foo/external-macro-src.rs.html#12"]' '[src]' // @has - '//a[@href="../src/foo/external-macro-src.rs.html#12"]' 'source'
make_foo!(); make_foo!();

View file

@ -1,8 +1,10 @@
pub struct Foo; pub struct Foo;
// @has issue_16265_1/traits/index.html '[src]' // @has issue_16265_1/traits/index.html 'source'
pub mod traits { pub mod traits {
impl PartialEq for super::Foo { impl PartialEq for super::Foo {
fn eq(&self, _: &super::Foo) -> bool { true } fn eq(&self, _: &super::Foo) -> bool {
true
}
} }
} }

View file

@ -1,4 +1,4 @@
// @has issue_16265_2/index.html '[src]' // @has issue_16265_2/index.html 'source'
trait Y {} trait Y {}
impl Y for Option<u32>{} impl Y for Option<u32> {}

View file

@ -7,5 +7,5 @@
extern crate issue_26606_macro; extern crate issue_26606_macro;
// @has issue_26606/constant.FOO.html // @has issue_26606/constant.FOO.html
// @has - '//a[@href="../src/issue_26606/issue-26606.rs.html#11"]' '[src]' // @has - '//a[@href="../src/issue_26606/issue-26606.rs.html#11"]' 'source'
make_item!(FOO); make_item!(FOO);

View file

@ -2,11 +2,11 @@
// @has foo/struct.Unsized.html // @has foo/struct.Unsized.html
// @has - '//div[@id="impl-Sized"]/h3[@class="code-header in-band"]' 'impl !Sized for Unsized' // @has - '//div[@id="impl-Sized"]/h3[@class="code-header in-band"]' 'impl !Sized for Unsized'
// @!has - '//div[@id="impl-Sized"]//a[@class="srclink"]' '[src]' // @!has - '//div[@id="impl-Sized"]//a[@class="srclink"]' 'source'
// @has - '//div[@id="impl-Sync"]/h3[@class="code-header in-band"]' 'impl Sync for Unsized' // @has - '//div[@id="impl-Sync"]/h3[@class="code-header in-band"]' 'impl Sync for Unsized'
// @!has - '//div[@id="impl-Sync"]//a[@class="srclink"]' '[src]' // @!has - '//div[@id="impl-Sync"]//a[@class="srclink"]' 'source'
// @has - '//div[@id="impl-Any"]/h3[@class="code-header in-band"]' 'impl<T> Any for T' // @has - '//div[@id="impl-Any"]/h3[@class="code-header in-band"]' 'impl<T> Any for T'
// @has - '//div[@id="impl-Any"]//a[@class="srclink"]' '[src]' // @has - '//div[@id="impl-Any"]//a[@class="srclink"]' 'source'
pub struct Unsized { pub struct Unsized {
data: [u8], data: [u8],
} }

View file

@ -1,6 +1,6 @@
#![crate_name = "foo"] #![crate_name = "foo"]
// @has foo/index.html '//a[@href="../src/foo/thread-local-src.rs.html#1-6"]' '[src]' // @has foo/index.html '//a[@href="../src/foo/thread-local-src.rs.html#1-6"]' 'source'
// @has foo/constant.FOO.html '//a[@href="../src/foo/thread-local-src.rs.html#6"]' '[src]' // @has foo/constant.FOO.html '//a[@href="../src/foo/thread-local-src.rs.html#6"]' 'source'
thread_local!(pub static FOO: bool = false); thread_local!(pub static FOO: bool = false);

View file

@ -1,26 +1,26 @@
#![crate_name = "quix"] #![crate_name = "quix"]
pub trait Foo { pub trait Foo {
// @has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#4"]' '[src]' // @has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#4"]' 'source'
fn required(); fn required();
// @has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' '[src]' // @has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' 'source'
fn provided() {} fn provided() {}
} }
pub struct Bar; pub struct Bar;
impl Foo for Bar { impl Foo for Bar {
// @has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#14"]' '[src]' // @has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#14"]' 'source'
fn required() {} fn required() {}
// @has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' '[src]' // @has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' 'source'
} }
pub struct Baz; pub struct Baz;
impl Foo for Baz { impl Foo for Baz {
// @has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#22"]' '[src]' // @has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#22"]' 'source'
fn required() {} fn required() {}
// @has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#25"]' '[src]' // @has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#25"]' 'source'
fn provided() {} fn provided() {}
} }