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)
This commit is contained in:
commit
a173778d1d
@ -591,7 +591,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
|||||||
ty: item.type_(),
|
ty: item.type_(),
|
||||||
name: item.name.clone().unwrap(),
|
name: item.name.clone().unwrap(),
|
||||||
path: fqp[..fqp.len() - 1].join("::"),
|
path: fqp[..fqp.len() - 1].join("::"),
|
||||||
desc: Escape(&shorter(item.doc_value())).to_string(),
|
desc: plain_summary_line(item.doc_value()),
|
||||||
parent: Some(did),
|
parent: Some(did),
|
||||||
parent_idx: None,
|
parent_idx: None,
|
||||||
search_type: get_index_search_type(&item),
|
search_type: get_index_search_type(&item),
|
||||||
@ -629,7 +629,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let crate_doc = krate.module.as_ref().map(|module| {
|
let crate_doc = krate.module.as_ref().map(|module| {
|
||||||
Escape(&shorter(module.doc_value())).to_string()
|
plain_summary_line(module.doc_value())
|
||||||
}).unwrap_or(String::new());
|
}).unwrap_or(String::new());
|
||||||
|
|
||||||
let mut crate_data = BTreeMap::new();
|
let mut crate_data = BTreeMap::new();
|
||||||
@ -1064,7 +1064,7 @@ impl DocFolder for Cache {
|
|||||||
ty: item.type_(),
|
ty: item.type_(),
|
||||||
name: s.to_string(),
|
name: s.to_string(),
|
||||||
path: path.join("::").to_string(),
|
path: path.join("::").to_string(),
|
||||||
desc: Escape(&shorter(item.doc_value())).to_string(),
|
desc: plain_summary_line(item.doc_value()),
|
||||||
parent: parent,
|
parent: parent,
|
||||||
parent_idx: None,
|
parent_idx: None,
|
||||||
search_type: get_index_search_type(&item),
|
search_type: get_index_search_type(&item),
|
||||||
|
@ -609,7 +609,7 @@
|
|||||||
displayPath + '<span class="' + type + '">' +
|
displayPath + '<span class="' + type + '">' +
|
||||||
name + '</span></a></td><td>' +
|
name + '</span></a></td><td>' +
|
||||||
'<a href="' + href + '">' +
|
'<a href="' + href + '">' +
|
||||||
'<span class="desc">' + item.desc +
|
'<span class="desc">' + escape(item.desc) +
|
||||||
' </span></a></td></tr>';
|
' </span></a></td></tr>';
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -807,14 +807,6 @@
|
|||||||
search();
|
search();
|
||||||
}
|
}
|
||||||
|
|
||||||
function plainSummaryLine(markdown) {
|
|
||||||
markdown.replace(/\n/g, ' ')
|
|
||||||
.replace(/'/g, "\'")
|
|
||||||
.replace(/^#+? (.+?)/, "$1")
|
|
||||||
.replace(/\[(.*?)\]\(.*?\)/g, "$1")
|
|
||||||
.replace(/\[(.*?)\]\[.*?\]/g, "$1");
|
|
||||||
}
|
|
||||||
|
|
||||||
index = buildIndex(rawSearchIndex);
|
index = buildIndex(rawSearchIndex);
|
||||||
startSearch();
|
startSearch();
|
||||||
|
|
||||||
@ -836,13 +828,10 @@
|
|||||||
if (crates[i] === window.currentCrate) {
|
if (crates[i] === window.currentCrate) {
|
||||||
klass += ' current';
|
klass += ' current';
|
||||||
}
|
}
|
||||||
if (rawSearchIndex[crates[i]].items[0]) {
|
var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
|
||||||
var desc = rawSearchIndex[crates[i]].items[0][3];
|
'title': rawSearchIndex[crates[i]].doc,
|
||||||
var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
|
'class': klass}).text(crates[i]);
|
||||||
'title': plainSummaryLine(desc),
|
ul.append($('<li>').append(link));
|
||||||
'class': klass}).text(crates[i]);
|
|
||||||
ul.append($('<li>').append(link));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sidebar.append(div);
|
sidebar.append(div);
|
||||||
}
|
}
|
||||||
|
20
src/test/rustdoc/search-index-summaries.rs
Normal file
20
src/test/rustdoc/search-index-summaries.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// @has 'search-index.js' 'Foo short link.'
|
||||||
|
// @!has - 'www.example.com'
|
||||||
|
// @!has - 'More Foo.'
|
||||||
|
|
||||||
|
/// Foo short [link](https://www.example.com/).
|
||||||
|
///
|
||||||
|
/// More Foo.
|
||||||
|
pub struct Foo;
|
Loading…
Reference in New Issue
Block a user