From 6aad08f13ffba2a18428c4f5ad03977bc1503f5d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Feb 2022 14:43:44 +0100 Subject: [PATCH 1/2] Unify headings indent and remove useless anchor --- src/librustdoc/html/markdown.rs | 2 +- src/librustdoc/html/markdown/tests.rs | 20 ++++++++++---------- src/librustdoc/html/render/mod.rs | 2 +- src/librustdoc/html/static/css/rustdoc.css | 21 --------------------- 4 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index a40181352f6c0..1c0448828a279 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -565,7 +565,7 @@ impl<'a, 'b, 'ids, I: Iterator>> Iterator self.buf.push_back((Event::Html(format!("", level).into()), 0..0)); let start_tags = format!( - "\ + "\ ", id = id, level = level diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index ea6575d179d86..6b44e447b5111 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -161,23 +161,23 @@ fn test_header() { t( "# Foo bar", - "

Foo bar

", + "

Foo bar

", ); t( "## Foo-bar_baz qux", - "

\ + "

\ Foo-bar_baz qux

", ); t( "### **Foo** *bar* baz!?!& -_qux_-%", - "

\ + "

\ Foo \ bar baz!?!& -qux-%\

", ); t( "#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux", - "
\ + "
\ Foo? & *bar?!* \ baz ❤ #qux\
", @@ -204,32 +204,32 @@ fn test_header_ids_multiple_blocks() { t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Panics", - "

Panics

", + "

Panics

", ); t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Search", - "

Search

", + "

Search

", ); t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Panics", - "

Panics

", + "

Panics

", ); } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index f3e65df6b1497..19b5fef4e092e 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2567,7 +2567,7 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) { w, "
\ \ -
\ +
\ Examples found in repository\
", id = id diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 04112c9779b36..78e7c97d71d25 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1141,16 +1141,6 @@ a.test-arrow { a.test-arrow:hover{ text-decoration: none; } -.section-header:hover a:before { - position: absolute; - left: -25px; - padding-right: 10px; /* avoid gap that causes hover to disappear */ - content: '\2002\00a7\2002'; -} - -.section-header:hover a { - text-decoration: none; -} .code-attribute { font-weight: 300; @@ -1196,17 +1186,6 @@ h3.variant { margin-top: 3px; } -.top-doc .docblock > .section-header:first-child { - margin-left: 15px; -} -.top-doc .docblock > .section-header:first-child:hover > a:before { - left: -10px; -} - -.docblock > .section-header:first-child { - margin-top: 0; -} - :target > code, :target > .code-header { opacity: 1; } From e8d5ae41a118364bc9897d01fa67a3838712b7c2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Feb 2022 14:44:10 +0100 Subject: [PATCH 2/2] Update rustdoc tests for headings indent --- src/librustdoc/html/markdown/tests.rs | 41 +++++------------------- src/test/rustdoc-gui/anchors.goml | 42 ------------------------- src/test/rustdoc-gui/headers-color.goml | 9 ++++-- 3 files changed, 13 insertions(+), 79 deletions(-) diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 6b44e447b5111..5c0bf0ed942f4 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -159,10 +159,7 @@ fn test_header() { assert_eq!(output, expect, "original: {}", input); } - t( - "# Foo bar", - "

Foo bar

", - ); + t("# Foo bar", "

Foo bar

"); t( "## Foo-bar_baz qux", "

