Skip to content

Commit d983969

Browse files
committed
Add theme
1 parent 94e2304 commit d983969

File tree

8 files changed

+217
-0
lines changed

8 files changed

+217
-0
lines changed

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
python=("https://docs.python.org/3", None),
2929
jinja=("https://jinja.palletsprojects.com/en/2.10.x/", None),
3030
sphinx=("https://www.sphinx-doc.org/en/master/", None),
31+
sphinx_rtd_theme=("https://sphinx-rtd-theme.readthedocs.io/en/stable/", None),
3132
# examples
3233
numpy=("https://docs.scipy.org/doc/numpy/", None),
3334
anndata=("https://anndata.readthedocs.io/en/latest/", None),
@@ -49,6 +50,7 @@
4950
# Don’t add module paths to documented functions’ names
5051
add_module_names = False
5152

53+
html_theme = "scanpydoc"
5254
html_context = dict(
5355
github_user="theislab", github_repo="scanpydoc", github_version="master"
5456
)

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Included extensions
1414
definition_list_typed_field
1515
elegant_typehints
1616
rtd_github_links
17+
theme

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ test = [
3232
]
3333
doc = [
3434
'sphinx-autodoc-typehints>=1.9',
35+
'sphinx-rtd-theme',
3536
]
3637

38+
[tool.flit.entrypoints.'sphinx.html_themes']
39+
scanpydoc = 'scanpydoc.theme'
40+
3741
[tool.black]
3842
target-version = ['py36']
3943

scanpydoc/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ def setup(app: Sphinx) -> Dict[str, Any]:
3636
app.setup_extension("scanpydoc.definition_list_typed_field")
3737
app.setup_extension("scanpydoc.elegant_typehints")
3838
app.setup_extension("scanpydoc.rtd_github_links")
39+
app.setup_extension("scanpydoc.theme")
3940
return metadata

