Skip to content

Commit 51aa20d

Browse files
authored
Rollup merge of #92801 - jsha:overflow-wrap, r=GuillaumeGomez
Enable wrapping words by default Faced with a very long word, browsers will let it overflow its box horizontally rather than break it in the middle. We essentially never want that behavior. We would rather break the word and keep it inside its horizontal limits. So we apply a default overflow-wrap: break-word/anywhere to the document as a while. In some contexts we would rather add a horizontal scrollbar (code blocks), or elide the excess text with an ellipsis (sidebar). Those still work as expected. Fixes #92771 [Some related discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/wrap.20.2F.20overflow.20.2F.20scroll) and a related issue: #92421. Demo: https://rustdoc.crud.net/jsha/overflow-wrap/std/iter/trait.Iterator.html#method.try_find r? ``@GuillaumeGomez``
2 parents 4de63e7 + 4d5a6c9 commit 51aa20d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/librustdoc/html/static/css/rustdoc.css

+16
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ body {
111111
font: 1rem/1.4 "Source Serif 4", NanumBarunGothic, serif;
112112
margin: 0;
113113
position: relative;
114+
/* We use overflow-wrap: break-word for Safari, which doesn't recognize
115+
`anywhere`: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap */
116+
overflow-wrap: break-word;
117+
/* Then override it with `anywhere`, which is required to make non-Safari browsers break
118+
more aggressively when we want them to. */
119+
overflow-wrap: anywhere;
114120

115121
-webkit-font-feature-settings: "kern", "liga";
116122
-moz-font-feature-settings: "kern", "liga";
@@ -446,6 +452,7 @@ nav.sub {
446452
text-align: center;
447453
border-bottom: 1px solid;
448454
overflow-wrap: break-word;
455+
overflow-wrap: anywhere;
449456
word-wrap: break-word; /* deprecated */
450457
word-break: break-word; /* Chrome, non-standard */
451458
}
@@ -576,6 +583,7 @@ nav.sub {
576583
}
577584

578585
.docblock-short {
586+
overflow-wrap: break-word;
579587
overflow-wrap: anywhere;
580588
}
581589
.docblock-short p {
@@ -641,6 +649,7 @@ nav.sub {
641649
flex-grow: 1;
642650
margin: 0px;
643651
padding: 0px;
652+
overflow-wrap: break-word;
644653
overflow-wrap: anywhere;
645654
}
646655

@@ -669,6 +678,7 @@ nav.sub {
669678
margin: .5em 0;
670679
width: calc(100% - 2px);
671680
overflow-x: auto;
681+
overflow-wrap: normal;
672682
display: block;
673683
}
674684

@@ -1495,6 +1505,7 @@ pre.rust {
14951505
padding: 4px 8px;
14961506
text-align: center;
14971507
background: rgba(0,0,0,0);
1508+
overflow-wrap: normal;
14981509
}
14991510

15001511
#theme-choices > button:not(:first-child) {
@@ -2099,9 +2110,14 @@ details.rustdoc-toggle[open] > summary.hideme::after {
20992110
}
21002111

21012112
.docblock code {
2113+
overflow-wrap: break-word;
21022114
overflow-wrap: anywhere;
21032115
}
21042116

2117+
.docblock table code {
2118+
overflow-wrap: normal;
2119+
}
2120+
21052121
.sub-container {
21062122
flex-direction: column;
21072123
}

0 commit comments

Comments
 (0)