From 5c98ae34a6764deb60f9311cdeca6c7df328cbc8 Mon Sep 17 00:00:00 2001 From: mitaa Date: Fri, 12 Feb 2016 13:45:07 +0100 Subject: [PATCH] Shorten docstrings after Markdown rendering --- src/librustdoc/html/render.rs | 7 ++++--- src/test/rustdoc/issue-30366.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/test/rustdoc/issue-30366.rs diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 12a17afcc7c5..a8bd46dab838 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1653,8 +1653,8 @@ fn shorter<'a>(s: Option<&'a str>) -> String { #[inline] fn plain_summary_line(s: Option<&str>) -> String { - let line = shorter(s).replace("\n", " "); - markdown::plain_summary_line(&line[..]) + let md = markdown::plain_summary_line(s.unwrap_or("")); + shorter(Some(&md)).replace("\n", " ") } fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result { @@ -1781,6 +1781,7 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering } else { String::new() }; + let doc_value = myitem.doc_value().unwrap_or(""); try!(write!(w, " Ordering ", name = *myitem.name.as_ref().unwrap(), stab_docs = stab_docs, - docs = Markdown(&shorter(myitem.doc_value())), + docs = shorter(Some(&Markdown(doc_value).to_string())), class = shortty(myitem), stab = myitem.stability_class(), href = item_path(myitem), diff --git a/src/test/rustdoc/issue-30366.rs b/src/test/rustdoc/issue-30366.rs new file mode 100644 index 000000000000..e622257b8f00 --- /dev/null +++ b/src/test/rustdoc/issue-30366.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// @has issue_30366/index.html '//a/@href' 'http://www.rust-lang.org/' + +/// Describe it. [Link somewhere][1]. +/// +/// [1]: http://www.rust-lang.org/ +pub fn here_is_a_fn() { }