Skip to content

Commit 34e01c3

Browse files
authored
Merge pull request #4 from B67687/pages/fix-notebook-contrast
Fix notebook text contrast on GitHub Pages
2 parents 138d947 + 5bfbb08 commit 34e01c3

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

build_pages.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,62 @@
3232
".yaml",
3333
}
3434

35+
NOTEBOOK_THEME_OVERRIDES = """
36+
<style>
37+
body.jp-Notebook {
38+
background: #f6f8fa;
39+
color: #1f2328;
40+
margin: 0 auto;
41+
padding: 24px;
42+
}
43+
44+
body.jp-Notebook {
45+
--jp-ui-font-color0: rgba(31, 35, 40, 1);
46+
--jp-ui-font-color1: rgba(31, 35, 40, 0.92);
47+
--jp-ui-font-color2: rgba(31, 35, 40, 0.72);
48+
--jp-ui-font-color3: rgba(31, 35, 40, 0.56);
49+
--jp-content-font-color0: rgba(31, 35, 40, 1);
50+
--jp-content-font-color1: rgba(31, 35, 40, 0.92);
51+
--jp-content-font-color2: rgba(31, 35, 40, 0.72);
52+
--jp-content-font-color3: rgba(31, 35, 40, 0.56);
53+
--jp-layout-color0: #ffffff;
54+
--jp-layout-color1: #ffffff;
55+
--jp-layout-color2: #f6f8fa;
56+
--jp-rendermime-table-row-background: #f6f8fa;
57+
--jp-rendermime-table-row-hover-background: #eaeef2;
58+
--jp-cell-editor-background: #ffffff;
59+
--jp-cell-editor-active-background: #ffffff;
60+
--jp-cell-editor-border-color: #d0d7de;
61+
--jp-cell-editor-active-border-color: #0969da;
62+
}
63+
64+
body.jp-Notebook .jp-Cell,
65+
body.jp-Notebook .jp-InputArea,
66+
body.jp-Notebook .jp-OutputArea-output,
67+
body.jp-Notebook .jp-RenderedHTMLCommon,
68+
body.jp-Notebook .jp-RenderedMarkdown,
69+
body.jp-Notebook .jp-RenderedText,
70+
body.jp-Notebook .jp-RenderedLatex {
71+
color: #1f2328;
72+
}
73+
74+
body.jp-Notebook .jp-InputArea-editor,
75+
body.jp-Notebook .jp-CodeMirrorEditor,
76+
body.jp-Notebook .highlight,
77+
body.jp-Notebook .jp-RenderedHTMLCommon pre,
78+
body.jp-Notebook .jp-RenderedText pre {
79+
background: #ffffff;
80+
color: #1f2328;
81+
}
82+
83+
body.jp-Notebook .jp-RenderedText pre .ansi-white-fg,
84+
body.jp-Notebook .jp-RenderedText pre .ansi-white-intense-fg,
85+
body.jp-Notebook .jp-RenderedText pre .ansi-default-inverse-fg {
86+
color: #1f2328;
87+
}
88+
</style>
89+
"""
90+
3591

3692
def should_skip(path: Path) -> bool:
3793
return any(part in EXCLUDED_PARTS for part in path.parts)
@@ -77,6 +133,8 @@ def rewrite_notebook_links(text: str) -> str:
77133
def rewrite_html_links(html_path: Path) -> None:
78134
content = html_path.read_text(encoding="utf-8")
79135
updated = rewrite_notebook_links(content)
136+
if NOTEBOOK_THEME_OVERRIDES not in updated and "</head>" in updated:
137+
updated = updated.replace("</head>", f"{NOTEBOOK_THEME_OVERRIDES}\n</head>", 1)
80138
if updated != content:
81139
html_path.write_text(updated, encoding="utf-8")
82140

0 commit comments

Comments
 (0)