mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
rustdoc: avoid redundant HTML when there's already line breaks
This commit is contained in:
parent
0d0e18e7f6
commit
9186001f34
@ -97,6 +97,12 @@ impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
|
||||
let _ = it.next(); // don't insert wbr before first char
|
||||
while let Some((i, s)) = it.next() {
|
||||
let pk = it.peek();
|
||||
if s.chars().all(|c| c.is_whitespace()) {
|
||||
// don't need "First <wbr>Second"; the space is enough
|
||||
EscapeBodyText(&text[last..i]).fmt(fmt)?;
|
||||
last = i;
|
||||
continue;
|
||||
}
|
||||
let is_uppercase = || s.chars().any(|c| c.is_uppercase());
|
||||
let next_is_uppercase =
|
||||
|| pk.map_or(true, |(_, t)| t.chars().any(|c| c.is_uppercase()));
|
||||
|
@ -9,6 +9,10 @@ fn escape_body_text_with_wbr() {
|
||||
// real(istic) examples
|
||||
assert_eq!(&E("FirstSecond").to_string(), "First<wbr>Second");
|
||||
assert_eq!(&E("First_Second").to_string(), "First<wbr>_Second");
|
||||
assert_eq!(&E("First Second").to_string(), "First Second");
|
||||
assert_eq!(&E("First HSecond").to_string(), "First HSecond");
|
||||
assert_eq!(&E("First HTTPSecond").to_string(), "First HTTP<wbr>Second");
|
||||
assert_eq!(&E("First SecondThird").to_string(), "First Second<wbr>Third");
|
||||
assert_eq!(&E("First<T>_Second").to_string(), "First<<wbr>T><wbr>_Second");
|
||||
assert_eq!(&E("first_second").to_string(), "first<wbr>_second");
|
||||
assert_eq!(&E("MY_CONSTANT").to_string(), "MY<wbr>_CONSTANT");
|
||||
|
Loading…
Reference in New Issue
Block a user