Skip to content

Commit c9fb725

Browse files
authored
Merge pull request #1741 from WaffleLapkin/test-link-fixup
fixup test links
2 parents e1dc026 + 0d6336b commit c9fb725

File tree

2 files changed

+90
-37
lines changed

2 files changed

+90
-37
lines changed

mdbook-spec/src/rules.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,34 @@ impl Spec {
8383
RULE_RE
8484
.replace_all(content, |caps: &Captures<'_>| {
8585
let rule_id = &caps[1];
86-
let mut test_html = String::new();
86+
let mut test_link = String::new();
87+
let mut test_popup = String::new();
8788
if let Some(tests) = tests.get(rule_id) {
88-
test_html = format!(
89-
"<span class=\"popup-container\">\n\
90-
&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0)\" onclick=\"spec_toggle_tests('{rule_id}');\">\
91-
Tests</a>\n\
92-
<div id=\"tests-{rule_id}\" class=\"tests-popup popup-hidden\">\n\
93-
Tests with this rule:
89+
test_link = format!(
90+
"<br><div class=\"test-link\">\n\
91+
<a href=\"javascript:void(0)\" onclick=\"spec_toggle_tests('{rule_id}');\">\
92+
<span>Tests</span></a></div>\n");
93+
test_popup = format!(
94+
"<div id=\"tests-{rule_id}\" class=\"tests-popup popup-hidden\">\n\
95+
Tests with this rule:\n\
9496
<ul>");
9597
for test in tests {
9698
writeln!(
97-
test_html,
99+
test_popup,
98100
"<li><a href=\"https://github.com/rust-lang/rust/blob/{git_ref}/{test_path}\">{test_path}</a></li>",
99101
test_path = test.path,
100102
)
101103
.unwrap();
102104
}
103105

104-
test_html.push_str("</ul></div></span>");
106+
test_popup.push_str("</ul></div>");
105107
}
106108
format!(
107109
"<div class=\"rule\" id=\"r-{rule_id}\">\
108-
<a class=\"rule-link\" href=\"#r-{rule_id}\" title=\"{rule_id}\"><span>[{rule_id_broken}]<span/></a>\
109-
{test_html}\
110-
</div>\n",
110+
<a class=\"rule-link\" href=\"#r-{rule_id}\" title=\"{rule_id}\"><span>[{rule_id_broken}]</span/></a>\n\
111+
{test_link}\
112+
</div>\n\
113+
{test_popup}\n",
111114
rule_id_broken = rule_id.replace(".", "<wbr>."),
112115
)
113116
})

theme/reference.css

+75-25
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ main {
178178
display: grid;
179179
grid-template-columns:
180180
/* Left margin / place for rules */
181-
[rules] minmax(20px, 1fr)
181+
[rules] minmax(36px, 1fr)
182182
/* The main text body */
183183
[text] auto
184184
/* Right margin */
185-
[margin] minmax(20px, 1fr);
185+
[margin] minmax(36px, 1fr);
186186

187187
/* We do these by hand via the grid */
188188
margin: 0;
@@ -257,24 +257,32 @@ main > ul {
257257

258258
/* Values for header margin-top and blockquote margin are taken from mdbook's general.css,
259259
values for header margin-bottom are taken from <https://www.w3schools.com/cssref/css_default_values.php> */
260+
:root {
261+
/* 1.6 is body font-size */
262+
--h2-margin-top: calc(1.5rem * 1.6 * 2.5 - 16px);
263+
--h3-margin-top: calc(1.17rem * 1.6 * 2.5 - 16px);
264+
--h4-margin-top: calc(1.00rem * 1.6 * 2 - 16px);
265+
--h5-margin-top: calc(0.83rem * 1.6 * 2 - 16px);
266+
--h6-margin-top: calc(0.67rem * 1.6 * 2 - 16px);
267+
}
260268
main > h2 {
261-
margin-top: calc(2.5em - 16px);
269+
margin-top: var(--h2-margin-top);
262270
margin-bottom: calc(0.83em - 16px);
263271
}
264272
main > h3 {
265-
margin-top: calc(2.5em - 16px);
273+
margin-top: var(--h3-margin-top);
266274
margin-bottom: calc(1em - 16px);
267275
}
268276
main > h4 {
269-
margin-top: calc(2em - 16px);
277+
margin-top: var(--h4-margin-top);
270278
margin-bottom: calc(1.33em - 16px);
271279
}
272280
main > h5 {
273-
margin-top: calc(2em - 16px);
281+
margin-top: var(--h5-margin-top);
274282
margin-bottom: calc(1.67em - 16px);
275283
}
276284
main > h6 {
277-
margin-top: calc(2em - 16px);
285+
margin-top: var(--h6-margin-top);
278286
margin-bottom: calc(2.33em - 16px);
279287
}
280288
main > blockquote {
@@ -302,50 +310,92 @@ main > .rule {
302310
color: #999 !important;
303311
}
304312

313+
/* Test links */
314+
.test-link {
315+
float: right;
316+
padding-right: 10px;
317+
}
318+
319+
.rule .popup-container > a {
320+
float: right;
321+
text-align: right;
322+
}
323+
305324
/* When clicking a rule, it is added as a URL fragment and the browser will
306325
navigate to it. This adds an indicator that the linked rule is the one that
307326
is "current", just like normal headers are in mdbook.
308327
*/
309-
.rule:target a::before {
328+
.rule:target .rule-link::before {
310329
display: inline-block;
311330
content: "»";
312331
padding-right: 5px;
313332
}
314333

315334
/* Dodge » from headings */
316-
.rule:has(+ h1:target),
317-
.rule:has(+ h2:target),
318-
.rule:has(+ h3:target),
319-
.rule:has(+ h4:target),
320-
.rule:has(+ h5:target),
321-
.rule:has(+ h6:target) {
335+
/* Note: Some rules have a .tests-popup in the way, so that's why this selects
336+
either with or without. */
337+
.rule:has(+ h1:target, + .tests-popup + h1:target),
338+
.rule:has(+ h2:target, + .tests-popup + h2:target),
339+
.rule:has(+ h3:target, + .tests-popup + h3:target),
340+
.rule:has(+ h4:target, + .tests-popup + h4:target),
341+
.rule:has(+ h5:target, + .tests-popup + h5:target),
342+
.rule:has(+ h6:target, + .tests-popup + h6:target) {
322343
padding-right: 24px;
323344
}
324345

346+
/* This positioning is to push the popup down over the header's top margin.
347+
Ideally I would like the popup to show *below* the header, but I have no idea how to do that.
348+
*/
349+
.tests-popup:has(+ h2) {
350+
position: relative;
351+
top: calc(var(--h2-margin-top) + 10px);
352+
}
353+
.tests-popup:has(+ h3) {
354+
position: relative;
355+
top: calc(var(--h3-margin-top) + 10px);
356+
}
357+
.tests-popup:has(+ h4) {
358+
position: relative;
359+
top: calc(var(--h4-margin-top) + 10px);
360+
}
361+
.tests-popup:has(+ h5) {
362+
position: relative;
363+
top: calc(var(--h5-margin-top) + 10px);
364+
}
365+
.tests-popup:has(+ h6) {
366+
position: relative;
367+
top: calc(var(--h6-margin-top) + 10px);
368+
}
369+
325370
/* Hide the rules if the width of the container is too small.
326371
The cutoff point is chosen semi-arbitrary, it felt that
327372
when `width < 14em`, there are too many breaks. */
328373
@container rule (width < 14em) {
329-
main > .rule a span {
374+
main > .rule a.rule-link span,
375+
.test-link > a span {
330376
display: none;
331377
}
332378

333-
main > .rule a::before {
379+
main > .rule > a.rule-link::before {
334380
content: "[*]";
335-
}
381+
}
382+
383+
.test-link > a::before {
384+
content: "[T]";
385+
}
336386
}
337387

338388
/* Align rules to various siblings */
339-
.rule:has(+ p),
340-
.rule:has(+ ul) {
389+
.rule:has(+ p, + .tests-popup + p),
390+
.rule:has(+ ul, + .tests-popup + ul) {
341391
margin-top: calc((1em - var(--font-size)) / var(--font-size-mult) / 2);
342392
}
343393

344-
.rule:has(+ h1) {
394+
.rule:has(+ h1, + .tests-popup + h1) {
345395
align-self: center;
346396
}
347397

348-
.rule:has(+ h2) {
398+
.rule:has(+ h2, + .tests-popup + h2) {
349399
/* multiplying by this turns h2's em into .rule's em*/
350400
--h2-em-mult: calc(
351401
(1 / var(--font-size-mult)) /* to main font size */
@@ -359,7 +409,7 @@ main > .rule {
359409
+ (1em * var(--h2-em-mult) - 1em) / 2
360410
)
361411
}
362-
.rule:has(+ h3) {
412+
.rule:has(+ h3, + .tests-popup + h3) {
363413
/* multiplying by this turns h3's em into .rule's em*/
364414
--h3-em-mult: calc(
365415
(1 / var(--font-size-mult)) /* to main font size */
@@ -374,7 +424,7 @@ main > .rule {
374424
)
375425
}
376426

377-
.rule:has(+ h4) {
427+
.rule:has(+ h4, + .tests-popup + h4) {
378428
/* multiplying by this turns h4's em into .rule's em*/
379429
--h4-em-mult: calc(
380430
(1 / var(--font-size-mult)) /* to main font size */
@@ -389,7 +439,7 @@ main > .rule {
389439
)
390440
}
391441

392-
.rule:has(+ h5) {
442+
.rule:has(+ h5, + .tests-popup + h5) {
393443
/* multiplying by this turns h5's em into .rule's em*/
394444
--h5-em-mult: calc(
395445
(1 / var(--font-size-mult)) /* to main font size */
@@ -404,7 +454,7 @@ main > .rule {
404454
)
405455
}
406456

407-
.rule:has(+ h6) {
457+
.rule:has(+ h6, + .tests-popup + h6) {
408458
/* multiplying by this turns h6's em into .rule's em*/
409459
--h6-em-mult: calc(
410460
(1 / var(--font-size-mult)) /* to main font size */

0 commit comments

Comments
 (0)