-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustdoc: Strip broken links in summaries #79781
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1035,7 +1035,14 @@ fn markdown_summary_with_limit(md: &str, length_limit: usize) -> (String, bool) | |||
*text_length += text.len(); | ||||
} | ||||
|
||||
'outer: for event in Parser::new_ext(md, summary_opts()) { | ||||
// NOTE: Make sure to update the same variable in `plain_text_summary` | ||||
// if/when you update this one. They have to be duplicated because of a typesystem thing. | ||||
let mut broken_link_callback = | ||||
|broken_link: BrokenLink<'_>| Some(("#".into(), broken_link.reference.to_owned().into())); | ||||
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. This treats every broken link as valid, right? Can we instead use the same logic as for intra-doc links and only replace it if it was resolved? 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. Well we could, but we’d have to thread the intra-doc link information through somehow. If you would like me to do that, could you give me some instructions? 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. This info is available from See rust/src/librustdoc/html/markdown.rs Line 365 in 5019791
[] style links.
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. Hmm, will I then I have to duplicate 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. I don't see why? You're stripping the links in both cases, right? 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. It's been a while since we last discussed this. It looks like the last thing we talked about is letting their be a little duplication and moving the summary functions to be on 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. It's coming back to me now: The reason I temporarily abandoned this is because I was having trouble with the lifetimes of the callback for the summary functions not on 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. So I tried this type signature: fn markdown_summary_with_limit(
md: &str,
length_limit: usize,
broken_link_callback: Option<F>,
) -> (String, bool)
where
F: for<'a> FnMut(BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)>,
{ /* ... */ } but that gives a bunch of errors like:
What are the correct lifetimes? I feel like this needs higher-ranked lifetimes (which I added) but as you can see it doesn't work. I need to communicate to the compiler that the return type lifetimes are totally unrelated from the input lifetimes. 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. @jyn514 friendly ping :) If you need to focus on other stuff, don't worry about looking at this now, but you seemed eager to get this working. 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. Try |
||||
|
||||
'outer: for event in | ||||
Parser::new_with_broken_link_callback(md, summary_opts(), Some(&mut broken_link_callback)) | ||||
{ | ||||
match &event { | ||||
Event::Text(text) => { | ||||
for word in text.split_inclusive(char::is_whitespace) { | ||||
|
@@ -1113,7 +1120,14 @@ crate fn plain_text_summary(md: &str) -> String { | |||
|
||||
let mut s = String::with_capacity(md.len() * 3 / 2); | ||||
|
||||
for event in Parser::new_ext(md, summary_opts()) { | ||||
// NOTE: Make sure to update the same variable in `markdown_summary_with_limit` | ||||
// if/when you update this one. They have to be duplicated because of a typesystem thing. | ||||
let mut broken_link_callback = | ||||
|broken_link: BrokenLink<'_>| Some(("#".into(), broken_link.reference.to_owned().into())); | ||||
|
||||
for event in | ||||
Parser::new_with_broken_link_callback(md, summary_opts(), Some(&mut broken_link_callback)) | ||||
{ | ||||
match &event { | ||||
Event::Text(text) => s.push_str(text), | ||||
Event::Code(code) => { | ||||
|
Uh oh!
There was an error while loading. Please reload this page.