Skip to content

Commit 66853af

Browse files
committed
Auto merge of rust-lang#23351 - nagisa:rustdoc-lines-2, r=alexcrichton
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 interprets both lines as the same paragraph and includes both into the short summary resulting in ![screenshot from 2015-03-13 22 47 08](https://cloud.githubusercontent.com/assets/679122/6648596/7ef792b2-c9e4-11e4-9c19-704c288ec4de.png)
2 parents 8c85a9d + b09e5da commit 66853af

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
@@ -453,7 +453,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::Result<String> {
453453
ty: shortty(item),
454454
name: item.name.clone().unwrap(),
455455
path: fqp[..fqp.len() - 1].connect("::"),
456-
desc: shorter(item.doc_value()).to_string(),
456+
desc: shorter(item.doc_value()),
457457
parent: Some(did),
458458
search_type: None,
459459
});
@@ -935,7 +935,7 @@ impl DocFolder for Cache {
935935
ty: shortty(&item),
936936
name: s.to_string(),
937937
path: path.connect("::").to_string(),
938-
desc: shorter(item.doc_value()).to_string(),
938+
desc: shorter(item.doc_value()),
939939
parent: parent,
940940
search_type: get_index_search_type(&item, parent_basename),
941941
});
@@ -1527,13 +1527,14 @@ fn full_path(cx: &Context, item: &clean::Item) -> String {
15271527
return s
15281528
}
15291529

1530-
fn shorter<'a>(s: Option<&'a str>) -> &'a str {
1530+
fn shorter<'a>(s: Option<&'a str>) -> String {
15311531
match s {
1532-
Some(s) => match s.find("\n\n") {
1533-
Some(pos) => &s[..pos],
1534-
None => s,
1535-
},
1536-
None => ""
1532+
Some(s) => s.lines().take_while(|line|{
1533+
(*line).chars().any(|chr|{
1534+
!chr.is_whitespace()
1535+
})
1536+
}).collect::<Vec<_>>().connect("\n"),
1537+
None => "".to_string()
15371538
}
15381539
}
15391540

@@ -1663,7 +1664,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
16631664
</tr>
16641665
",
16651666
*myitem.name.as_ref().unwrap(),
1666-
Markdown(shorter(myitem.doc_value())),
1667+
Markdown(&shorter(myitem.doc_value())[..]),
16671668
class = shortty(myitem),
16681669
href = item_path(myitem),
16691670
title = full_path(cx, myitem),

0 commit comments

Comments
 (0)