Skip to content

Commit 25d4152

Browse files
committed
rustdoc: move the wbr after the underscore, instead of before
1 parent 17bff74 commit 25d4152

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/librustdoc/html/escape.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
108108
|| pk.map_or(true, |(_, t)| t.chars().any(|c| c.is_uppercase()));
109109
let next_is_underscore = || pk.map_or(true, |(_, t)| t.contains('_'));
110110
let next_is_colon = || pk.map_or(true, |(_, t)| t.contains(':'));
111-
if (i - last > 3 && is_uppercase() && !next_is_uppercase())
112-
|| (s.contains('_') && !next_is_underscore())
113-
{
111+
if i - last > 3 && is_uppercase() && !next_is_uppercase() {
114112
EscapeBodyText(&text[last..i]).fmt(fmt)?;
115113
fmt.write_str("<wbr>")?;
116114
last = i;
117-
} else if s.contains(':') && !next_is_colon() {
115+
} else if (s.contains(':') && !next_is_colon())
116+
|| (s.contains('_') && !next_is_underscore())
117+
{
118118
EscapeBodyText(&text[last..i + 1]).fmt(fmt)?;
119119
fmt.write_str("<wbr>")?;
120120
last = i + 1;

src/librustdoc/html/escape/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ fn escape_body_text_with_wbr() {
1414
assert_eq!(&E(" ").to_string(), " ");
1515
// real(istic) examples
1616
assert_eq!(&E("FirstSecond").to_string(), "First<wbr>Second");
17-
assert_eq!(&E("First_Second").to_string(), "First<wbr>_Second");
17+
assert_eq!(&E("First_Second").to_string(), "First_<wbr>Second");
1818
assert_eq!(&E("First Second").to_string(), "First Second");
1919
assert_eq!(&E("First HSecond").to_string(), "First HSecond");
2020
assert_eq!(&E("First HTTPSecond").to_string(), "First HTTP<wbr>Second");
2121
assert_eq!(&E("First SecondThird").to_string(), "First Second<wbr>Third");
22-
assert_eq!(&E("First<T>_Second").to_string(), "First&lt;<wbr>T&gt;<wbr>_Second");
23-
assert_eq!(&E("first_second").to_string(), "first<wbr>_second");
22+
assert_eq!(&E("First<T>_Second").to_string(), "First&lt;<wbr>T&gt;_<wbr>Second");
23+
assert_eq!(&E("first_second").to_string(), "first_<wbr>second");
2424
assert_eq!(&E("first:second").to_string(), "first:<wbr>second");
2525
assert_eq!(&E("first::second").to_string(), "first::<wbr>second");
26-
assert_eq!(&E("MY_CONSTANT").to_string(), "MY<wbr>_CONSTANT");
26+
assert_eq!(&E("MY_CONSTANT").to_string(), "MY_<wbr>CONSTANT");
2727
// a string won't get wrapped if it's less than 8 bytes
2828
assert_eq!(&E("HashSet").to_string(), "HashSet");
2929
// an individual word won't get wrapped if it's less than 4 bytes
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<ul class="item-table"><li><div class="item-name"><a class="constant" href="constant.MY_CONSTANT.html" title="constant item_desc_list_at_start::MY_CONSTANT">MY<wbr />_CONSTANT</a></div><div class="desc docblock-short">Groups: <code>SamplePatternSGIS</code>, <code>SamplePatternEXT</code></div></li></ul>
1+
<ul class="item-table"><li><div class="item-name"><a class="constant" href="constant.MY_CONSTANT.html" title="constant item_desc_list_at_start::MY_CONSTANT">MY_<wbr />CONSTANT</a></div><div class="desc docblock-short">Groups: <code>SamplePatternSGIS</code>, <code>SamplePatternEXT</code></div></li></ul>

0 commit comments

Comments
 (0)