From 146615375354a7976e4826c0946cb4cca88bb8e7 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 23 Feb 2022 12:10:40 +0100 Subject: [PATCH 1/3] Support dark mode --- src/nbsphinx.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nbsphinx.py b/src/nbsphinx.py index 39ef8366..9213771c 100644 --- a/src/nbsphinx.py +++ b/src/nbsphinx.py @@ -661,7 +661,6 @@ border: none; border-collapse: collapse; border-spacing: 0; - color: black; font-size: 12px; table-layout: fixed; } @@ -692,6 +691,10 @@ div.rendered_html tbody tr:nth-child(odd) { background: #f5f5f5; } +body[data-theme="dark"] .jp-RenderedHTMLCommon tbody tr:nth-child(odd), +body[data-theme="dark"] div.rendered_html tbody tr:nth-child(odd) { + background: rgba(255, 255, 255, .1); +} .jp-RenderedHTMLCommon tbody tr:hover, div.rendered_html tbody tr:hover { background: rgba(66, 165, 245, 0.2); From e5479326e8fd80b0259d4746917b8f441cdc10a5 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Fri, 25 Feb 2022 08:56:54 +0100 Subject: [PATCH 2/3] generalize --- src/nbsphinx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nbsphinx.py b/src/nbsphinx.py index 9213771c..c11a5af8 100644 --- a/src/nbsphinx.py +++ b/src/nbsphinx.py @@ -691,8 +691,8 @@ div.rendered_html tbody tr:nth-child(odd) { background: #f5f5f5; } -body[data-theme="dark"] .jp-RenderedHTMLCommon tbody tr:nth-child(odd), -body[data-theme="dark"] div.rendered_html tbody tr:nth-child(odd) { +*[data-theme="dark"] .jp-RenderedHTMLCommon tbody tr:nth-child(odd), +*[data-theme="dark"] div.rendered_html tbody tr:nth-child(odd) { background: rgba(255, 255, 255, .1); } .jp-RenderedHTMLCommon tbody tr:hover, From 59118d646dc447ddf2c2c6ff37370805a1ca4489 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sun, 20 Mar 2022 11:11:51 +0100 Subject: [PATCH 3/3] Maybe this works --- src/nbsphinx.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/nbsphinx.py b/src/nbsphinx.py index c11a5af8..8285db53 100644 --- a/src/nbsphinx.py +++ b/src/nbsphinx.py @@ -656,25 +656,18 @@ } /* Some additional styling taken form the Jupyter notebook CSS */ -.jp-RenderedHTMLCommon table, -div.rendered_html table { +:is(.jp-RenderedHTMLCommon, div.rendered_html) table { border: none; border-collapse: collapse; border-spacing: 0; font-size: 12px; table-layout: fixed; } -.jp-RenderedHTMLCommon thead, -div.rendered_html thead { +:is(.jp-RenderedHTMLCommon, div.rendered_html) thead { border-bottom: 1px solid black; vertical-align: bottom; } -.jp-RenderedHTMLCommon tr, -.jp-RenderedHTMLCommon th, -.jp-RenderedHTMLCommon td, -div.rendered_html tr, -div.rendered_html th, -div.rendered_html td { +:is(.jp-RenderedHTMLCommon, div.rendered_html) :is(tr, th, td) { text-align: right; vertical-align: middle; padding: 0.5em 0.5em; @@ -683,20 +676,29 @@ max-width: none; border: none; } -.jp-RenderedHTMLCommon th, -div.rendered_html th { +:is(.jp-RenderedHTMLCommon, div.rendered_html) th { font-weight: bold; } -.jp-RenderedHTMLCommon tbody tr:nth-child(odd), -div.rendered_html tbody tr:nth-child(odd) { - background: #f5f5f5; +@media (prefers-color-scheme: light) { + body:not([data-theme="dark"]) { + --nbsphinx-table-row-odd-bg: #f5f5f5; + } } -*[data-theme="dark"] .jp-RenderedHTMLCommon tbody tr:nth-child(odd), -*[data-theme="dark"] div.rendered_html tbody tr:nth-child(odd) { - background: rgba(255, 255, 255, .1); +@media (prefers-color-scheme: dark) { + body:not([data-theme="light"]) { + --nbsphinx-table-row-odd-bg: rgba(255, 255, 255, .1); + } } -.jp-RenderedHTMLCommon tbody tr:hover, -div.rendered_html tbody tr:hover { +body[data-theme="light"]) { + --nbsphinx-table-row-odd-bg: #f5f5f5; +} +body[data-theme="dark"] { + --nbsphinx-table-row-odd-bg: rgba(255, 255, 255, .1); +} +:is(.jp-RenderedHTMLCommon, div.rendered_html) tbody tr:nth-child(odd) { + background: var(--nbsphinx-table-row-odd-bg); +} +:is(.jp-RenderedHTMLCommon, div.rendered_html) tbody tr:hover { background: rgba(66, 165, 245, 0.2); } """