From a32cb15f6700827c8c8298d3503c2cc84b7eb623 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 6 Jul 2024 19:07:22 -0700 Subject: [PATCH] rustdoc: use `` in sidebar This also improves sidebar layout, so instead of BTreeM ap you get this BTree Map --- src/librustdoc/html/layout.rs | 2 ++ src/librustdoc/html/render/mod.rs | 2 +- src/librustdoc/html/render/sidebar.rs | 16 ++++++++++++++++ src/librustdoc/html/templates/page.html | 2 +- src/librustdoc/html/templates/sidebar.html | 8 +++++--- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index d4b4db0f3fda6..430ef7c508758 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -71,6 +71,8 @@ struct PageLayout<'a> { display_krate_version_extra: &'a str, } +pub(crate) use crate::html::render::sidebar::filters; + pub(crate) fn render( layout: &Layout, page: &Page<'_>, diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 877a00e206d11..15580682486e2 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -30,7 +30,7 @@ mod tests; mod context; mod print_item; -mod sidebar; +pub(crate) mod sidebar; mod span_map; mod type_layout; mod write_shared; diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 3d28937eb99e1..afcc71d6ed44b 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -76,6 +76,22 @@ impl<'a> Link<'a> { } } +pub(crate) mod filters { + use crate::{html::escape::EscapeBodyTextWithWbr, html::render::display_fn}; + use askama::{Html, MarkupDisplay}; + use std::fmt::Display; + pub(crate) fn wrapped(v: T) -> askama::Result> + where + T: Display, + { + let string = v.to_string(); + Ok(MarkupDisplay::new_safe( + display_fn(move |f| EscapeBodyTextWithWbr(&string).fmt(f)), + Html, + )) + } +} + pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { let blocks: Vec> = match *it.kind { clean::StructItem(ref s) => sidebar_struct(cx, it, s), diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index cdf01fa7a97e8..65c4304e20207 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -98,7 +98,7 @@ {# #} {% endif %}

{# #} - {{display_krate}} {# #} + {{display_krate|wrapped|safe}} {# #} {% if !display_krate_version_number.is_empty() %} {{+ display_krate_version_number}} {% endif %} diff --git a/src/librustdoc/html/templates/sidebar.html b/src/librustdoc/html/templates/sidebar.html index 3251b4c14c95a..3c9ec990dfa06 100644 --- a/src/librustdoc/html/templates/sidebar.html +++ b/src/librustdoc/html/templates/sidebar.html @@ -1,6 +1,6 @@ {% if !title.is_empty() %}

{# #} - {{title_prefix}}{{title}} {# #} + {{title_prefix}}{{title|wrapped|safe}} {# #}

{% endif %}