Skip to content

Commit 441669c

Browse files
authored
Rollup merge of #105442 - notriddle:notriddle/docblock-table-css, r=GuillaumeGomez
rustdoc: clean up docblock table CSS # Preview http://notriddle.com/notriddle-rustdoc-demos/table-2/test_dingus/fn.test.html # Before ![image](https://user-images.githubusercontent.com/1593513/206364287-1b80eaaf-2e0e-4138-8b56-4aa8ff39abac.png) # After ![image](https://user-images.githubusercontent.com/1593513/206364209-d287d165-31be-4de1-9b43-05b35ce2a86b.png) # Details * The rule `display: block` had no noticeable effect. Technically, because markdown tables have a tbody and thead, they get wrapped in an [anonymous table box] in the CSS tree, nested within the `<table>` element's block layout box. This rule was added in #87230 to make the table side-scrolling, but this same issue was doubly fixed in #88742 by wrapping it in an explicit `<div>` tag. Since accessibility advocates recommend the wrapper div over marking the table as `display: block`, we'll stick with that. https://adrianroselli.com/2020/11/under-engineered-responsive-tables.html * The rule `width: calc(100% - 2px)` had no visible effect, because the anonymous table box was not affected. * The style is tweaked to basically be the same style GitHub uses. In particular, it adds zebra stripes, and removes dotted borders. https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Markdown.20table.20styling [anonymous table box]: https://www.w3.org/TR/CSS2/tables.html#anonymous-boxes
2 parents 4b09861 + 34700f6 commit 441669c

File tree

6 files changed

+57
-10
lines changed

6 files changed

+57
-10
lines changed

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

+4-10
Original file line numberDiff line numberDiff line change
@@ -630,22 +630,16 @@ pre, .rustdoc.source .example-wrap {
630630

631631
.docblock table {
632632
margin: .5em 0;
633-
width: calc(100% - 2px);
634-
overflow-x: auto;
635-
display: block;
636633
border-collapse: collapse;
637634
}
638635

639-
.docblock table td {
636+
.docblock table td, .docblock table th {
640637
padding: .5em;
641-
border: 1px dashed var(--border-color);
642-
vertical-align: top;
638+
border: 1px solid var(--border-color);
643639
}
644640

645-
.docblock table th {
646-
padding: .5em;
647-
text-align: left;
648-
border: 1px solid var(--border-color);
641+
.docblock table tbody tr:nth-child(2n) {
642+
background: var(--table-alt-row-background-color);
649643
}
650644

651645
/* Shift "where ..." part of method or fn definition down a line */

src/librustdoc/html/static/css/themes/ayu.css

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
8787
--crate-search-hover-border: #e0e0e0;
8888
--source-sidebar-background-selected: #14191f;
8989
--source-sidebar-background-hover: #14191f;
90+
--table-alt-row-background-color: #191f26;
9091
}
9192

9293
h1, h2, h3, h4 {

src/librustdoc/html/static/css/themes/dark.css

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
--crate-search-hover-border: #2196f3;
8383
--source-sidebar-background-selected: #333;
8484
--source-sidebar-background-hover: #444;
85+
--table-alt-row-background-color: #2A2A2A;
8586
}
8687

8788
.content .item-info::before { color: #ccc; }

src/librustdoc/html/static/css/themes/light.css

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
--crate-search-hover-border: #717171;
8080
--source-sidebar-background-selected: #fff;
8181
--source-sidebar-background-hover: #e0e0e0;
82+
--table-alt-row-background-color: #F5F5F5;
8283
}
8384

8485
.content .item-info::before { color: #ccc; }

src/test/rustdoc-gui/docblock-table.goml

+47
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,50 @@ goto: "file://" + |DOC_PATH| + "/test_docs/doc_block_table/struct.DocBlockTable.
22

33
compare-elements-css: (".impl-items .docblock table th", ".top-doc .docblock table th", ["border"])
44
compare-elements-css: (".impl-items .docblock table td", ".top-doc .docblock table td", ["border"])
5+
6+
define-function: (
7+
"check-colors",
8+
(theme, border_color, zebra_stripe_color),
9+
[
10+
("local-storage", {"rustdoc-use-system-theme": "false", "rustdoc-theme": |theme|}),
11+
("reload"),
12+
("assert-css", (".top-doc .docblock table tbody tr:nth-child(1)", {
13+
"background-color": "rgba(0, 0, 0, 0)",
14+
})),
15+
("assert-css", (".top-doc .docblock table tbody tr:nth-child(2)", {
16+
"background-color": |zebra_stripe_color|,
17+
})),
18+
("assert-css", (".top-doc .docblock table tbody tr:nth-child(3)", {
19+
"background-color": "rgba(0, 0, 0, 0)",
20+
})),
21+
("assert-css", (".top-doc .docblock table tbody tr:nth-child(4)", {
22+
"background-color": |zebra_stripe_color|,
23+
})),
24+
("assert-css", (".top-doc .docblock table td", {
25+
"border-style": "solid",
26+
"border-width": "1px",
27+
"border-color": |border_color|,
28+
})),
29+
("assert-css", (".top-doc .docblock table th", {
30+
"border-style": "solid",
31+
"border-width": "1px",
32+
"border-color": |border_color|,
33+
})),
34+
]
35+
)
36+
37+
call-function: ("check-colors", {
38+
"theme": "dark",
39+
"border_color": "rgb(224, 224, 224)",
40+
"zebra_stripe_color": "rgb(42, 42, 42)",
41+
})
42+
call-function: ("check-colors", {
43+
"theme": "ayu",
44+
"border_color": "rgb(92, 103, 115)",
45+
"zebra_stripe_color": "rgb(25, 31, 38)",
46+
})
47+
call-function: ("check-colors", {
48+
"theme": "light",
49+
"border_color": "rgb(224, 224, 224)",
50+
"zebra_stripe_color": "rgb(245, 245, 245)",
51+
})

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

+3
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ pub mod doc_block_table {
343343
/// | header1 | header2 |
344344
/// |--------------------------|--------------------------|
345345
/// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
346+
/// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
347+
/// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
348+
/// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
346349
pub struct DocBlockTable {}
347350

348351
impl DocBlockTableTrait for DocBlockTable {

0 commit comments

Comments
 (0)