Skip to content

Commit b09e5da

Browse files
committed
Split rustdoc summary lines in a smarter way
Previously it would fail on a trivial case like /// Summary line /// <trailing space> /// Regular content Compliant markdown preprocessor would render that as two separate paragraphs, but our summary line extractor would interpret both lines as the same paragraph and include both into the short summary.
1 parent 9eb69ab commit b09e5da

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/librustdoc/html/render.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::Result<String> {
407407
ty: shortty(item),
408408
name: item.name.clone().unwrap(),
409409
path: fqp[..fqp.len() - 1].connect("::"),
410-
desc: shorter(item.doc_value()).to_string(),
410+
desc: shorter(item.doc_value()),
411411
parent: Some(did),
412412
});
413413
},
@@ -876,7 +876,7 @@ impl DocFolder for Cache {
876876
ty: shortty(&item),
877877
name: s.to_string(),
878878
path: path.connect("::").to_string(),
879-
desc: shorter(item.doc_value()).to_string(),
879+
desc: shorter(item.doc_value()),
880880
parent: parent,
881881
});
882882
}
@@ -1467,13 +1467,14 @@ fn full_path(cx: &Context, item: &clean::Item) -> String {
14671467
return s
14681468
}
14691469

1470-
fn shorter<'a>(s: Option<&'a str>) -> &'a str {
1470+
fn shorter<'a>(s: Option<&'a str>) -> String {
14711471
match s {
1472-
Some(s) => match s.find("\n\n") {
1473-
Some(pos) => &s[..pos],
1474-
None => s,
1475-
},
1476-
None => ""
1472+
Some(s) => s.lines().take_while(|line|{
1473+
(*line).chars().any(|chr|{
1474+
!chr.is_whitespace()
1475+
})
1476+
}).collect::<Vec<_>>().connect("\n"),
1477+
None => "".to_string()
14771478
}
14781479
}
14791480

@@ -1603,7 +1604,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
16031604
</tr>
16041605
",
16051606
*myitem.name.as_ref().unwrap(),
1606-
Markdown(shorter(myitem.doc_value())),
1607+
Markdown(&shorter(myitem.doc_value())[..]),
16071608
class = shortty(myitem),
16081609
href = item_path(myitem),
16091610
title = full_path(cx, myitem),

0 commit comments

Comments
 (0)