From 94c84bd72a0fd9c9e0dbcff43c21e6a862cae6cf Mon Sep 17 00:00:00 2001 From: Stefan Schindler Date: Fri, 18 Jun 2021 00:33:42 +0200 Subject: [PATCH] Migrate from custom elements to divs with classes to be compatible with safari --- src/librustdoc/html/render/mod.rs | 2 +- src/librustdoc/html/render/print_item.rs | 29 ++++++++++++-------- src/librustdoc/html/static/rustdoc.css | 16 +++++------ src/test/rustdoc/deprecated.rs | 6 ++-- src/test/rustdoc/doc-cfg.rs | 6 ++-- src/test/rustdoc/duplicate-cfg.rs | 4 +-- src/test/rustdoc/inline_cross/macros.rs | 4 +-- src/test/rustdoc/internal.rs | 8 ++++-- src/test/rustdoc/issue-32374.rs | 10 +++---- src/test/rustdoc/issue-46377.rs | 2 +- src/test/rustdoc/issue-55364.rs | 8 +++--- src/test/rustdoc/reexport-check.rs | 6 ++-- src/test/rustdoc/short-docblock-codeblock.rs | 6 ++-- src/test/rustdoc/short-docblock.rs | 25 +++++++++++++++++ src/test/rustdoc/short-dockblock.rs | 25 ----------------- 15 files changed, 82 insertions(+), 75 deletions(-) create mode 100644 src/test/rustdoc/short-docblock.rs delete mode 100644 src/test/rustdoc/short-dockblock.rs diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 7e6d394bbec..10584e3eaca 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1694,7 +1694,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { write!( buffer, "
\ -
+
\

Version {}

\
", Escape(version), diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 5f1291c0b16..5fd0607356d 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -29,6 +29,9 @@ use crate::html::highlight; use crate::html::layout::Page; use crate::html::markdown::MarkdownSummaryLine; +const ITEM_TABLE_OPEN: &'static str = "
"; +const ITEM_TABLE_CLOSE: &'static str = "
"; + pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, page: &Page<'_>) { debug_assert!(!item.is_stripped()); // Write the breadcrumb trail header for the top @@ -263,14 +266,15 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl curty = myty; } else if myty != curty { if curty.is_some() { - w.write_str(""); + w.write_str(ITEM_TABLE_CLOSE); } curty = myty; let (short, name) = item_ty_to_strs(myty.unwrap()); write!( w, "

\ - {name}

\n", + {name}\n{}", + ITEM_TABLE_OPEN, id = cx.derive_id(short.to_owned()), name = name ); @@ -283,14 +287,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl match *src { Some(ref src) => write!( w, - "{}extern crate {} as {};", + "
{}extern crate {} as {};", myitem.visibility.print_with_space(myitem.def_id, cx), anchor(myitem.def_id.expect_real(), &*src.as_str(), cx), myitem.name.as_ref().unwrap(), ), None => write!( w, - "{}extern crate {};", + "
{}extern crate {};", myitem.visibility.print_with_space(myitem.def_id, cx), anchor( myitem.def_id.expect_real(), @@ -299,7 +303,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl ), ), } - w.write_str("\n"); + w.write_str("
"); } clean::ImportItem(ref import) => { @@ -326,10 +330,10 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl write!( w, - "\ + "
\ {vis}{imp}\ - \ - {stab_tags}", +
\ +
{stab_tags}
", stab = stab.unwrap_or_default(), add = add, vis = myitem.visibility.print_with_space(myitem.def_id, cx), @@ -358,10 +362,11 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl let doc_value = myitem.doc_value().unwrap_or_default(); write!( w, - "\ + "
\ {name}{unsafety_flag}\ - {stab_tags}{docs}", + title=\"{title}\">{name}{unsafety_flag}\ +
\ +
{stab_tags}{docs}
", name = *myitem.name.as_ref().unwrap(), stab_tags = extra_info_tags(myitem, item, cx.tcx()), docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(), @@ -381,7 +386,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl } if curty.is_some() { - w.write_str(""); + w.write_str(ITEM_TABLE_CLOSE); } } diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index a3ae22308b5..3b52fd94d27 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -169,7 +169,7 @@ div.impl-items > div { h1, h2, h3, h4, .sidebar, a.source, .search-input, .search-results .result-name, .content table td:first-child > a, -item-left > a, +.item-left > a, div.item-list .out-of-band, span.since, #source-sidebar, #sidebar-toggle, details.rustdoc-toggle > summary::before, @@ -711,7 +711,7 @@ a { .block a.current.crate { font-weight: 500; } -item-table { +.item-table { display: grid; column-gap: 1.2rem; row-gap: 0.0rem; @@ -720,13 +720,13 @@ item-table { justify-items: start; } -item-left, item-right { +.item-left, .item-right { display: block; } -item-left { +.item-left { grid-column: 1; } -item-right { +.item-right { grid-column: 2; } @@ -1775,11 +1775,11 @@ details.undocumented[open] > summary::before { } /* Display an alternating layout on tablets and phones */ - item-table { + .item-table { display: flex; flex-flow: column wrap; } - item-left, item-right { + .item-left, .item-right { width: 100%; } @@ -1795,7 +1795,7 @@ details.undocumented[open] > summary::before { .search-results .result-name, .search-results div.desc, .search-results .result-description { width: 100%; } - .search-results div.desc, .search-results .result-description, item-right { + .search-results div.desc, .search-results .result-description, .item-right { padding-left: 2em; } } diff --git a/src/test/rustdoc/deprecated.rs b/src/test/rustdoc/deprecated.rs index a286856b2c3..444624b034c 100644 --- a/src/test/rustdoc/deprecated.rs +++ b/src/test/rustdoc/deprecated.rs @@ -1,6 +1,6 @@ -// @has deprecated/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' \ +// @has deprecated/index.html '//*[@class="item-right docblock-short"]/span[@class="stab deprecated"]' \ // 'Deprecated' -// @has - '//*[@class="docblock-short"]' 'Deprecated docs' +// @has - '//*[@class="item-right docblock-short"]' 'Deprecated docs' // @has deprecated/struct.S.html '//*[@class="stab deprecated"]' \ // 'Deprecated since 1.0.0: text' @@ -8,7 +8,7 @@ #[deprecated(since = "1.0.0", note = "text")] pub struct S; -// @matches deprecated/index.html '//*[@class="docblock-short"]' '^Docs' +// @matches deprecated/index.html '//*[@class="item-right docblock-short"]' '^Docs' /// Docs pub struct T; diff --git a/src/test/rustdoc/doc-cfg.rs b/src/test/rustdoc/doc-cfg.rs index bc30e45556a..bd47ae4438d 100644 --- a/src/test/rustdoc/doc-cfg.rs +++ b/src/test/rustdoc/doc-cfg.rs @@ -12,7 +12,7 @@ pub struct Portable; // @has doc_cfg/unix_only/index.html \ // '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \ // 'This is supported on Unix only.' -// @matches - '//*[@class="docblock-short"]//*[@class="stab portability"]' '\AARM\Z' +// @matches - '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '\AARM\Z' // @count - '//*[@class="stab portability"]' 2 #[doc(cfg(unix))] pub mod unix_only { @@ -42,7 +42,7 @@ pub mod unix_only { // @has doc_cfg/wasi_only/index.html \ // '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \ // 'This is supported on WASI only.' -// @matches - '//*[@class="docblock-short"]//*[@class="stab portability"]' '\AWebAssembly\Z' +// @matches - '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '\AWebAssembly\Z' // @count - '//*[@class="stab portability"]' 2 #[doc(cfg(target_os = "wasi"))] pub mod wasi_only { @@ -74,7 +74,7 @@ pub mod wasi_only { // the portability header is different on the module view versus the full view // @has doc_cfg/index.html -// @matches - '//*[@class="docblock-short"]//*[@class="stab portability"]' '\Aavx\Z' +// @matches - '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '\Aavx\Z' // @has doc_cfg/fn.uses_target_feature.html // @has - '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \ diff --git a/src/test/rustdoc/duplicate-cfg.rs b/src/test/rustdoc/duplicate-cfg.rs index 30bb6b0fc74..e3241a8746e 100644 --- a/src/test/rustdoc/duplicate-cfg.rs +++ b/src/test/rustdoc/duplicate-cfg.rs @@ -2,8 +2,8 @@ #![feature(doc_cfg)] // @has 'foo/index.html' -// @matches '-' '//*[@class="docblock-short"]//*[@class="stab portability"]' '^sync$' -// @has '-' '//*[@class="docblock-short"]//*[@class="stab portability"]/@title' 'This is supported on crate feature `sync` only' +// @matches '-' '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '^sync$' +// @has '-' '//*[@class="item-right docblock-short"]//*[@class="stab portability"]/@title' 'This is supported on crate feature `sync` only' // @has 'foo/struct.Foo.html' // @has '-' '//*[@class="stab portability"]' 'sync' diff --git a/src/test/rustdoc/inline_cross/macros.rs b/src/test/rustdoc/inline_cross/macros.rs index f9bf982659e..601797fd64c 100644 --- a/src/test/rustdoc/inline_cross/macros.rs +++ b/src/test/rustdoc/inline_cross/macros.rs @@ -7,8 +7,8 @@ extern crate macros; -// @has foo/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' Deprecated -// @has - '//*[@class="docblock-short"]/span[@class="stab unstable"]' Experimental +// @has foo/index.html '//*[@class="item-right docblock-short"]/span[@class="stab deprecated"]' Deprecated +// @has - '//*[@class="item-right 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 a1e322fb9a3..f316eb24a48 100644 --- a/src/test/rustdoc/internal.rs +++ b/src/test/rustdoc/internal.rs @@ -2,9 +2,11 @@ // Check that the unstable marker is not added for "rustc_private". -// @!matches internal/index.html '//*[@class="docblock-short"]/span[@class="stab unstable"]' -// @!matches internal/index.html '//*[@class="docblock-short"]/span[@class="stab internal"]' -// @matches - '//*[@class="docblock-short"]' 'Docs' +// @!matches internal/index.html \ +// '//*[@class="item-right docblock-short"]/span[@class="stab unstable"]' +// @!matches internal/index.html \ +// '//*[@class="item-right docblock-short"]/span[@class="stab internal"]' +// @matches - '//*[@class="item-right docblock-short"]' 'Docs' // @!has internal/struct.S.html '//*[@class="stab unstable"]' // @!has internal/struct.S.html '//*[@class="stab internal"]' diff --git a/src/test/rustdoc/issue-32374.rs b/src/test/rustdoc/issue-32374.rs index 11caa34d4b1..604451eb7e8 100644 --- a/src/test/rustdoc/issue-32374.rs +++ b/src/test/rustdoc/issue-32374.rs @@ -1,17 +1,17 @@ #![feature(staged_api)] -#![doc(issue_tracker_base_url = "http://issue_url/")] +#![doc(issue_tracker_base_url = "https://issue_url/")] #![unstable(feature="test", issue = "32374")] -// @matches issue_32374/index.html '//*[@class="docblock-short"]/span[@class="stab deprecated"]' \ +// @matches issue_32374/index.html '//*[@class="item-right docblock-short"]/span[@class="stab deprecated"]' \ // 'Deprecated' -// @matches issue_32374/index.html '//*[@class="docblock-short"]/span[@class="stab unstable"]' \ +// @matches issue_32374/index.html '//*[@class="item-right docblock-short"]/span[@class="stab unstable"]' \ // 'Experimental' -// @matches issue_32374/index.html '//*[@class="docblock-short"]/text()' 'Docs' +// @matches issue_32374/index.html '//*[@class="item-right docblock-short"]/text()' 'Docs' // @has issue_32374/struct.T.html '//*[@class="stab deprecated"]' \ // '👎 Deprecated since 1.0.0: text' -// @has - 'test #32374' +// @has - 'test #32374' // @matches issue_32374/struct.T.html '//*[@class="stab unstable"]' \ // '🔬 This is a nightly-only experimental API. \(test\s#32374\)$' /// Docs diff --git a/src/test/rustdoc/issue-46377.rs b/src/test/rustdoc/issue-46377.rs index 236afb20be5..4489f038c59 100644 --- a/src/test/rustdoc/issue-46377.rs +++ b/src/test/rustdoc/issue-46377.rs @@ -1,3 +1,3 @@ -// @has 'issue_46377/index.html' '//*[@class="docblock-short"]' 'Check out this struct!' +// @has 'issue_46377/index.html' '//*[@class="item-right docblock-short"]' 'Check out this struct!' /// # Check out this struct! pub struct SomeStruct; diff --git a/src/test/rustdoc/issue-55364.rs b/src/test/rustdoc/issue-55364.rs index 62a51a23350..70aa10767b2 100644 --- a/src/test/rustdoc/issue-55364.rs +++ b/src/test/rustdoc/issue-55364.rs @@ -29,8 +29,8 @@ pub mod subone { // @has - '//section[@id="main"]/details/div[@class="docblock"]//a[@href="../fn.foo.html"]' 'foo' // @has - '//section[@id="main"]/details/div[@class="docblock"]//a[@href="../fn.bar.html"]' 'bar' // Though there should be such links later -// @has - '//section[@id="main"]/item-table//item-left[@class="module-item"]/a[@class="fn"][@href="fn.foo.html"]' 'foo' -// @has - '//section[@id="main"]/item-table//item-left[@class="module-item"]/a[@class="fn"][@href="fn.bar.html"]' 'bar' +// @has - '//section[@id="main"]/div[@class="item-table"]//div[@class="item-left module-item"]/a[@class="fn"][@href="fn.foo.html"]' 'foo' +// @has - '//section[@id="main"]/div[@class="item-table"]//div[@class="item-left module-item"]/a[@class="fn"][@href="fn.bar.html"]' 'bar' /// See either [foo] or [bar]. pub mod subtwo { @@ -68,8 +68,8 @@ pub mod subthree { // Next we go *deeper* - In order to ensure it's not just "this or parent" // we test `crate::` and a `super::super::...` chain // @has issue_55364/subfour/subfive/subsix/subseven/subeight/index.html -// @has - '//section[@id="main"]/item-table//item-right[@class="docblock-short"]//a[@href="../../../../../subone/fn.foo.html"]' 'other foo' -// @has - '//section[@id="main"]/item-table//item-right[@class="docblock-short"]//a[@href="../../../../../subtwo/fn.bar.html"]' 'other bar' +// @has - '//section[@id="main"]/div[@class="item-table"]//div[@class="item-right docblock-short"]//a[@href="../../../../../subone/fn.foo.html"]' 'other foo' +// @has - '//section[@id="main"]/div[@class="item-table"]//div[@class="item-right docblock-short"]//a[@href="../../../../../subtwo/fn.bar.html"]' 'other bar' pub mod subfour { pub mod subfive { pub mod subsix { diff --git a/src/test/rustdoc/reexport-check.rs b/src/test/rustdoc/reexport-check.rs index 583b49698c4..db1f90c6999 100644 --- a/src/test/rustdoc/reexport-check.rs +++ b/src/test/rustdoc/reexport-check.rs @@ -4,15 +4,15 @@ extern crate reexport_check; // @!has 'foo/index.html' '//code' 'pub use self::i32;' -// @has 'foo/index.html' '//item-left[@class="deprecated module-item"]' 'i32' +// @has 'foo/index.html' '//div[@class="item-left deprecated module-item"]' 'i32' // @has 'foo/i32/index.html' #[allow(deprecated, deprecated_in_future)] pub use std::i32; // @!has 'foo/index.html' '//code' 'pub use self::string::String;' -// @has 'foo/index.html' '//item-left[@class="module-item"]' 'String' +// @has 'foo/index.html' '//div[@class="item-left module-item"]' 'String' pub use std::string::String; -// @has 'foo/index.html' '//item-right[@class="docblock-short"]' 'Docs in original' +// @has 'foo/index.html' '//div[@class="item-right docblock-short"]' 'Docs in original' // this is a no-op, but shows what happens if there's an attribute that isn't a doc-comment #[doc(inline)] pub use reexport_check::S; diff --git a/src/test/rustdoc/short-docblock-codeblock.rs b/src/test/rustdoc/short-docblock-codeblock.rs index 13b7f0c19a7..c6b318b0677 100644 --- a/src/test/rustdoc/short-docblock-codeblock.rs +++ b/src/test/rustdoc/short-docblock-codeblock.rs @@ -1,8 +1,8 @@ #![crate_name = "foo"] -// @has foo/index.html '//item-right[@class="docblock-short"]' "" -// @!has foo/index.html '//item-right[@class="docblock-short"]' "Some text." -// @!has foo/index.html '//item-right[@class="docblock-short"]' "let x = 12;" +// @has foo/index.html '//*[@class="item-right docblock-short"]' "" +// @!has foo/index.html '//*[@class="item-right docblock-short"]' "Some text." +// @!has foo/index.html '//*[@class="item-right docblock-short"]' "let x = 12;" /// ``` /// let x = 12; diff --git a/src/test/rustdoc/short-docblock.rs b/src/test/rustdoc/short-docblock.rs new file mode 100644 index 00000000000..74fa783174d --- /dev/null +++ b/src/test/rustdoc/short-docblock.rs @@ -0,0 +1,25 @@ +#![crate_name = "foo"] + +// @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'fooo' +// @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h1' 'fooo' +// @has foo/fn.foo.html '//h1[@id="fooo"]/a[@href="#fooo"]' 'fooo' + +/// # fooo +/// +/// foo +pub fn foo() {} + +// @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'mooood' +// @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h2' 'mooood' +// @has foo/foo/index.html '//h2[@id="mooood"]/a[@href="#mooood"]' 'mooood' + +/// ## mooood +/// +/// foo mod +pub mod foo {} + +// @has foo/index.html '//*[@class="item-right docblock-short"]/p/a[@href=\ +// "https://nougat.world"]/code' 'nougat' + +/// [`nougat`](https://nougat.world) +pub struct Bar; diff --git a/src/test/rustdoc/short-dockblock.rs b/src/test/rustdoc/short-dockblock.rs deleted file mode 100644 index 5493bca54c5..00000000000 --- a/src/test/rustdoc/short-dockblock.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![crate_name = "foo"] - -// @has foo/index.html '//*[@class="docblock-short"]/p' 'fooo' -// @!has foo/index.html '//*[@class="docblock-short"]/p/h1' 'fooo' -// @has foo/fn.foo.html '//h1[@id="fooo"]/a[@href="#fooo"]' 'fooo' - -/// # fooo -/// -/// foo -pub fn foo() {} - -// @has foo/index.html '//*[@class="docblock-short"]/p' 'mooood' -// @!has foo/index.html '//*[@class="docblock-short"]/p/h2' 'mooood' -// @has foo/foo/index.html '//h2[@id="mooood"]/a[@href="#mooood"]' 'mooood' - -/// ## mooood -/// -/// foo mod -pub mod foo {} - -// @has foo/index.html '//*[@class="docblock-short"]/p/a[@href=\ -// "https://nougat.world"]/code' 'nougat' - -/// [`nougat`](https://nougat.world) -pub struct Bar;