Skip to content

Commit b7f202a

Browse files
committed
rustdoc: use <wbr> in sidebar
This also improves sidebar layout, so instead of BTreeM ap you get this BTree Map
1 parent 0411d58 commit b7f202a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/librustdoc/html/render/sidebar.rs

+16
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ impl<'a> Link<'a> {
7676
}
7777
}
7878

79+
pub(crate) mod filters {
80+
use crate::{html::escape::EscapeBodyTextWithWbr, html::render::display_fn};
81+
use askama::{Html, MarkupDisplay};
82+
use std::fmt::Display;
83+
pub(crate) fn wrapped<T>(v: T) -> askama::Result<MarkupDisplay<Html, impl Display>>
84+
where
85+
T: Display,
86+
{
87+
let string = v.to_string();
88+
Ok(MarkupDisplay::new_safe(
89+
display_fn(move |f| EscapeBodyTextWithWbr(&string).fmt(f)),
90+
Html,
91+
))
92+
}
93+
}
94+
7995
pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
8096
let blocks: Vec<LinkBlock<'_>> = match *it.kind {
8197
clean::StructItem(ref s) => sidebar_struct(cx, it, s),

src/librustdoc/html/templates/sidebar.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ <h2 class="location"> {# #}
1515
{% for block in blocks %}
1616
{% if block.should_render() %}
1717
{% if !block.heading.name.is_empty() %}
18-
<h3><a href="#{{block.heading.href|safe}}">{{block.heading.name}}</a></h3>
18+
<h3><a href="#{{block.heading.href|safe}}"> {# #}
19+
{{block.heading.name|wrapped|safe}} {# #}
20+
</a></h3> {# #}
1921
{% endif %}
2022
{% if !block.links.is_empty() %}
2123
<ul class="block{% if !block.class.is_empty() +%} {{+block.class}}{% endif %}">
2224
{% for link in block.links %}
23-
<li><a href="#{{link.href|safe}}">{{link.name}}</a></li>
25+
<li><a href="#{{link.href|safe}}">{{link.name|wrapped|safe}}</a></li>
2426
{% endfor %}
2527
</ul>
2628
{% endif %}

0 commit comments

Comments
 (0)