scanpydoc/theme/__init__.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""A widescreen extension for :doc:`sphinx_rtd_theme:index`.
2+
3+
Add to ``conf.py``:
4+
5+
.. code:: python
6+
7+
html_theme = 'scanpydoc'
8+
9+
Theme options
10+
=============
11+
12+
This theme only adds one configuration value:
13+
14+
.. confval:: accent_color
15+
16+
:type: str
17+
:default: ``#f07e44``
18+
19+
The CSS color used for the mobile header background and the project name text.
20+
21+
See ``sphinx_rtd_theme``’s :doc:`sphinx_rtd_theme:configuring`, e.g.:
22+
23+
.. code:: python
24+
25+
html_theme_options = dict(
26+
logo_only=False,
27+
accent_color='rebeccapurple',
28+
display_version=False,
29+
)
30+
31+
"""
32+
33+
from pathlib import Path
34+
35+
from sphinx.application import Sphinx
36+
37+
from .. import _setup_sig
38+
39+
40+
HERE = Path(__file__).parent.resolve()
41+
42+
43+
@_setup_sig
44+
def setup(app: Sphinx):
45+
"""Setup theme (like an extension)"""
46+
app.add_html_theme("scanpydoc", str(HERE))
47+
return dict(parallel_read_safe=True, parallel_write_safe=True)

scanpydoc/theme/layout.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% extends "sphinx_rtd_theme/layout.html" %}
2+
{%- block extrahead %}
3+
{{ super() }}
4+
{% if theme_accent_color %}
5+
<style>
6+
:root { --accent-color: {{ theme_accent_color }} }
7+
</style>
8+
{% endif %}
9+
{% endblock %}

scanpydoc/theme/static/css/scanpy.css

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
@import "theme.css";
2+
3+
/* ReadTheDocs theme global changes */
4+
5+
:root { --accent-color: #f07e44 }
6+
.wy-nav-top { background-color: var(--accent-color) }
7+
.wy-nav-content { max-width: 1200px }
8+
.wy-side-nav-search { background-color: transparent }
9+
.wy-side-nav-search input[type="text"] { border-width: 0 }
10+
.wy-side-nav-search a.icon-home { font-size: 2em; color: var(--accent-color) }
11+
.wy-side-nav-search a.icon-home::before { content: none }
12+
13+
14+
/* Custom classes */
15+
16+
.small { font-size:40% }
17+
.smaller, .pr, .issue { font-size:70% }
18+
19+
20+
/* Custom classes with bootstrap buttons */
21+
22+
.tutorial,
23+
.tutorial:visited,
24+
.tutorial:hover
25+
{
26+
/* text-decoration: underline; */
27+
font-weight: bold;
28+
padding: 2px 5px;
29+
white-space: nowrap;
30+
max-width: 100%;
31+
background: #EF3270; /* color from the tail of the scampy */
32+
border: solid 1px #EF3270;
33+
border-radius: .25rem;
34+
font-size: 75%;
35+
/* font-family: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",Courier,monospace; */
36+
color: #404040;
37+
overflow-x: auto;
38+
box-sizing: border-box;
39+
}
40+
41+
42+
/* Formatting of RTD markup: rubrics and sidebars and admonitions */
43+
44+
/* rubric */
45+
.rst-content p.rubric {
46+
margin-bottom: 6px;
47+
font-weight: normal;
48+
}
49+
50+
/* sidebar */
51+
.rst-content .sidebar {
52+
/* margin: 0px 0px 0px 12px; */
53+
padding-bottom: 0px;
54+
}
55+
.rst-content .sidebar p {
56+
margin-bottom: 12px;
57+
}
58+
.rst-content .sidebar p,
59+
.rst-content .sidebar ul,
60+
.rst-content .sidebar dl {
61+
font-size: 13px;
62+
}
63+
64+
/* less space after bullet lists in admonitions like warnings and notes */
65+
.rst-content .section .admonition ul {
66+
margin-bottom: 6px;
67+
}
68+
69+
70+
/* Code: literals and links */
71+
72+
.rst-content tt.literal,
73+
.rst-content code.literal {
74+
color: #404040;
75+
}
76+
/* slim font weight for non-link code */
77+
.rst-content tt:not(.xref),
78+
.rst-content code:not(.xref),
79+
.rst-content *:not(a) > tt.xref,
80+
.rst-content *:not(a) > code.xref,
81+
.rst-content dl:not(.docutils) code
82+
{
83+
font-weight: normal;
84+
}
85+
.rst-content a > tt.xref,
86+
.rst-content a > code.xref,
87+
.rst-content dl:not(.docutils) a > tt.xref,
88+
.rst-content dl:not(.docutils) a > code.xref
89+
{
90+
font-weight: bold; /* underline looks clumsy, in particular with buttons and
91+
other hyperlinks, which don't come with underlines */
92+
}
93+
94+
95+
/* Just one box for annotation code for a less noisy look */
96+
97+
.rst-content .annotation {
98+
padding: 2px 5px;
99+
background-color: white;
100+
border: 1px solid #e1e4e5;
101+
}
102+
.rst-content .annotation tt,
103+
.rst-content .annotation code {
104+
padding: 0 0;
105+
background-color: transparent;
106+
border: 0 solid transparent;
107+
}
108+
109+
110+
/* Parameter lists */
111+
112+
/* Mimick rubric style used for other headings */
113+
/* TODO: once scanpydoc adds classes, also change return types like this */
114+
.rst-content dl:not(.docutils) dl > dt {
115+
font-weight: bold;
116+
background: none transparent;
117+
border-left: none;
118+
margin: 0 0 12px;
119+
padding: 3px 0 0;
120+
font-size: 111.11%;
121+
}
122+
/* Parameters contain <strong> parts and don’t need bold font */
123+
.rst-content dl.field-list dl > dt { font-weight: unset }
124+
/* Add colon between return tuple element name and type */
125+
.rst-content dl:not(.docutils) dl > dt .classifier::before { content: ' : ' }
126+
127+
/* Function headers */
128+
129+
.rst-content dl:not(.docutils) dt {
130+
background: #edf0f2;
131+
color: #404040;
132+
border-top: solid 3px #343131;
133+
}

scanpydoc/theme/theme.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[theme]
2+
inherit = sphinx_rtd_theme
3+
stylesheet = css/scanpy.css
4+
pygments_style = default
5+
6+
[options]
7+
canonical_url =
8+
analytics_id =
9+
collapse_navigation = True
10+
sticky_navigation = True
11+
navigation_depth = 4
12+
includehidden = True
13+
titles_only =
14+
logo_only =
15+
display_version = True
16+
prev_next_buttons_location = bottom
17+
style_external_links = False
18+
style_nav_header_background =
19+
# added by scanpydoc
20+
accent_color =

0 commit comments

Comments
 (0)