From 4f15e1183c205e57b1826eee5674b2f65744e225 Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Mon, 12 Dec 2016 18:39:36 +0000 Subject: [PATCH] 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. --- src/librustdoc/html/render.rs | 6 +++--- src/librustdoc/html/static/main.js | 21 +++++---------------- src/test/rustdoc/search-index-summaries.rs | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 src/test/rustdoc/search-index-summaries.rs diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e721b66779f..73c9b15648b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -591,7 +591,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { ty: item.type_(), name: item.name.clone().unwrap(), 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_idx: None, 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| { - Escape(&shorter(module.doc_value())).to_string() + plain_summary_line(module.doc_value()) }).unwrap_or(String::new()); let mut crate_data = BTreeMap::new(); @@ -1064,7 +1064,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option { ty: item.type_(), name: s.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_idx: None, search_type: get_index_search_type(&item), diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 6ea25fa1241..c12e1e7d608 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -609,7 +609,7 @@ displayPath + '' + name + '' + '' + - '' + item.desc + + '' + escape(item.desc) + ' '; }); } else { @@ -807,14 +807,6 @@ search(); } - function plainSummaryLine(markdown) { - markdown.replace(/\n/g, ' ') - .replace(/'/g, "\'") - .replace(/^#+? (.+?)/, "$1") - .replace(/\[(.*?)\]\(.*?\)/g, "$1") - .replace(/\[(.*?)\]\[.*?\]/g, "$1"); - } - index = buildIndex(rawSearchIndex); startSearch(); @@ -836,13 +828,10 @@ if (crates[i] === window.currentCrate) { klass += ' current'; } - if (rawSearchIndex[crates[i]].items[0]) { - var desc = rawSearchIndex[crates[i]].items[0][3]; - var link = $('', {'href': '../' + crates[i] + '/index.html', - 'title': plainSummaryLine(desc), - 'class': klass}).text(crates[i]); - ul.append($('
  • ').append(link)); - } + var link = $('', {'href': '../' + crates[i] + '/index.html', + 'title': rawSearchIndex[crates[i]].doc, + 'class': klass}).text(crates[i]); + ul.append($('
  • ').append(link)); } sidebar.append(div); } diff --git a/src/test/rustdoc/search-index-summaries.rs b/src/test/rustdoc/search-index-summaries.rs new file mode 100644 index 00000000000..dd195dc33e4 --- /dev/null +++ b/src/test/rustdoc/search-index-summaries.rs @@ -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 or the MIT license +// , 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; -- 2.44.0