Skip to content

Commit a173778

Browse files
committed
Auto merge of #38330 - ollie27:rustdoc_short_summaries, r=steveklabnik
rustdoc: Fix short summaries in search results They should be run through a Markdown renderer in rustdoc to remove links. This also fixes the mouse over text for the Crates list on the sidebar. [before](https://doc.rust-lang.org/nightly/std/index.html?search=ord) [after](https://ollie27.github.io/rust_doc_test/std/index.html?search=ord)
2 parents 17d873c + 4f15e11 commit a173778

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/librustdoc/html/render.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
591591
ty: item.type_(),
592592
name: item.name.clone().unwrap(),
593593
path: fqp[..fqp.len() - 1].join("::"),
594-
desc: Escape(&shorter(item.doc_value())).to_string(),
594+
desc: plain_summary_line(item.doc_value()),
595595
parent: Some(did),
596596
parent_idx: None,
597597
search_type: get_index_search_type(&item),
@@ -629,7 +629,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
629629
}
630630

631631
let crate_doc = krate.module.as_ref().map(|module| {
632-
Escape(&shorter(module.doc_value())).to_string()
632+
plain_summary_line(module.doc_value())
633633
}).unwrap_or(String::new());
634634

635635
let mut crate_data = BTreeMap::new();
@@ -1064,7 +1064,7 @@ impl DocFolder for Cache {
10641064
ty: item.type_(),
10651065
name: s.to_string(),
10661066
path: path.join("::").to_string(),
1067-
desc: Escape(&shorter(item.doc_value())).to_string(),
1067+
desc: plain_summary_line(item.doc_value()),
10681068
parent: parent,
10691069
parent_idx: None,
10701070
search_type: get_index_search_type(&item),

src/librustdoc/html/static/main.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@
609609
displayPath + '<span class="' + type + '">' +
610610
name + '</span></a></td><td>' +
611611
'<a href="' + href + '">' +
612-
'<span class="desc">' + item.desc +
612+
'<span class="desc">' + escape(item.desc) +
613613
'&nbsp;</span></a></td></tr>';
614614
});
615615
} else {
@@ -807,14 +807,6 @@
807807
search();
808808
}
809809

810-
function plainSummaryLine(markdown) {
811-
markdown.replace(/\n/g, ' ')
812-
.replace(/'/g, "\'")
813-
.replace(/^#+? (.+?)/, "$1")
814-
.replace(/\[(.*?)\]\(.*?\)/g, "$1")
815-
.replace(/\[(.*?)\]\[.*?\]/g, "$1");
816-
}
817-
818810
index = buildIndex(rawSearchIndex);
819811
startSearch();
820812

@@ -836,13 +828,10 @@
836828
if (crates[i] === window.currentCrate) {
837829
klass += ' current';
838830
}
839-
if (rawSearchIndex[crates[i]].items[0]) {
840-
var desc = rawSearchIndex[crates[i]].items[0][3];
841-
var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
842-
'title': plainSummaryLine(desc),
843-
'class': klass}).text(crates[i]);
844-
ul.append($('<li>').append(link));
845-
}
831+
var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
832+
'title': rawSearchIndex[crates[i]].doc,
833+
'class': klass}).text(crates[i]);
834+
ul.append($('<li>').append(link));
846835
}
847836
sidebar.append(div);
848837
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
// @has 'search-index.js' 'Foo short link.'
14+
// @!has - 'www.example.com'
15+
// @!has - 'More Foo.'
16+
17+
/// Foo short [link](https://www.example.com/).
18+
///
19+
/// More Foo.
20+
pub struct Foo;

0 commit comments

Comments
 (0)