From 336e9f608594a3c554a2fee41450151472d34d4b Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Mon, 24 Feb 2025 03:01:25 +0100 Subject: [PATCH 1/3] fixup test links display it was broken since I changed rule link display, oops. --- mdbook-spec/src/rules.rs | 6 +++--- theme/reference.css | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/mdbook-spec/src/rules.rs b/mdbook-spec/src/rules.rs index dcab26d1b..1b51fe413 100644 --- a/mdbook-spec/src/rules.rs +++ b/mdbook-spec/src/rules.rs @@ -86,9 +86,9 @@ impl Spec { let mut test_html = String::new(); if let Some(tests) = tests.get(rule_id) { test_html = format!( - "\n\ -     \ - Tests\n\ + "
\n\ + \ + Tests\n\
\n\ Tests with this rule:
    "); diff --git a/theme/reference.css b/theme/reference.css index 147e0ed5a..fd5ef93be 100644 --- a/theme/reference.css +++ b/theme/reference.css @@ -302,6 +302,17 @@ main > .rule { color: #999 !important; } +/* Test links */ +.rule .popup-container { + float: right; + padding-right: 10px; +} + +.rule .popup-container > a { + float: right; + text-align: right; +} + /* When clicking a rule, it is added as a URL fragment and the browser will navigate to it. This adds an indicator that the linked rule is the one that is "current", just like normal headers are in mdbook. @@ -326,13 +337,18 @@ main > .rule { The cutoff point is chosen semi-arbitrary, it felt that when `width < 14em`, there are too many breaks. */ @container rule (width < 14em) { - main > .rule a span { + main > .rule a.rule-link span, + main > .rule .popup-container > a span { display: none; } - main > .rule a::before { + main > .rule > a.rule-link::before { content: "[*]"; - } + } + + main > .rule .popup-container > a::before { + content: "[T]"; + } } /* Align rules to various siblings */ From b625a412f320aa60f1b186ad182013b5a98dbc5f Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Mon, 24 Feb 2025 03:08:14 +0100 Subject: [PATCH 2/3] make the margins slightly bigger this prevents an issue where [*] (rule link) is cut off and only *] is shown. --- theme/reference.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/theme/reference.css b/theme/reference.css index fd5ef93be..49a3427c7 100644 --- a/theme/reference.css +++ b/theme/reference.css @@ -178,11 +178,11 @@ main { display: grid; grid-template-columns: /* Left margin / place for rules */ - [rules] minmax(20px, 1fr) + [rules] minmax(36px, 1fr) /* The main text body */ [text] auto /* Right margin */ - [margin] minmax(20px, 1fr); + [margin] minmax(36px, 1fr); /* We do these by hand via the grid */ margin: 0; From 0d6336b038329df01ae4e446c560a5879fd263d5 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 5 Mar 2025 13:55:58 -0800 Subject: [PATCH 3/3] Adjust tests popups to appear in the main column --- mdbook-spec/src/rules.rs | 25 +++++++------ theme/reference.css | 80 ++++++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 34 deletions(-) diff --git a/mdbook-spec/src/rules.rs b/mdbook-spec/src/rules.rs index 1b51fe413..8276292a3 100644 --- a/mdbook-spec/src/rules.rs +++ b/mdbook-spec/src/rules.rs @@ -83,31 +83,34 @@ impl Spec { RULE_RE .replace_all(content, |caps: &Captures<'_>| { let rule_id = &caps[1]; - let mut test_html = String::new(); + let mut test_link = String::new(); + let mut test_popup = String::new(); if let Some(tests) = tests.get(rule_id) { - test_html = format!( - "
    \n\ + test_link = format!( + "
    \n\ \ - Tests\n\ -
    \n\ - Tests with this rule: + Tests
    \n"); + test_popup = format!( + "
    \n\ + Tests with this rule:\n\
      "); for test in tests { writeln!( - test_html, + test_popup, "
    • {test_path}
    • ", test_path = test.path, ) .unwrap(); } - test_html.push_str("
    "); + test_popup.push_str("
"); } format!( "
\ - [{rule_id_broken}]\ - {test_html}\ -
\n", + [{rule_id_broken}]\n\ + {test_link}\ + \n\ + {test_popup}\n", rule_id_broken = rule_id.replace(".", "."), ) }) diff --git a/theme/reference.css b/theme/reference.css index 49a3427c7..793464116 100644 --- a/theme/reference.css +++ b/theme/reference.css @@ -257,24 +257,32 @@ main > ul { /* Values for header margin-top and blockquote margin are taken from mdbook's general.css, values for header margin-bottom are taken from */ +:root { + /* 1.6 is body font-size */ + --h2-margin-top: calc(1.5rem * 1.6 * 2.5 - 16px); + --h3-margin-top: calc(1.17rem * 1.6 * 2.5 - 16px); + --h4-margin-top: calc(1.00rem * 1.6 * 2 - 16px); + --h5-margin-top: calc(0.83rem * 1.6 * 2 - 16px); + --h6-margin-top: calc(0.67rem * 1.6 * 2 - 16px); +} main > h2 { - margin-top: calc(2.5em - 16px); + margin-top: var(--h2-margin-top); margin-bottom: calc(0.83em - 16px); } main > h3 { - margin-top: calc(2.5em - 16px); + margin-top: var(--h3-margin-top); margin-bottom: calc(1em - 16px); } main > h4 { - margin-top: calc(2em - 16px); + margin-top: var(--h4-margin-top); margin-bottom: calc(1.33em - 16px); } main > h5 { - margin-top: calc(2em - 16px); + margin-top: var(--h5-margin-top); margin-bottom: calc(1.67em - 16px); } main > h6 { - margin-top: calc(2em - 16px); + margin-top: var(--h6-margin-top); margin-bottom: calc(2.33em - 16px); } main > blockquote { @@ -303,7 +311,7 @@ main > .rule { } /* Test links */ -.rule .popup-container { +.test-link { float: right; padding-right: 10px; } @@ -317,28 +325,54 @@ main > .rule { navigate to it. This adds an indicator that the linked rule is the one that is "current", just like normal headers are in mdbook. */ -.rule:target a::before { +.rule:target .rule-link::before { display: inline-block; content: "»"; padding-right: 5px; } /* Dodge » from headings */ -.rule:has(+ h1:target), -.rule:has(+ h2:target), -.rule:has(+ h3:target), -.rule:has(+ h4:target), -.rule:has(+ h5:target), -.rule:has(+ h6:target) { +/* Note: Some rules have a .tests-popup in the way, so that's why this selects + either with or without. */ +.rule:has(+ h1:target, + .tests-popup + h1:target), +.rule:has(+ h2:target, + .tests-popup + h2:target), +.rule:has(+ h3:target, + .tests-popup + h3:target), +.rule:has(+ h4:target, + .tests-popup + h4:target), +.rule:has(+ h5:target, + .tests-popup + h5:target), +.rule:has(+ h6:target, + .tests-popup + h6:target) { padding-right: 24px; } +/* This positioning is to push the popup down over the header's top margin. + Ideally I would like the popup to show *below* the header, but I have no idea how to do that. +*/ +.tests-popup:has(+ h2) { + position: relative; + top: calc(var(--h2-margin-top) + 10px); +} +.tests-popup:has(+ h3) { + position: relative; + top: calc(var(--h3-margin-top) + 10px); +} +.tests-popup:has(+ h4) { + position: relative; + top: calc(var(--h4-margin-top) + 10px); +} +.tests-popup:has(+ h5) { + position: relative; + top: calc(var(--h5-margin-top) + 10px); +} +.tests-popup:has(+ h6) { + position: relative; + top: calc(var(--h6-margin-top) + 10px); +} + /* Hide the rules if the width of the container is too small. The cutoff point is chosen semi-arbitrary, it felt that when `width < 14em`, there are too many breaks. */ @container rule (width < 14em) { main > .rule a.rule-link span, - main > .rule .popup-container > a span { + .test-link > a span { display: none; } @@ -346,22 +380,22 @@ main > .rule { content: "[*]"; } - main > .rule .popup-container > a::before { + .test-link > a::before { content: "[T]"; } } /* Align rules to various siblings */ -.rule:has(+ p), -.rule:has(+ ul) { +.rule:has(+ p, + .tests-popup + p), +.rule:has(+ ul, + .tests-popup + ul) { margin-top: calc((1em - var(--font-size)) / var(--font-size-mult) / 2); } -.rule:has(+ h1) { +.rule:has(+ h1, + .tests-popup + h1) { align-self: center; } -.rule:has(+ h2) { +.rule:has(+ h2, + .tests-popup + h2) { /* multiplying by this turns h2's em into .rule's em*/ --h2-em-mult: calc( (1 / var(--font-size-mult)) /* to main font size */ @@ -375,7 +409,7 @@ main > .rule { + (1em * var(--h2-em-mult) - 1em) / 2 ) } -.rule:has(+ h3) { +.rule:has(+ h3, + .tests-popup + h3) { /* multiplying by this turns h3's em into .rule's em*/ --h3-em-mult: calc( (1 / var(--font-size-mult)) /* to main font size */ @@ -390,7 +424,7 @@ main > .rule { ) } -.rule:has(+ h4) { +.rule:has(+ h4, + .tests-popup + h4) { /* multiplying by this turns h4's em into .rule's em*/ --h4-em-mult: calc( (1 / var(--font-size-mult)) /* to main font size */ @@ -405,7 +439,7 @@ main > .rule { ) } -.rule:has(+ h5) { +.rule:has(+ h5, + .tests-popup + h5) { /* multiplying by this turns h5's em into .rule's em*/ --h5-em-mult: calc( (1 / var(--font-size-mult)) /* to main font size */ @@ -420,7 +454,7 @@ main > .rule { ) } -.rule:has(+ h6) { +.rule:has(+ h6, + .tests-popup + h6) { /* multiplying by this turns h6's em into .rule's em*/ --h6-em-mult: calc( (1 / var(--font-size-mult)) /* to main font size */