Skip to content

Commit f03aec9

Browse files
Shared styles from lecture-foundations
Synced from lecture-foundations. In dark mode, search hits stay readable, images from code cells sit on a light card, and QR codes turn white. Code in footnotes and callout titles takes the text colour, links and marked text in callout titles keep full strength, and the toggle icon no longer hides the link's name. The rule for the exercise QR codes moves into the shared core.
1 parent b5963fb commit f03aec9

2 files changed

Lines changed: 67 additions & 26 deletions

File tree

‎_dark.scss‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ $body-secondary-bg: $pi-dark-code-surface;
2424
$body-tertiary-bg: $pi-dark-code-surface;
2525
$link-color: $lec-highlight-on-dark;
2626
$primary: $lec-question-on-dark;
27+
// Search hits (<mark>): a dark fill, not a pale yellow box; body text 7.6:1 on it
28+
$mark-bg: mix($lec-task-on-dark, $pi-dark-ground, 25%);
2729

2830
// Code: Zed's dark active line; the left bar marks a block as code
2931
$code-block-bg: $pi-dark-code-surface;

‎styles.scss‎

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@
33
Generated into each lecture by scripts/sync-core-scss.py. DO NOT EDIT the
44
copy inside a lecture repo; edit this file and re-run the script.
55
6-
Theme order in every lecture:
6+
Theme order in every lecture (wired by scripts/wire-dark-mode.py):
77
88
theme:
9-
- default
10-
- fonts.scss self-hosted @font-face, no CDN
11-
- _core.scss this file
12-
- styles.scss lecture-local rules only
13-
- brand _brand.yml
9+
light: [default, styles.scss, brand]
10+
dark: [default, _dark.scss, styles.scss, brand]
11+
12+
styles.scss is this file (it @imports _fonts.scss and _paper-and-ink.scss)
13+
followed by the lecture's LOCAL fragment. _dark.scss is the dark layer and
14+
sits in the dark list only.
1415
1516
Two things about that order, both verified against a real render:
1617
1718
1. Quarto emits `scss:defaults` in REVERSE theme order. So `brand` is
18-
declared first (which is why `$brand-*` resolves at all), and a lecture's
19-
`styles.scss` is declared BEFORE this file — meaning a plain assignment
20-
there pre-empts any `!default` below. That is how Study-Business-Basics
21-
remaps the palette.
19+
declared first (which is why `$brand-*` resolves at all), and
20+
`_dark.scss` after this file, so its plain assignments replace the light
21+
values in the dark bundle. A plain assignment in a lecture's LOCAL
22+
fragment pre-empts any `!default` below: that is how
23+
Study-Business-Basics remaps the palette.
2224
2. `scss:rules` are emitted in FORWARD order, so a lecture's local rules
2325
come after these and win on a tie.
2426
2527
── Why the colours below are literal hex, not `$brand-*` ──────────────────
26-
Only four palette tokens exist in ALL fifteen lectures: `codeline`,
28+
Only four palette tokens exist in ALL sixteen lectures: `codeline`,
2729
`darker`, `greyer`, `lighter`. Study-Business-Basics has no `oneDark` /
2830
`twoDark` / `threeDark` at all — its palette is `sand` / `teal` /
2931
`dangerColor`, with different hex values. Referencing `$brand-twoDark` here
@@ -662,8 +664,8 @@ html.print-pdf .reveal .r-stack table {
662664
background:
663665
linear-gradient(to right, var(--bs-body-bg) 40%, transparent) left center / 1.5rem 100% no-repeat local,
664666
linear-gradient(to left, var(--bs-body-bg) 40%, transparent) right center / 1.5rem 100% no-repeat local,
665-
radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.15), transparent) left 1px center / 0.45rem 100% no-repeat scroll,
666-
radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.15), transparent) right 1px center / 0.45rem 100% no-repeat scroll;
667+
radial-gradient(farthest-side at 0 50%, color-mix(in srgb, var(--bs-body-color) 25%, transparent), transparent) left 1px center / 0.45rem 100% no-repeat scroll,
668+
radial-gradient(farthest-side at 100% 50%, color-mix(in srgb, var(--bs-body-color) 25%, transparent), transparent) right 1px center / 0.45rem 100% no-repeat scroll;
667669
}
668670
:is(h1, h2, h3, h4) {
669671
-webkit-hyphens: auto;
@@ -737,24 +739,39 @@ blockquote.blockquote {
737739
color: $lec-code-inline;
738740
}
739741

740-
// Inline code in a heading takes the heading's colour. Quarto sets h3 to 90 %
741-
// opacity, which pulled teal inline code in a heading under 4.5:1 on its chip
742-
// (Introduction-to-Python's cheatsheet and FAQ: 4.23:1).
743-
:is(h1, h2, h3, h4, h5, h6) > code:not(.sourceCode) {
742+
// Inline code in a heading, a footnote or a callout title takes the text's
743+
// colour. Quarto sets h3 and the footnote list to 90 % opacity and the callout
744+
// header to 75 %, which pulled teal inline code under 4.5:1 on its chip
745+
// (Introduction-to-Python's cheatsheet and FAQ: 4.23:1; Materiallogistik's
746+
// footnotes: 3.81:1; Grundlagen-OR's callout titles: 2.89:1).
747+
:is(h1, h2, h3, h4, h5, h6) > code:not(.sourceCode),
748+
.footnotes code:not(.sourceCode),
749+
.callout-header code:not(.sourceCode) {
744750
color: inherit;
745751
}
752+
// A link or a coloured text class in a callout title keeps full strength: at
753+
// the header's 75 % the link red fell to 4.23:1 (Study-Business-Basics' index
754+
// cards). `div.` ties with Quarto's `.callout.callout-style-simple >
755+
// div.callout-header { opacity: 75% }`, and this rule comes later in the bundle.
756+
div.callout-header:has(.callout-title-container :is(a, .highlight, .errors, .task, .question)) {
757+
opacity: 1;
758+
}
746759

747760
// ANSI output, see $lec-ansi. Scoped to .ansi-escaped-output so it outranks
748761
// Quarto's own notebook colours whatever order the layers come in.
749762
@each $hue, $pair in $lec-ansi {
750763
.ansi-escaped-output .ansi-#{$hue}-fg { color: nth($pair, 1); }
751764
.ansi-escaped-output :is(.ansi-bright-#{$hue}-fg, .ansi-#{$hue}-intense-#{$hue}) { color: nth($pair, 2); }
752-
.ansi-escaped-output .ansi-#{$hue}-bg { background-color: nth($pair, 1); color: $lec-ansi-on-colour; }
753-
.ansi-escaped-output .ansi-bright-#{$hue}-bg { background-color: nth($pair, 2); color: $lec-ansi-on-colour; }
754765
}
755766
.ansi-escaped-output .ansi-bright-black-fg {
756767
color: $lec-ansi-grey;
757768
}
769+
// Backgrounds after every foreground, so a span with both classes takes the
770+
// on-colour text whatever its hues.
771+
@each $hue, $pair in $lec-ansi {
772+
.ansi-escaped-output .ansi-#{$hue}-bg { background-color: nth($pair, 1); color: $lec-ansi-on-colour; }
773+
.ansi-escaped-output .ansi-bright-#{$hue}-bg { background-color: nth($pair, 2); color: $lec-ansi-on-colour; }
774+
}
758775
// IPython writes 256-colour codes as inline styles. The one in use (colour
759776
// 28, a green; 3.9:1 on the dark ground) follows the palette's green.
760777
.ansi-escaped-output span[style*="rgb(0,135,0)"]:not([class*="-bg"]) {
@@ -790,9 +807,38 @@ pre.numberSource code > span > a:first-child::before {
790807
}
791808
body.quarto-light .quarto-color-scheme-toggle .bi::before {
792809
content: "\f497"; // bi-moon
810+
content: "\f497" / ""; // no alt text: the link's title stays its name
793811
}
794812
body.quarto-dark .quarto-color-scheme-toggle .bi::before {
795813
content: "\f5a2"; // bi-sun
814+
content: "\f5a2" / "";
815+
}
816+
817+
// Plots on a dark page: the courses' plot helpers draw on a transparent
818+
// background in the brand's dark text, which vanishes on the dark ground. Every
819+
// image a code cell produces (also in a `layout` panel, which has no
820+
// .cell-output-display) sits on the light page colour as a card, as opaque
821+
// figures already do. A hand-made transparent diagram opts in with
822+
// `{.light-card}`. Later, maybe: a dark rendering per plot (Quarto's
823+
// `renderings: [light, dark]`).
824+
body.quarto-dark :is(div.cell img, img.light-card) {
825+
background-color: $pi-light-ground;
826+
border-radius: 6px;
827+
}
828+
829+
// QR codes (transparent, dark modules: `assets/qr/`, `images/*-qr.svg`) turn
830+
// white on a dark page; scanners read them inverted. Keep them out of the card
831+
// above (a code cell, `.light-card`): white on it would vanish. Decks stay
832+
// light and keep the dark modules.
833+
body.quarto-dark img:is([src*="/qr/"], [src*="-qr."]) {
834+
filter: brightness(0) invert(1);
835+
}
836+
837+
// Search hits on a dark page sit on a dark fill ($mark-bg in _dark.scss), but
838+
// the browser paints <mark> text black (2.0:1 there). They take the text's own
839+
// colour: body text 7.6:1, links 5.6:1. Light mode keeps the black.
840+
body.quarto-dark mark {
841+
color: inherit;
796842
}
797843

798844
// Footer, slide number, blockquotes and asides on a light slide: everything
@@ -847,10 +893,3 @@ body.quarto-dark .quarto-color-scheme-toggle .bi::before {
847893
_core.scss by scripts/sync-core-scss.py. Edit it there, not here.
848894
Everything BELOW is yours and is preserved across syncs.
849895
───────────────────────────────────────────────────────────────────────── */
850-
851-
// Exercise QR codes (lectures/assets/qr, transparent PNGs from
852-
// helpers/make_qr.py): white squares on the dark page in dark mode. Decks
853-
// stay light and keep the slate squares.
854-
body.quarto-dark img[src*="assets/qr/"] {
855-
filter: brightness(0) invert(1);
856-
}

0 commit comments

Comments
 (0)