rustdoc: use <wbr> in sidebar headers

This also improves sidebar layout, so instead of

    BTreeM
    ap

you get this

    BTree
    Map
This commit is contained in:
Michael Howell 2024-07-06 19:07:22 -07:00
parent 9186001f34
commit 1d339b07ca
5 changed files with 24 additions and 4 deletions

View File

@ -69,6 +69,8 @@ struct PageLayout<'a> {
display_krate_version_extra: &'a str,
}
pub(crate) use crate::html::render::sidebar::filters;
pub(crate) fn render<T: Print, S: Print>(
layout: &Layout,
page: &Page<'_>,

View File

@ -30,7 +30,7 @@
mod context;
mod print_item;
mod sidebar;
pub(crate) mod sidebar;
mod span_map;
mod type_layout;
mod write_shared;

View File

@ -77,6 +77,22 @@ pub fn empty() -> Link<'static> {
}
}
pub(crate) mod filters {
use std::fmt::Display;
use rinja::filters::Safe;
use crate::html::escape::EscapeBodyTextWithWbr;
use crate::html::render::display_fn;
pub(crate) fn wrapped<T>(v: T) -> rinja::Result<Safe<impl Display>>
where
T: Display,
{
let string = v.to_string();
Ok(Safe(display_fn(move |f| EscapeBodyTextWithWbr(&string).fmt(f))))
}
}
pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
let blocks: Vec<LinkBlock<'_>> = match *it.kind {
clean::StructItem(ref s) => sidebar_struct(cx, it, s),

View File

@ -98,7 +98,7 @@
</a> {# #}
{% endif %}
<h2> {# #}
<a href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">{{display_krate}}</a> {# #}
<a href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">{{display_krate|wrapped|safe}}</a> {# #}
{% if !display_krate_version_number.is_empty() %}
<span class="version">{{+ display_krate_version_number}}</span>
{% endif %}

View File

@ -1,6 +1,6 @@
{% if !title.is_empty() %}
<h2 class="location"> {# #}
<a href="#">{{title_prefix}}{{title}}</a> {# #}
<a href="#">{{title_prefix}}{{title|wrapped|safe}}</a> {# #}
</h2>
{% endif %}
<div class="sidebar-elems">
@ -15,7 +15,9 @@
{% for block in blocks %}
{% if block.should_render() %}
{% if !block.heading.name.is_empty() %}
<h3><a href="#{{block.heading.href|safe}}">{{block.heading.name}}</a></h3>
<h3><a href="#{{block.heading.href|safe}}"> {# #}
{{block.heading.name|wrapped|safe}} {# #}
</a></h3> {# #}
{% endif %}
{% if !block.links.is_empty() %}
<ul class="block{% if !block.class.is_empty() +%} {{+block.class}}{% endif %}">