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: clean up DOM by removing .dockblock-short p #101778

Merged
merged 1 commit into from
Sep 15, 2022
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
6 changes: 5 additions & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,11 @@ impl MarkdownSummaryLine<'_> {

let mut s = String::new();

html::push_html(&mut s, LinkReplacer::new(SummaryLine::new(p), links));
let without_paragraphs = LinkReplacer::new(SummaryLine::new(p), links).filter(|event| {
!matches!(event, Event::Start(Tag::Paragraph) | Event::End(Tag::Paragraph))
});

html::push_html(&mut s, without_paragraphs);

s
}
Expand Down
6 changes: 1 addition & 5 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -609,16 +609,12 @@ h2.location a {
.docblock-short {
overflow-wrap: break-word;
overflow-wrap: anywhere;
}
.docblock-short p {
display: inline;
overflow: hidden;
text-overflow: ellipsis;
margin: 0;
}
/* Wrap non-pre code blocks (`text`) but not (```text```). */
.docblock > :not(pre) > code,
.docblock-short > :not(pre) > code {
.docblock-short > code {
white-space: pre-wrap;
}

Expand Down
18 changes: 3 additions & 15 deletions src/test/rustdoc-gui/label-next-to-symbol.goml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@ compare-elements-position: (
)

// Ensure no wrap
compare-elements-position-near: (
"//*[@class='item-left module-item']//a[text()='replaced_function']",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']",
{"y": 2},
)
// compare parent elements
compare-elements-position: (
"//*[@class='item-left module-item']//a[text()='replaced_function']/..",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']/..",
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
("y"),
)

Expand All @@ -60,19 +54,13 @@ compare-elements-position: (
)

// Ensure wrap
compare-elements-position-near-false: (
"//*[@class='item-left module-item']//a[text()='replaced_function']",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']",
{"y": 12},
)
// compare parent elements
compare-elements-position-false: (
"//*[@class='item-left module-item']//a[text()='replaced_function']/..",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']/..",
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
("y"),
)
compare-elements-position-false: (
".item-left .stab.deprecated",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']",
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
("y"),
)
10 changes: 5 additions & 5 deletions src/test/rustdoc/short-docblock.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#![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/index.html '//*[@class="item-right docblock-short"]' 'fooo'
// @!has foo/index.html '//*[@class="item-right docblock-short"]/h1' 'fooo'
// @has foo/fn.foo.html '//h2[@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/index.html '//*[@class="item-right docblock-short"]' 'mooood'
// @!has foo/index.html '//*[@class="item-right docblock-short"]/h2' 'mooood'
// @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' 'mooood'

/// ## mooood
///
/// foo mod
pub mod foo {}

// @has foo/index.html '//*[@class="item-right docblock-short"]/p/a[@href=\
// @has foo/index.html '//*[@class="item-right docblock-short"]/a[@href=\
// "https://nougat.world"]/code' 'nougat'

/// [`nougat`](https://nougat.world)
Expand Down
24 changes: 12 additions & 12 deletions src/test/rustdoc/trait-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ pub trait Trait {
pub struct Struct;

impl Trait for Struct {
// @has trait_impl/struct.Struct.html '//*[@id="method.a"]/../../div[@class="docblock"]/p' 'Some long docs'
// @!has - '//*[@id="method.a"]/../../div[@class="docblock"]/p' 'link will be added'
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/p/a' 'Read more'
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/p/a/@href' 'trait.Trait.html#tymethod.a'
// @has trait_impl/struct.Struct.html '//*[@id="method.a"]/../../div[@class="docblock"]' 'Some long docs'
// @!has - '//*[@id="method.a"]/../../div[@class="docblock"]' 'link will be added'
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/a' 'Read more'
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.a'
fn a() {}

// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p' 'These docs contain'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a' 'reference link'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a/@href' 'https://example.com'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a' 'Read more'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a/@href' 'trait.Trait.html#tymethod.b'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]' 'These docs contain'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'reference link'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'https://example.com'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'Read more'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.b'
fn b() {}

// @!has - '//*[@id="method.c"]/../../div[@class="docblock"]/p' 'code block'
// @!has - '//*[@id="method.c"]/../../div[@class="docblock"]' 'code block'
// @has - '//*[@id="method.c"]/../../div[@class="docblock"]/a' 'Read more'
// @has - '//*[@id="method.c"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.c'
fn c() {}

// @has - '//*[@id="method.d"]/../../div[@class="docblock"]/p' 'Escaped formatting a*b*c* works'
// @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/p/em' ''
// @has - '//*[@id="method.d"]/../../div[@class="docblock"]' 'Escaped formatting a*b*c* works'
// @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/em' ''
fn d() {}

// @has - '//*[@id="impl-Trait-for-Struct"]/h3//a/@href' 'trait.Trait.html'
Expand Down