Skip to content

rustdoc: fix summary lines #31902

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

Merged
merged 2 commits into from
Feb 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
let text = lines.collect::<Vec<&str>>().join("\n");
if rendered { return }
PLAYGROUND_KRATE.with(|krate| {
let mut s = String::new();
// insert newline to clearly separate it from the
// previous block so we can shorten the html output
let mut s = String::from("\n");
krate.borrow().as_ref().map(|krate| {
let test = origtext.lines().map(|l| {
stripped_filtered_line(l).unwrap_or(l)
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,8 @@ fn shorter<'a>(s: Option<&'a str>) -> String {

#[inline]
fn plain_summary_line(s: Option<&str>) -> String {
let md = markdown::plain_summary_line(s.unwrap_or(""));
shorter(Some(&md)).replace("\n", " ")
let line = shorter(s).replace("\n", " ");
markdown::plain_summary_line(&line[..])
}

fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {
Expand Down
70 changes: 70 additions & 0 deletions src/test/rustdoc/issue-31899.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.


// @has issue_31899/index.html
// @has - 'Make this line a bit longer.'
// @!has - 'rust rust-example-rendered'
// @!has - 'use ndarray::arr2'
// @!has - 'prohibited'

/// A tuple or fixed size array that can be used to index an array.
/// Make this line a bit longer.
///
/// ```
/// use ndarray::arr2;
///
/// let mut a = arr2(&[[0, 1], [0, 0]]);
/// a[[1, 1]] = 1;
/// assert_eq!(a[[0, 1]], 1);
/// assert_eq!(a[[1, 1]], 1);
/// ```
///
/// **Note** the blanket implementation that's not visible in rustdoc:
/// `impl<D> NdIndex for D where D: Dimension { ... }`
pub fn bar() {}

/// Some line
///
/// # prohibited
pub fn foo() {}

/// Some line
///
/// 1. prohibited
/// 2. bar
pub fn baz() {}

/// Some line
///
/// - prohibited
/// - bar
pub fn qux() {}

/// Some line
///
/// * prohibited
/// * bar
pub fn quz() {}

/// Some line
///
/// > prohibited
/// > bar
pub fn qur() {}

/// Some line
///
/// prohibited
/// =====
///
/// Second
/// ------
pub fn qut() {}