Rollup merge of #77686 - camelid:rustdoc-render-search-results, r=GuillaumeGomez

Render Markdown in search results

Fixes #32040.

Previously Markdown documentation was not rendered to HTML for search results,
which led to the output not being very readable, particularly for inline code.
This PR fixes that by rendering Markdown to HTML with the help of pulldown-cmark
(the library rustdoc uses to parse Markdown for the main text of documentation).
However, the text for the title attribute (the text shown when you hover over an
element) still uses the plain-text rendering since it is displayed in browsers
as plain-text.

Only these styles will be rendered; everything else is stripped away:

* *italics*
* **bold**
* `inline code`
This commit is contained in:
Dylan DPC 2020-12-04 03:30:17 +01:00 committed by GitHub
commit 6f2fbc1613
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 203 additions and 51 deletions

View file

@ -1,2 +1,2 @@
/// Foo
/// Docs for Foo
pub struct Foo;

View file

@ -0,0 +1,21 @@
// ignore-tidy-linelength
const QUERY = ['summaries', 'summaries::Sidebar', 'summaries::Sidebar2'];
const EXPECTED = [
{
'others': [
{ 'path': '', 'name': 'summaries', 'desc': 'This <em>summary</em> has a link and <code>code</code>.' },
],
},
{
'others': [
{ 'path': 'summaries', 'name': 'Sidebar', 'desc': 'This <code>code</code> will be rendered in a code tag.' },
],
},
{
'others': [
{ 'path': 'summaries', 'name': 'Sidebar2', 'desc': '' },
],
},
];

View file

@ -0,0 +1,18 @@
#![crate_type = "lib"]
#![crate_name = "summaries"]
//! This *summary* has a [link] and `code`.
//!
//! This is the second paragraph.
//!
//! [link]: https://example.com
/// This `code` will be rendered in a code tag.
///
/// This text should not be rendered.
pub struct Sidebar;
/// ```text
/// this block should not be rendered
/// ```
pub struct Sidebar2;

View file

@ -1,21 +1,22 @@
#![crate_type = "lib"]
#![crate_name = "summaries"]
//! This summary has a [link] and `code`.
//! This *summary* has a [link] and `code`.
//!
//! This is the second paragraph.
//!
//! [link]: https://example.com
// @has search-index.js 'This summary has a link and `code`.'
// @has search-index.js 'This <em>summary</em> has a link and <code>code</code>.'
// @!has - 'second paragraph'
/// This `code` should be in backticks.
/// This `code` will be rendered in a code tag.
///
/// This text should not be rendered.
pub struct Sidebar;
// @has summaries/sidebar-items.js 'This `code` should be in backticks.'
// @has search-index.js 'This <code>code</code> will be rendered in a code tag.'
// @has summaries/sidebar-items.js 'This `code` will be rendered in a code tag.'
// @!has - 'text should not be rendered'
/// ```text