Skip to content

Commit

Permalink
rustdoc: improve <wbr>-insertion for SCREAMING_CAMEL_CASE
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Oct 7, 2024
1 parent 7caad69 commit e23419f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustdoc/html/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ 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() {
if i - last > 3 && is_uppercase() && !next_is_uppercase() && !next_is_underscore() {
EscapeBodyText(&text[last..i]).fmt(fmt)?;
fmt.write_str("<wbr>")?;
last = i;
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/escape/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ fn escape_body_text_with_wbr() {
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("_SIDD_MASKED_NEGATIVE_POLARITY").to_string(),
"_SIDD_<wbr>MASKED_<wbr>NEGATIVE_<wbr>POLARITY"
);
// 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

0 comments on commit e23419f

Please sign in to comment.