Skip to content

Commit 9186001

Browse files
committed
rustdoc: avoid redundant HTML when there's already line breaks
1 parent 0d0e18e commit 9186001

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustdoc/html/escape.rs

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
9797
let _ = it.next(); // don't insert wbr before first char
9898
while let Some((i, s)) = it.next() {
9999
let pk = it.peek();
100+
if s.chars().all(|c| c.is_whitespace()) {
101+
// don't need "First <wbr>Second"; the space is enough
102+
EscapeBodyText(&text[last..i]).fmt(fmt)?;
103+
last = i;
104+
continue;
105+
}
100106
let is_uppercase = || s.chars().any(|c| c.is_uppercase());
101107
let next_is_uppercase =
102108
|| pk.map_or(true, |(_, t)| t.chars().any(|c| c.is_uppercase()));

src/librustdoc/html/escape/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ fn escape_body_text_with_wbr() {
99
// real(istic) examples
1010
assert_eq!(&E("FirstSecond").to_string(), "First<wbr>Second");
1111
assert_eq!(&E("First_Second").to_string(), "First<wbr>_Second");
12+
assert_eq!(&E("First Second").to_string(), "First Second");
13+
assert_eq!(&E("First HSecond").to_string(), "First HSecond");
14+
assert_eq!(&E("First HTTPSecond").to_string(), "First HTTP<wbr>Second");
15+
assert_eq!(&E("First SecondThird").to_string(), "First Second<wbr>Third");
1216
assert_eq!(&E("First<T>_Second").to_string(), "First&lt;<wbr>T&gt;<wbr>_Second");
1317
assert_eq!(&E("first_second").to_string(), "first<wbr>_second");
1418
assert_eq!(&E("MY_CONSTANT").to_string(), "MY<wbr>_CONSTANT");

0 commit comments

Comments
 (0)