Skip to content

Commit 0bb0f30

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

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

src/librustdoc/html/layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ struct PageLayout<'a> {
6969
display_krate_version_extra: &'a str,
7070
}
7171

72+
pub(crate) use crate::html::render::sidebar::filters;
73+
7274
pub(crate) fn render<T: Print, S: Print>(
7375
layout: &Layout,
7476
page: &Page<'_>,

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod tests;
3030

3131
mod context;
3232
mod print_item;
33-
mod sidebar;
33+
pub(crate) mod sidebar;
3434
mod span_map;
3535
mod type_layout;
3636
mod write_shared;

src/librustdoc/html/render/sidebar.rs

+19
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ impl<'a> Link<'a> {
7777
}
7878
}
7979

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

src/librustdoc/html/templates/page.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
</a> {# #}
9999
{% endif %}
100100
<h2> {# #}
101-
<a href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">{{display_krate}}</a> {# #}
101+
<a href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">{{display_krate|wrapped|safe}}</a> {# #}
102102
{% if !display_krate_version_number.is_empty() %}
103103
<span class="version">{{+ display_krate_version_number}}</span>
104104
{% endif %}

src/librustdoc/html/templates/sidebar.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% if !title.is_empty() %}
22
<h2 class="location"> {# #}
3-
<a href="#">{{title_prefix}}{{title}}</a> {# #}
3+
<a href="#">{{title_prefix}}{{title|wrapped|safe}}</a> {# #}
44
</h2>
55
{% endif %}
66
<div class="sidebar-elems">
@@ -15,7 +15,9 @@ <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 %}">

0 commit comments

Comments
 (0)