Skip to content

Commit

Permalink
rustdoc: move the wbr after the underscore, instead of before
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Jul 23, 2024
1 parent 51174b0 commit e277d8e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/librustdoc/html/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
|| pk.map_or(true, |(_, t)| t.chars().any(|c| c.is_uppercase()));
let next_is_underscore = || pk.map_or(true, |(_, t)| t.contains('_'));
let next_is_colon = || pk.map_or(true, |(_, t)| t.contains(':'));
if (i - last > 3 && is_uppercase() && !next_is_uppercase())
|| (s.contains('_') && !next_is_underscore())
{
if i - last > 3 && is_uppercase() && !next_is_uppercase() {
EscapeBodyText(&text[last..i]).fmt(fmt)?;
fmt.write_str("<wbr>")?;
last = i;
} else if s.contains(':') && !next_is_colon() {
} else if (s.contains(':') && !next_is_colon())
|| (s.contains('_') && !next_is_underscore())
{
EscapeBodyText(&text[last..i + 1]).fmt(fmt)?;
fmt.write_str("<wbr>")?;
last = i + 1;
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/html/escape/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ fn escape_body_text_with_wbr() {
assert_eq!(&E(" ").to_string(), " ");
// 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_<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&lt;<wbr>T&gt;<wbr>_Second");
assert_eq!(&E("first_second").to_string(), "first<wbr>_second");
assert_eq!(&E("First<T>_Second").to_string(), "First&lt;<wbr>T&gt;_<wbr>Second");
assert_eq!(&E("first_second").to_string(), "first_<wbr>second");
assert_eq!(&E("first:second").to_string(), "first:<wbr>second");
assert_eq!(&E("first::second").to_string(), "first::<wbr>second");
assert_eq!(&E("MY_CONSTANT").to_string(), "MY<wbr>_CONSTANT");
assert_eq!(&E("MY_CONSTANT").to_string(), "MY_<wbr>CONSTANT");
// a string won't get wrapped if it's less than 8 bytes
assert_eq!(&E("HashSet").to_string(), "HashSet");
// an individual word won't get wrapped if it's less than 4 bytes
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc/item-desc-list-at-start.item-table.html
Original file line number Diff line number Diff line change
@@ -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>
<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 comments on commit e277d8e

Please sign in to comment.