\ @@ -201,36 +198,12 @@ fn test_header_ids_multiple_blocks() { assert_eq!(output, expect, "original: {}", input); } - t( - &mut map, - "# Example", - "

Example

", - ); - t( - &mut map, - "# Panics", - "

Panics

", - ); - t( - &mut map, - "# Example", - "

Example

", - ); - t( - &mut map, - "# Search", - "

Search

", - ); - t( - &mut map, - "# Example", - "

Example

", - ); - t( - &mut map, - "# Panics", - "

Panics

", - ); + t(&mut map, "# Example", "

Example

"); + t(&mut map, "# Panics", "

Panics

"); + t(&mut map, "# Example", "

Example

"); + t(&mut map, "# Search", "

Search

"); + t(&mut map, "# Example", "

Example

"); + t(&mut map, "# Panics", "

Panics

"); } #[test] diff --git a/src/test/rustdoc-gui/anchors.goml b/src/test/rustdoc-gui/anchors.goml index 26e4503a5d086..ddfb23a4f86ba 100644 --- a/src/test/rustdoc-gui/anchors.goml +++ b/src/test/rustdoc-gui/anchors.goml @@ -31,46 +31,4 @@ assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"}) move-cursor-to: "#impl" assert-css: ("#impl a.anchor", {"color": "rgb(0, 0, 0)"}) -// Now we check the positions: only the first heading of the top doc comment should -// have a different position. -move-cursor-to: ".top-doc .docblock .section-header:first-child" -assert-css: ( - ".top-doc .docblock .section-header:first-child > a::before", - {"left": "-10px", "padding-right": "10px"}, -) -// We also check that the heading itself has a different indent. -assert-css: (".top-doc .docblock .section-header:first-child", {"margin-left": "15px"}) - -move-cursor-to: ".top-doc .docblock .section-header:not(:first-child)" -assert-css: ( - ".top-doc .docblock .section-header:not(:first-child) > a::before", - {"left": "-25px", "padding-right": "10px"}, -) -assert-css: (".top-doc .docblock .section-header:not(:first-child)", {"margin-left": "0px"}) - -// Now let's check some other docblock headings... -// First the impl block docs. -move-cursor-to: "#title-for-struct-impl-doc" -assert-css: ( - "#title-for-struct-impl-doc > a::before", - {"left": "-25px", "padding-right": "10px"}, -) -assert-css: ("#title-for-struct-impl-doc", {"margin-left": "0px"}) -// Now a method docs. -move-cursor-to: "#title-for-struct-impl-item-doc" -assert-css: ( - "#title-for-struct-impl-item-doc > a::before", - {"left": "-25px", "padding-right": "10px"}, -) assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"}) - -// Finally, we want to ensure that if the first element of the doc block isn't a heading, -// if there is a heading afterwards, it won't have the indent. -goto: file://|DOC_PATH|/test_docs/enum.WhoLetTheDogOut.html - -move-cursor-to: ".top-doc .docblock .section-header" -assert-css: ( - ".top-doc .docblock .section-header > a::before", - {"left": "-25px", "padding-right": "10px"}, -) -assert-css: (".top-doc .docblock .section-header", {"margin-left": "0px"}) diff --git a/src/test/rustdoc-gui/headers-color.goml b/src/test/rustdoc-gui/headers-color.goml index d58ca13a6291f..cf9caa2d5866a 100644 --- a/src/test/rustdoc-gui/headers-color.goml +++ b/src/test/rustdoc-gui/headers-color.goml @@ -40,7 +40,8 @@ goto: file://|DOC_PATH|/test_docs/index.html assert-css: (".small-section-header a", {"color": "rgb(197, 197, 197)"}, ALL) goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html -assert-css: (".section-header a", {"color": "rgb(57, 175, 215)"}, ALL) +// We select headings (h2, h3, h...). +assert-css: (".docblock > :not(p) > a", {"color": "rgb(57, 175, 215)"}, ALL) // Dark theme local-storage: { @@ -78,7 +79,8 @@ goto: file://|DOC_PATH|/test_docs/index.html assert-css: (".small-section-header a", {"color": "rgb(221, 221, 221)"}, ALL) goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html -assert-css: (".section-header a", {"color": "rgb(210, 153, 29)"}, ALL) +// We select headings (h2, h3, h...). +assert-css: (".docblock > :not(p) > a", {"color": "rgb(210, 153, 29)"}, ALL) // Light theme local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} @@ -111,4 +113,5 @@ goto: file://|DOC_PATH|/test_docs/index.html assert-css: (".small-section-header a", {"color": "rgb(0, 0, 0)"}, ALL) goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html -assert-css: (".section-header a", {"color": "rgb(56, 115, 173)"}, ALL) +// We select headings (h2, h3, h...). +assert-css: (".docblock > :not(p) > a", {"color": "rgb(56, 115, 173)"}, ALL)