diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-03-15 05:13:44 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-03-15 10:23:40 +0530 |
| commit | 01f10dead316aaff615fcff5955d1db0c7f22936 (patch) | |
| tree | 97c37a8547d990a9c8e5c8e43e41ee4179288d26 | |
| parent | 8c85a9d20f6d764f80e55132f821dcd996921327 (diff) | |
| parent | b09e5daa89b6dbfe93b9db7a66b670ca6d1b5f4a (diff) | |
Rollup merge of #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

| -rw-r--r-- | src/librustdoc/html/render.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 4c6341efb72..f97470dbaed 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -453,7 +453,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::Result<String> { ty: shortty(item), name: item.name.clone().unwrap(), path: fqp[..fqp.len() - 1].connect("::"), - desc: shorter(item.doc_value()).to_string(), + desc: shorter(item.doc_value()), parent: Some(did), search_type: None, }); @@ -935,7 +935,7 @@ impl DocFolder for Cache { ty: shortty(&item), name: s.to_string(), path: path.connect("::").to_string(), - desc: shorter(item.doc_value()).to_string(), + desc: shorter(item.doc_value()), parent: parent, search_type: get_index_search_type(&item, parent_basename), }); @@ -1527,13 +1527,14 @@ fn full_path(cx: &Context, item: &clean::Item) -> String { return s } -fn shorter<'a>(s: Option<&'a str>) -> &'a str { +fn shorter<'a>(s: Option<&'a str>) -> String { match s { - Some(s) => match s.find("\n\n") { - Some(pos) => &s[..pos], - None => s, - }, - None => "" + Some(s) => s.lines().take_while(|line|{ + (*line).chars().any(|chr|{ + !chr.is_whitespace() + }) + }).collect::<Vec<_>>().connect("\n"), + None => "".to_string() } } @@ -1663,7 +1664,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, </tr> ", *myitem.name.as_ref().unwrap(), - Markdown(shorter(myitem.doc_value())), + Markdown(&shorter(myitem.doc_value())[..]), class = shortty(myitem), href = item_path(myitem), title = full_path(cx, myitem), |
