Skip to content

Commit 1ac8a3b

Browse files
Rollup merge of #131257 - GuillaumeGomez:fix-list-margins, r=notriddle
[rustdoc] Fix list margins Fixes #131106. Fixes #131223. Follow-up of #130933. This PR changes the display as follow: the margin between list items is reduced by half to ensure that they visually still seem part of the same list, while also being bigger than previously which improves display for list items with more than one paragragh. Paragraphs also get they bottom margin reduced to a little bit less than the list items bottom margin for two reasons: 1. The list items keep having the biggest bottom margin which makes it better for coherency. 2. The paragraphs are still visually separated but they don't "overcome" the list. | before | after | |-|-| | ![Screenshot from 2024-10-04 17-58-51](https://github.com./user-attachments/assets/3fdc1472-781e-435d-a0d7-012f43aa8fb8) | ![image](https://github.com./user-attachments/assets/0366313d-416f-4f04-b905-bb16c54f4528) | Can be tested [here](https://rustdoc.crud.net/imperio/fix-list-margins/doc/test_docs/long_list/index.html). r? `@notriddle`
2 parents 1d4224f + 1c63ec9 commit 1ac8a3b

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -961,10 +961,13 @@ pre, .rustdoc.src .example-wrap, .example-wrap .src-line-numbers {
961961
}
962962

963963
.docblock li {
964-
margin-bottom: .8em;
964+
margin-bottom: .4em;
965965
}
966-
.docblock li p {
967-
margin-bottom: .1em;
966+
.docblock li p:not(:last-child) {
967+
/* This margin is voluntarily smaller than `.docblock li` to keep the visual
968+
list element items separated while also having a visual separation (although
969+
smaller) for paragraphs. */
970+
margin-bottom: .3em;
968971
}
969972

970973
/* "where ..." clauses with block display are also smaller */

tests/rustdoc-gui/list-margins.goml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This test ensures that the documentation list markers are correctly placed.
2+
// It also serves as a regression test for <https://github.com./rust-lang/rust/issues/130622>.
3+
4+
go-to: "file://" + |DOC_PATH| + "/test_docs/long_list/index.html"
5+
show-text: true
6+
7+
// 0.3em
8+
assert-css: (".docblock li p:not(last-child)", {"margin-bottom": "4.8px"})
9+
assert-css: (".docblock li p + p:last-child", {"margin-bottom": "0px"})
10+
// 0.4em
11+
assert-css: (".docblock li", {"margin-bottom": "6.4px"})

tests/rustdoc-gui/src/test_docs/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,27 @@ pub mod short_docs {
628628
/// subt_vec_num(x: &[f64], y: f64)
629629
pub fn subt_vec_num() {}
630630
}
631+
632+
pub mod long_list {
633+
//! bla
634+
//!
635+
//! * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et libero ut leo
636+
//! interdum laoreet vitae a mi. Aliquam erat volutpat. Suspendisse volutpat non quam non
637+
//! commodo.
638+
//!
639+
//! Praesent enim neque, imperdiet sed nisl at, lobortis egestas augue. Sed vitae tristique
640+
//! augue. Phasellus vel pretium lectus.
641+
//! * Praesent enim neque, imperdiet sed nisl at, lobortis egestas augue. Sed vitae tristique
642+
//! augue. Phasellus vel pretium lectus.
643+
//! * Praesent enim neque, imperdiet sed nisl at, lobortis egestas augue. Sed vitae tristique
644+
//! augue. Phasellus vel pretium lectus.
645+
//!
646+
//! Another list:
647+
//!
648+
//! * [`TryFromBytes`](#a) indicates that a type may safely be converted from certain byte
649+
//! sequence (conditional on runtime checks)
650+
//! * [`FromZeros`](#a) indicates that a sequence of zero bytes represents a valid instance of
651+
//! a type
652+
//! * [`FromBytes`](#a) indicates that a type may safely be converted from an arbitrary byte
653+
//! sequence
654+
}

0 commit comments

Comments
 (0)