-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustdoc: do not use plain summary for trait impls #73819
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1506,6 +1506,7 @@ impl Context { | |
} | ||
} | ||
|
||
/// Construct a map of items shown in the sidebar to a plain-text summary of their docs. | ||
fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> { | ||
// BTreeMap instead of HashMap to get a sorted output | ||
let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new(); | ||
|
@@ -1522,7 +1523,7 @@ impl Context { | |
let short = short.to_string(); | ||
map.entry(short) | ||
.or_default() | ||
.push((myname, Some(plain_summary_line(item.doc_value())))); | ||
.push((myname, Some(plain_text_summary(item.doc_value())))); | ||
} | ||
|
||
if self.shared.sort_modules_alphabetically { | ||
|
@@ -1728,22 +1729,15 @@ fn full_path(cx: &Context, item: &clean::Item) -> String { | |
s | ||
} | ||
|
||
/// Renders the first paragraph of the given markdown as plain text, making it suitable for | ||
/// contexts like alt-text or the search index. | ||
/// | ||
/// If no markdown is supplied, the empty string is returned. | ||
/// | ||
/// See [`markdown::plain_text_summary`] for further details. | ||
#[inline] | ||
crate fn plain_summary_line(s: Option<&str>) -> String { | ||
let s = s.unwrap_or(""); | ||
// This essentially gets the first paragraph of text in one line. | ||
let mut line = s | ||
.lines() | ||
.skip_while(|line| line.chars().all(|c| c.is_whitespace())) | ||
.take_while(|line| line.chars().any(|c| !c.is_whitespace())) | ||
.fold(String::new(), |mut acc, line| { | ||
acc.push_str(line); | ||
acc.push(' '); | ||
acc | ||
}); | ||
// remove final whitespace | ||
line.pop(); | ||
markdown::plain_summary_line(&line[..]) | ||
crate fn plain_text_summary(s: Option<&str>) -> String { | ||
s.map(markdown::plain_text_summary).unwrap_or_default() | ||
} | ||
|
||
crate fn shorten(s: String) -> String { | ||
|
@@ -1800,25 +1794,35 @@ fn render_markdown( | |
) | ||
} | ||
|
||
/// Writes a documentation block containing only the first paragraph of the documentation. If the | ||
/// docs are longer, a "Read more" link is appended to the end. | ||
fn document_short( | ||
w: &mut Buffer, | ||
cx: &Context, | ||
item: &clean::Item, | ||
link: AssocItemLink<'_>, | ||
prefix: &str, | ||
is_hidden: bool, | ||
) { | ||
if let Some(s) = item.doc_value() { | ||
let markdown = if s.contains('\n') { | ||
format!( | ||
"{} [Read more]({})", | ||
&plain_summary_line(Some(s)), | ||
naive_assoc_href(item, link) | ||
) | ||
} else { | ||
plain_summary_line(Some(s)) | ||
}; | ||
render_markdown(w, cx, &markdown, item.links(), prefix, is_hidden); | ||
let mut summary_html = MarkdownSummaryLine(s, &item.links()).into_string(); | ||
|
||
if s.contains('\n') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it take into account when you only have an indented code block like: /// hello
? |
||
let link = format!(r#" <a href="{}">Read more</a>"#, naive_assoc_href(item, link)); | ||
|
||
if let Some(idx) = summary_html.rfind("</p>") { | ||
summary_html.insert_str(idx, &link); | ||
} else { | ||
summary_html.push_str(&link); | ||
} | ||
} | ||
|
||
write!( | ||
w, | ||
"<div class='docblock{}'>{}{}</div>", | ||
if is_hidden { " hidden" } else { "" }, | ||
prefix, | ||
summary_html, | ||
); | ||
} else if !prefix.is_empty() { | ||
write!( | ||
w, | ||
|
@@ -3689,7 +3693,7 @@ fn render_impl( | |
} else if show_def_docs { | ||
// In case the item isn't documented, | ||
// provide short documentation from the trait. | ||
document_short(w, cx, it, link, "", is_hidden); | ||
document_short(w, it, link, "", is_hidden); | ||
} | ||
} | ||
} else { | ||
|
@@ -3701,7 +3705,7 @@ fn render_impl( | |
} else { | ||
document_stability(w, cx, item, is_hidden); | ||
if show_def_docs { | ||
document_short(w, cx, item, link, "", is_hidden); | ||
document_short(w, item, link, "", is_hidden); | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![crate_type = "lib"] | ||
#![crate_name = "summaries"] | ||
|
||
//! This summary has a [link] and `code`. | ||
//! | ||
//! This is the second paragraph. | ||
//! | ||
//! [link]: https://example.com | ||
|
||
// @has search-index.js 'This summary has a link and `code`.' | ||
// @!has - 'second paragraph' | ||
|
||
/// This `code` should be in backticks. | ||
/// | ||
/// This text should not be rendered. | ||
pub struct Sidebar; | ||
|
||
// @has summaries/sidebar-items.js 'This `code` should be in backticks.' | ||
// @!has - 'text should not be rendered' | ||
|
||
/// ```text | ||
/// this block should not be rendered | ||
/// ``` | ||
pub struct Sidebar2; | ||
|
||
// @!has summaries/sidebar-items.js 'block should not be rendered' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.